public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "Jason Pyeron" <jpyeron@pdinc.us>
To: <cygwin@cygwin.com>
Subject: RE: [cygwin] DD bug fails to wipe last 48 sectors of a disk
Date: Sun, 28 Jun 2020 13:50:16 -0400	[thread overview]
Message-ID: <00f601d64d74$959826d0$c0c87470$@pdinc.us> (raw)
In-Reply-To: <5c9c5b44-c8a6-a075-705e-1761533cc966@t-online.de>

> -----Original Message-----
> From: Christian Franke
> Sent: Sunday, June 28, 2020 10:35 AM
> 
> 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.

The reason I have never encountered this is because I use a block size which is the largest practical GCD of the drive size and 512 bytes (typically between 32 MB and 64 MB).

E.g. I have a drive that is 160,041,885,696 bytes, which divides 312,581,808 times evenly into 512. I would use a block size of ‭39,072,726‬ bytes, which gives 4,096 blocks to write.

-Jason


  reply	other threads:[~2020-06-28 17:50 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-19 18:19 Hashim Aziz
     [not found] ` <1d1801d64677$bea56050$3bf020f0$@pdinc.us>
2020-06-20 17:31   ` [cygwin] " Hashim Aziz
2020-06-20 20:26     ` Eliot Moss
2020-06-23 15:28       ` Hashim Aziz
2020-06-23 15:29         ` Eliot Moss
2020-06-23 16:06         ` Nicholas Clark
2020-06-23 19:46           ` Hashim Aziz
2020-06-24 10:21             ` Andrey Repin
2020-06-25 12:08               ` Hashim Aziz
2020-06-25 13:25                 ` Brian Inglis
2020-06-28 14:34               ` Christian Franke
2020-06-28 17:50                 ` Jason Pyeron [this message]
2020-06-28 20:28                   ` Brian Inglis
2020-06-23 19:33         ` Brian Inglis
2020-12-29  0:46           ` Hashim Aziz
2020-12-29  2:41             ` Jason Pyeron
2020-12-29 17:54               ` Brian Inglis
2020-12-30  1:35                 ` Jason Pyeron
     [not found]                   ` <DB7PR01MB5193B13815933B913D11DDC2D5D20@DB7PR01MB5193.eurprd01.prod.exchangelabs.com>
2021-01-04 21:08                     ` Jason Pyeron
2020-08-04 22:42 ` Hashim Aziz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='00f601d64d74$959826d0$c0c87470$@pdinc.us' \
    --to=jpyeron@pdinc.us \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).