[cygwin] DD bug fails to wipe last 48 sectors of a disk
Christian Franke
Christian.Franke@t-online.de
Sun Jun 28 14:34:33 GMT 2020
Andrey Repin wrote:
>
>> dd if=/dev/zero of=/dev/sda iflag=fullblock bs=4M status=progress
The root of the problem is that the Windows WriteFile() function
apparently does not support truncated writes at EOM. If seek_position +
write_size > disk_size, then WriteFile() does nothing and returns an error.
> oflag=direct
>
> Although I'm unsure how Cygwin/Windows handles it. But without this flag, the
> write is cached, and the problem may be outside dd, or even Cygwin.
If 'oflag=direct' is used, dd passes O_DIRECT flag to open() call of
output file. Cygwin's open() function then passes
FILE_NO_INTERMEDIATE_BUFFERING to NtCreateFile() and the write()
function calls WriteFile() directly with original address and size.
Without O_DIRECT, Cygwin ensures that address and size passed to
WriteFile() are both aligned to sector size. All writes are then done
through a 64KiB internal buffer.
As a consequence, oflag=direct in the above dd command may increase
speed but would also let the final 4MiB WriteFile() fail. Without
oflag=direct, only the last 64KiB WriteFile() fails.
To clear the last sectors of the disk, use an appropriate small block
size. I did this several times with Cygwin 'dd seek=... bs=512 ...' to
get rid of Intel RST RAID metadata.
--
Regards,
Christian
More information about the Cygwin
mailing list