X-Recipient: archive-cygwin@delorie.com
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3DDDF3851C2C
Authentication-Results: sourceware.org;
 dmarc=none (p=none dis=none) header.from=t-online.de
Authentication-Results: sourceware.org;
 spf=none smtp.mailfrom=Christian.Franke@t-online.de
Subject: Re: [cygwin] DD bug fails to wipe last 48 sectors of a disk
To: cygwin@cygwin.com
References: <DB7PR01MB5193A18F1D947ED4C276CD25D5980@DB7PR01MB5193.eurprd01.prod.exchangelabs.com>
 <1d1801d64677$bea56050$3bf020f0$@pdinc.us>
 <DB7PR01MB5193CC1C7630FB13B81B9DBAD5980@DB7PR01MB5193.eurprd01.prod.exchangelabs.com>
 <60bf1507-4edb-a03f-ec14-07e1ab7f0d94@cs.umass.edu>
 <DB7PR01MB519396195ADB3E3E1217B22BD5940@DB7PR01MB5193.eurprd01.prod.exchangelabs.com>
 <CAKNeuBqZpacuUwTD6U+kKPGOO052VYhpRnttm=HYr7m+OT7tiA@mail.gmail.com>
 <DB7PR01MB519371C6CAE2D3CFFEF41DCAD5940@DB7PR01MB5193.eurprd01.prod.exchangelabs.com>
 <1814912576.20200624132126@yandex.ru>
From: Christian Franke <Christian.Franke@t-online.de>
Message-ID: <5c9c5b44-c8a6-a075-705e-1761533cc966@t-online.de>
Date: Sun, 28 Jun 2020 16:34:33 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101
 SeaMonkey/2.53.2
MIME-Version: 1.0
In-Reply-To: <1814912576.20200624132126@yandex.ru>
X-ID: rxEiG4ZlohMeCzAzZJfjoxmW+rWJXOsI98BTglS+yJwSFdcKeMgFLmkfMXgY-PQQpV
X-TOI-EXPURGATEID: 150726::1593354875-0000FE54-B26DFC74/0/0 CLEAN NORMAL
X-TOI-MSGID: 7e4969aa-04c7-4b74-a773-5293efb3dec4
X-Spam-Status: No, score=2.8 required=5.0 tests=BAYES_00, FREEMAIL_FROM,
 KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_BARRACUDACENTRAL,
 RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE,
 TXREP autolearn=no autolearn_force=no version=3.4.2
X-Spam-Level: **
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <http://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <http://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="us-ascii"; Format="flowed"
Errors-To: cygwin-bounces@cygwin.com
Sender: "Cygwin" <cygwin-bounces@cygwin.com>

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

--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
