Anonymous | Login | 2024-12-04 05:07 UTC |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Simple Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||
ID | Category | Severity | Type | Date Submitted | Last Update | ||
0000406 | [1003.1(2008)/Issue 7] Shell and Utilities | Objection | Enhancement Request | 2011-04-14 23:00 | 2024-06-11 08:53 | ||
Reporter | eblake | View Status | public | ||||
Assigned To | ajosey | ||||||
Priority | normal | Resolution | Accepted | ||||
Status | Closed | ||||||
Name | Eric Blake | ||||||
Organization | Red Hat | ||||||
User Reference | ebb.dd | ||||||
Section | dd | ||||||
Page Number | 2582 | ||||||
Line Number | 83165 | ||||||
Interp Status | --- | ||||||
Final Accepted Text | |||||||
Summary | 0000406: add dd iflags=fullblock, for better pipe interaction | ||||||
Description |
The rationale for head states (XCU line 91101): There is no −c option (as there is in tail) because it is not historical practice and because other utilities in this volume of POSIX.1-2008 provide similar functionality. but does not name what those other utilities might be. The only one I can think of is dd. However, dd does _not_ provide the ability to efficiently read a particular number of byte. It is limited to reading count= blocks of input of ibs= bytes each, but if any of the input reads are short, then fewer than count*ibs bytes will be output. The only way to get an exact byte count is thus to use dd ibs=1 count=$n (since ibs=1 guarantees no short reads), but that causes $n reads. The problem of short reads is most noticeable with pipes and FIFOs, where short reads are common, but is also possible with regular files where the implementation encounters signals that interrupt the middle of reading. The GNU version of dd offers an extension iflags=fullblock which is used to enable dd to do multiple reads until the complete ibs= size has been read in, before proceeding on with the rest of the algorithm. Standardizing this extension would make dd more useful with input from pipes, while allowing more efficient blocking sizes. If this extension is not standardized, then it would be wise to modify the non-normative text to warn users that dd does not work well with pipes for anything larger than ibs=1. This proposal attempts to codify existing practice of one implementation but requires introducing a new option iflags (GNU dd also uses iflags for other purposes, such as iflags=noctty to specify the use of O_NOCTTY when opening if=, but that is not included in this proposal). However, if [io]flags is ever considered for standardization for use in specifying various O_* flags to pass to open(), it may make more sense to instead invent a new conversion specification conv=fullblock, rather than the GNU spelling of iflags=fullblock. This proposal helps with efficient read sizes from pipes when reading to end of file or when reading an exact multiple of the block size, but still lacks the ability to read an arbitrary number of bytes without resorting to two dd processes, as in this method of truncating input at exactly 10000 bytes while still writing an exact number of blocks for an output file with a 4k block size: process | { dd bs=4096 count=2 iflags=fullblock; \ dd ibs=1808 count=1 iflags=fullblock conv=sync obs=4096; } > output Therefore, it may also be worth standardizing a means of limiting input to a fixed byte count which is not a multiple of the requested input block size, although I don't know of any existing practice for that in dd; for that usage, the non-standard 'head -c' makes more sense. |
||||||
Desired Action |
At line 83245 [XCU dd OPERANDS], add a new paragraph: iflags=fullblock Perform as many reads as required to reach the full input block size or end of file, rather than acting on partial reads. If this operand is in effect, then the count= operand refers to the number of full input blocks rather than reads. Behavior is unspecified if iflags=fullblock is requested alongside the sync, block, or unblock conversions. At line 83144 [dd DESCRIPTION], add a sentence to step 1: If the iflags=fullblock operand is specified, this may entail multiple reads; otherwise, the input block is used even if the read was shorter than the specified block size. At line 83321 [dd APPLICATION USAGE], add a new paragraph: Using the count= operand of dd with a pipe or FIFO as the input can lead to surprising results, since these file types are prone to encountering short reads for any input block size other than 1. Unless the iflags=fullblock operand is in effect, dd will stop after the specified number of reads, rather than input blocks, and therefore can often result in fewer bytes being output than the product of the count and input block size. |
||||||
Tags | issue8 | ||||||
Attached Files | |||||||
|
Relationships | |||||||||||||
|
Mantis 1.1.6[^] Copyright © 2000 - 2008 Mantis Group |