Date: 2006sep30
Q. What's the format of a tar file?
A. There is no header for the entire file it.
The format is:
[Header for file 1]
[Contents of file 1]
[Header for file 2]
[Contents of file 2]
...
[EOF marker]
This means the only way to see how many files are in a tar file
is to read the entire file.
The header is always 512 bytes. Unused area at the end (of the header)
is padded with zeros.
The EOF marker is two 512 blocks of zero (ie 1024 zeros).
The file header is this:
typedef struct
{
char name[100];
char mode[8];
char owner_id[8];
char group_id[8];
char size[12];
char modtime[12];
char checksum[8];
char link; // '5' means directory
char linked_file[100];
} CLASSIC_TAR_HEADER;
typedef struct
{
char ustar[6];
char version[2];
char owner[32];
char group[32];
char major[8];
char minor[8];
char prefix[155];
} USTAR_HEADER;
typedef struct
{
CLASSIC_TAR_HEADER;
USTAR_HEADER;
} TAR_HEADER;
More info:
http://en.wikipedia.org/wiki/Tar_%28file_format%29
Add a comment
Sign in to add a comment