开发者

Write on a pendrive with low level access

I am trying to开发者_运维百科 create a low level format utility for Linux. Is there any C/C++ library that can be used to access disk drives and write in the specific position?

Thanks!


In Linux (and other UNIX-like operating systems) block devises like hard drives can be accessed trough special files, like /dev/sda. You can open it as a file, do seeking, reading and writing. It will fail only if filesystem is mounted from that device. See also man sd.

Just in case, there is no need in low-level format utility for Linux. You can fill drive with 0 bytes by just using dd command, i.e. dd if=/dev/zero of=/dev/sda bs=512 count=.... After that, just create a new filesystem using mkfs. So you don't really need C/C++ API, it can fit into a couple of lines of a simple shell script.

Good luck!


I'm pretty sure you cannot actually format these devices. Or any modern storage device. Every device nowadays comes pre-formatted and cannot be reformatted (except possibly by vendor-specific software or firmware).

You haven't said why you want to achieve it. My guess is that if you try hard enough you'll "brick" the device.

You can write in a specific "logical position" easily enough through the standard block interface but in practice, on any modern drive (i.e. those manufactured in the last 15 years) that has no fixed relationship with a physical position. This is even more true on SDDs than it is on discs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜