Subject: bug#59809: dd: Summary discrepancy with iflag=fullblock if the last write would be partial

From: Sworddragon <[email-masked]>
Date: Sat, 3 Dec 2022 23:32:39 +0000

Hi,

I'm using Knoppix 9.1 (x86_64 environment) (from early 2021 - but this is
the most recent version of it that is public available) with GNU Coreutils
8.32.

I was overwriting a HDD and wanted to try out the iflag=fullblock option -
despite not strictly needed for that special case but this shouldn't
matter. Here is the output that I got (freely translated form german to
english so some terms might be a bit off):

root@Microknoppix:~# dd if=/dev/random iflag=fullblock of=/dev/sda bs=1M
conv=fsync status=progress
320059998208 Bytes (320 GB, 298 GiB) copied, 5519 s, 58.0 MB/s
dd: Error on writing to '/dev/sda': No sufficient disk space available on
the device
305246+0 records in
305245+0 records out
320072933376 Bytes (320 GB, 298 GiB) copied, 5539.18 s, 57.8 MB/s

(That the output from status=progress mismatches with the final result is
due to bug https://debbugs.gnu.org/cgi/bugreport.cgi?bug=51482 which should
be already fixed so just ignore that)

The summary tells me that 320072933376 Bytes have been written which does
not match a multiple of bs=1M which implies my HDD has been fully
overwritten with random data - which would also match the documentation for
iflag=fullblock since it should never affect partial writes.
However, the previous line tells me that 305245+0 records have been written
which tells me that the last 352256 Bytes of my HDD haven't been
overwritten with random data.

So there is a discrepancy in the output where the second last line tells me
"305245+0 records out" while the last line basically tells me "305245+1
records out" - which one is now true?

So this issue seems to be a summary bug and in the worst-case also a
dataloss bug.

Edit: To test this further I did now a run of the same command just without
iflag=fullblock and I got pretty much the same result (305246+0 records in,
305245+0 records out, 320072933376 Bytes copied).
So this issue seems to be not related to iflag=fullblock - but the
discrepancy in the summary still exists. In this run I would have expected
to see "305245+1 records out" and I'm now curious again if my HDD has been
fully overwritten or not.

Maybe somebody can shed some light into this if something is indeed broken
or if I just miss something that I can't figure out.