On 10/20/2013 04:46 PM, Jan Engelhardt wrote:
On Sunday 2013-10-20 16:28, Carlos E. R. wrote:
cer@Eleanor4:~/bin> dd if=/dev/random of=sample bs=100 count=1 ; l sample 0+1 records in 0+1 records out 22 bytes (22 B) copied, 0.00131574 s, 16.7 kB/s - -rw-r--r-- 1 cer users 22 Oct 20 16:08 sample
cer@Eleanor4:~/bin> dd if=/dev/random of=sample bs=100 count=1 ; l sample 0+1 records in 0+1 records out 9 bytes (9 B) copied, 17.0424 s, 0.0 kB/s - -rw-r--r-- 1 cer users 9 Oct 20 16:08 sample cer@Eleanor4:~/bin>
Why if the input is /dev/random, the size of the output file is not 100 bytes?
Because dd stops when it the syscall returns an error. But it won't tell you that.
Sorry. but that's not correct. We're talking about "short reads" here, and dd(1) behaves exactly as POSIX specifies it ([1]): search for "partial" and "short" in the specification. [1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/dd.html In this case, dd(1) told us that 0 blocks were full reads and that there happened 1 partial read: 0+1 records in "%u+%u records in\n", <number of whole input blocks>, <number of partial input blocks>
So stop using dd already. Use ddrescue - it's saner in every aspect.
If you think that dd(1) has a bug or contradicts the specification, then please report a bug. Otherwise, simply use the iflag=fullblock option [2]: ‘fullblock’ 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. [2] http://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html#dd... Have a nice day, Berny -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org