问题
I'm doing a tar
like in C, and I've got a problem.
I just want to archive and unarchive files and diretory, 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 output is always as ./PaxHeaders.NUMBER/FILE_NAME
.
When I try to open the archive in an editor, it show a PaxHeader before each files.
What is PaxHeaders
? Is there a header added to be fully compatible with Pax ? If there is, it's possible to remove them ?
I'm a bit lost, do i have to parse them or jump after these headers ?
Thanks a lot !
回答1:
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.
来源:https://stackoverflow.com/questions/34688392/paxheaders-in-tarball