Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PaxHeaders in tarball

Tags:

c

unix

posix

tar

pax

I'm doing a tar like in C, and I've got a problem. I just want to archive and unarchive files and diretories, so I operate this command: tar -cvf NAME.tar FILE1 [FILE2...]

Now I'm trying to get the header POSIX of this archive :

struct posix_header
{                              /* byte offset */
  char name[100];               /*   0 */
  char mode[8];                 /* 100 */
  char uid[8];                  /* 108 */
  char gid[8];                  /* 116 */
  char size[12];                /* 124 */
  char mtime[12];               /* 136 */
  char chksum[8];               /* 148 */
  char typeflag;                /* 156 */
  char linkname[100];           /* 157 */
  char magic[6];                /* 257 */
  char version[2];              /* 263 */
  char uname[32];               /* 265 */
  char gname[32];               /* 297 */
  char devmajor[8];             /* 329 */
  char devminor[8];             /* 337 */
  char prefix[155];             /* 345 */
                                /* 500 */
};
int main()
{
    struct posix_header header;
    int fd;

    if ((fd = open("./obj.tar", O_RDONLY)) < 2)     //open tarball
        return (1);
    read(fd, &header, 500);                         //fill struct
    printf("%s\n", header.name);
    close(fd);
}

but the output is always as ./PaxHeaders.NUMBER/FILE_NAME. When I try to open the archive in an editor, it shows a PaxHeader before each file.

What is PaxHeaders? Is there a header added to be fully compatible with Pax? If there is, is it possible to remove them?

I'm a bit lost, do I have to parse them or jump after these headers?

like image 217
Liroo Pierre Avatar asked Jan 09 '16 00:01

Liroo Pierre


1 Answers

POSIX.1 2008 defines an extension to the ustar format called the pax format. It's new features are introduced using special files with typeflag set to x for an extended pax header (affects the next file) or g for a global pax header (affects all further files). These headers allow archiving programs to store additional attributes in tar files, like access time or extended length (to store file too large for conventional tar).

Space in this answer is too restricted to replicate the full specification, read POSIX for more details.

like image 171
fuz Avatar answered Nov 04 '22 10:11

fuz