Tar and absolute pathnames

Phil Hochstetler phil at sequent.UUCP
Thu Feb 4 05:34:34 AEST 1988


I once ran into a tape written this way and devised a quick filter that
gets around this problem.  Basically, you can process the tar header
blocks moving the pathname up to get rid of the leading '/' but have to
be sure the header checksum is correct.  My quick solution is to move
the '/' to the end of the pathname array, after the terminating null
character.  This means you can then do:

	tarfix < absolute.archive.tar | tar -xpvBf -

to extract the archive correctly.  Code follows:

---- tarfix.c
main()
{
	char fixbuf[512];

	while (read(0, fixbuf, sizeof (fixbuf)) == sizeof (fixbuf)) {
		if (fixbuf[0] == '/' && fixbuf[99] == 0) {
			strcpy(fixbuf, &fixbuf[1]);
			fixbuf[99] = '/';
		}
		write(1, fixbuf, sizeof (fixbuf));
	}
}
----
Phil Hochstetler
Sequent Computer Systems
Beaverton, Oregon



More information about the Comp.unix.wizards mailing list