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

Re: Problems with dd and the keywords swab and sync



On Thu, Apr 19, 2001 at 01:21:55PM +0200, Johannes Poehlmann wrote:
> I asked Andrew if I may quote the interesting paragraphs from SUSv3.
Ok, I can do that: 

>From the description of 
     dd - convert and copy a file

11607:        
The processing order shall be as follows:

1. An input block is read.

2. If the input block is shorter than the specified input block size
   and the sync conversion is specified, null bytes shall be appended to
   the input data up to the specified size. (If either block or unblock is
   also specified, <space>s shall be appended instead of null bytes.) The
   remaining conversions and output shall include the pad characters as
   if they had been read from the input.

3. If the bs=expr operand is specified and no conversion other than
   sync or noerror is requested, the resulting data shall be written to
   the output as a single block, and the remaining steps are omitted.

4. If the swab conversion is specified, each pair of input data bytes
   shall be swapped. If there is an odd number of bytes in the input
   block, the last byte in the input record shall not be swapped.

5.Any remaining conversions (block, unblock, lcase, and ucase) shall be
  performed. These conversions shall operate on the input data independently
  of the input blocking; an input or output fixed-length record may span
  block boundaries.

6. The data resulting from input or conversion or both shall be
 aggregated into output blocks of the specified size. After the end
 of input is reached, any remaining output shall be written as a block
 without padding if conv=sync is not specified; thus, the final output
 block may be shorter than the output block size.

11626                       

Is this interpretation correct ?

> For me the SUSv3 page on dd reads such that the extra (odd) character
> is NOT to be ignored, but output after the swabbed byte pairs. 
> 
> But did´nt dd output a newline before this last character? 
> 
> There is a test case, but this test case:
> 	echo ababx | dd conv=swab
> 	babax
> 
> is giving us a false alarm:
> 
> The error only occurs, if the ababx is followed by a newline character:
> Proof:   (Type in ababX followed by 2 times <Ctrl+D>   )
>       $ dd conv=swab of=x
>       ababX0+1 records in
>       0+1 records out
>       $ cat x
>       babaX$ 
> 
> The reason is that (without the block directive) dd is treating Newline
> as a normal character and not as a line end. 
> 
> 
> The info page on dd is clear enough and (I think) in line with SUS_v3:
> 
>     `swab'
>           Swap every pair of input bytes.  GNU `dd', unlike others,
>           works when an odd number of bytes are read--the last byte is
>           simply copied (since there is nothing to swap it with).
> 
> 
> So I think, we have no standard deviation with dd from fileutils.
> 
> 
> 
> 
>  
> 
> 

-- 
     ______   ___        
    /  ___/__/  /                 Caldera (Deutschland) GmbH          
   /  /_/ _  / /__        Naegelsbachstr. 49c, 91052 Erlangen, Germany 
  /_____/_/ /____/            software developer / lsb project 
 ==== /____/ =====   Dipl. Inf. Johannes Poehlmann, mail: jhp@caldera.de
Caldera OpenLinux    phone: ++49 9131 7192 335, fax: ++49 9131 7192 399



Reply to: