X-Recipient: archive-cygwin AT delorie DOT com X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT 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 DOT Franke AT t-online DOT de Subject: Re: [cygwin] DD bug fails to wipe last 48 sectors of a disk To: cygwin AT cygwin DOT com References: <1d1801d64677$bea56050$3bf020f0$@pdinc.us> <60bf1507-4edb-a03f-ec14-07e1ab7f0d94 AT cs DOT umass DOT edu> <1814912576 DOT 20200624132126 AT yandex DOT ru> From: Christian Franke 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 AT cygwin DOT com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: cygwin-bounces AT cygwin DOT com Sender: "Cygwin" 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