[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dd - behavior on read error

From: David Balažic
Subject: Re: dd - behavior on read error
Date: Mon, 10 Apr 2017 18:04:51 +0200

On 10 April 2017 at 17:05, Pádraig Brady  wrote:
> On 10/04/17 06:37, David Balažic wrote:
>> Hi!
>> Using dd on Ubuntu 16.04.2 LTS (64 bit) I discovered this behavior
>> that was (for me) unexpected.
>> There is a bad sector on /dev/sda which on read attempt returns an i/o error.
>> Suppose it is sector number 50.
>> So: dd if=/dev/sda bs=512 count=1 skip=50
>> result: I/O error printed on stderr, exit status code is 1 (non zero,
>> don't remember the exact value)
>> But this: dd if=/dev/sda bs=2048 count=1 skip=12
>> returns exit code 0 and no error. It reads 1024 bytes (up to the
>> erroring sector)
>> Is this by design? I would expect an I/O error to be reported (in exit code).
> Your probably hitting the default short read behavior of dd
> which is defined by POSIX.  I.E. the read() system call will
> return what's available before returning the read() error,
> however with a count=1 dd will only consider the first read operation.
> You can change this operation with the iflag=fullblock flag.
> Note also the conv=sync,noerror settings which would be useful
> for reading as much as possible from the disk.

The dd docs (at [1]) say:


Accumulate full blocks from input. The read system call may return
early if a full block is not available. When that happens, continue
calling read to fill the remainder of the block. This flag can be used
only with iflag. This flag is useful with pipes for example as they
may return short reads. In that case, this flag is needed to ensure
that a ‘count=’ argument is interpreted as a block count rather than a
count of read operations.

Does POSIX mandate treating short reads and error reads the same? Can
you point me to the relevant text?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]