ZhangZQ said:
Is there an API to format the HD? I found to use the DeviceIoControl with
IOCTL_DISK_FORMAT_TRACKS code can format the floppy, but how to format the
HD, I don't want the SHFormatDrvie way.
There's a section on Physical Disks and Volumes in the Platform SDK
documentation for CreateFile() but you probably saw that as a method of
getting a handle for DeviceIoControl. I do believe you can just write to
the media direct with WriteFile() but I've never tried it other than for
floppy disks (Google appears to confirm it).
Most of the modern file systems I know of only lay down their
super-structure when formatting. This makes formats very quick but many
do a disk scan or even clear every sector with a pattern, adding a huge
amount of time. I once did something like this for floppy disks by
simply laying down the initialisation state programmatically (i.e. a
MBR, BPB, FAT, Root Dir). If you know the file system media format you
can probably just lay down a default, empty one but I don't know how to
make a file system driver do a format on its own (would save you from
having to know the media format). You could write a pattern of your
devising to do a basic clearing of data but that won't do a forensic
safe cleanup - I believe the US DoD specifies a set of per-sector write
patterns they believe shreds the data to a forensic (or at least DoD
approved) state.