tar or cpio?

Fred Fish fnf at mcdsun.UUCP
Wed Feb 17 08:28:45 AEST 1988


In article <2071 at bsu-cs.UUCP> dhesi at bsu-cs.UUCP (Rahul Dhesi) writes:
>An even more correct thing to do is for cpio to always write archive headers
>in a canonical format that is not dependent on the byte-ordering of the
>hardware.  E.g., all header data written least significant byte first.
>
>In other words, portability ought to be achieved by making the cpio *format*
>portable, not just by compensating for nonportability in the format (in this
>case, ambiguity in byte ordering).

Unfortunately this will not work for one not-so-obvious reason, and that
is because there are systems that when reading the exact same media,
will return bytes ordered differently.  I have seen this happen for example
when reading a given floppy on both a Callan Unistar machine and a Motorola
machine.  Thus there is no way to get around have to detect and do byte
swapping in the archiver as the same media can be read differently on
two different systems.  As long as you never move off the system, you
will never notice this problem.

Several years ago after I got my first Unix system, I was so disgusted
with tar and cpio that I wrote my own backup/archiver type program (bru)
which has always handled this problem completely transparently to the
user by writing ASCII formatted archives and doing whatever byte swapping
was necessary.  The basic algorithm is:

	1.	Examine block's magic number, if correct, no swapping.
	2.	Swap all bytes and try again.  If correct, note byte swap
		needed for all blocks.
	3.	Swap all shorts and try again.  If correct, note short swap
		also needed for all blocks.
	4.	Swap all bytes and try again.  If correct, reset byte swapping
		flag (swap shorts only).

I have never encountered a machine where one of these four combinations of
byte/short swapping didn't result in a readable archive, but I've seen
each combination needed at least once for at least one machine.

-Fred
-- 
# Fred Fish    hao!noao!mcdsun!fnf    (602) 438-3614
# Motorola Computer Division, 2900 S. Diablo Way, Tempe, Az 85282  USA



More information about the Comp.unix.questions mailing list