[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: enhancement request for a long word byte swap option for 'dd'
From: |
Bob Proulx |
Subject: |
Re: enhancement request for a long word byte swap option for 'dd' |
Date: |
Thu, 29 Jun 2006 22:08:17 -0600 |
User-agent: |
Mutt/1.5.9i |
Mike Lockhart wrote:
> To avoid endian issues, all our output binary files are written
> big-endian.
Binary data files need a defined format and one is as good as the
other. Depending upon your point of view little endian machines seem
to be more popular these days though. I actually think that the
choice of big-endian for the disk format is fortunate because it
forces people to consider endian issues up front and prevents them
from reading and writing binary data structures with abandon. :-)
> Some of my 'awk' scripts use 'od' to access data words in these
> files. Unfortunately (for me), on an Intel box running Linux, 'od'
> expects little-endian words.
I suggest always specifying a one byte size to od. For example on a
little-endian machine:
printf "abcdefgh\n" | od -tx1
0000000 61 62 63 64 65 66 67 68 0a
printf "abcdefgh\n" | od -tx
0000000 64636261 68676665 0000000a
On a big-endian machine:
printf "abcdefgh\n" | od -tx1
0000000 61 62 63 64 65 66 67 68 0a
printf "abcdefgh\n" | od -tx
0000000 61626364 65666768 0a000000
This is why I suggest avoiding the native word case and to always
specify -tx1 to get byte ordering. It avoids that problem entirely.
You can also use perl (or ruby or python or awk) to swap bytes.
printf "abcdefghijklmno\n" \
| perl -e 'while (sysread(STDIN,$d,4)){print pack("N",unpack("V",$d));}' \
| od -tx
0000000 61626364 65666768 696a6b6c 6d6e6f0a
> Not a problem if they're 1- or 2-byte words, as I pipe a 'dd' with
> conv=swab into 'od' and all is cool. For 4-byte words (floats, long
> integers), however, this doesn't work.
Here is an example:
printf "abcdefgh\n" | dd conv=swab | od -tx
0000000 63646162 67686566 0000000a
> How does one go about asking for an enhancement, say, for 'dd' -
> conv=swab4 - that would allow this operation?
I would always use one byte od dumps with -tx1. Or I would process
the file through perl or ruby or etc. to swap the bytes.
In a recent discussion thread it was suggested that perhaps dd should
be enhanced rather than od.
http://lists.gnu.org/archive/html/bug-coreutils/2006-02/msg00063.html
The environment seems good to add this feature to dd if someone were
able to do the work and make the appropriate copyright assignments for
the result.
Bob