1 // Archive/TarHeader.cpp 2 3 #include "StdAfx.h" 4 5 #include "TarHeader.h" 6 7 namespace NArchive { 8 namespace NTar { 9 namespace NFileHeader { 10 11 const char * const kLongLink = "././@LongLink"; 12 const char * const kLongLink2 = "@LongLink"; 13 14 // The magic field is filled with this if uname and gname are valid. 15 namespace NMagic 16 { 17 // const char * const kUsTar = "ustar"; // 5 chars 18 // const char * const kGNUTar = "GNUtar "; // 7 chars and a null 19 // const char * const kEmpty = "\0\0\0\0\0\0\0\0"; 20 // 7-Zip used kUsTar_00 before 21.07: 21 const char k_Posix_ustar_00[8] = { 'u', 's', 't', 'a', 'r', 0, '0', '0' } ; 22 // GNU TAR uses such header: 23 const char k_GNU_ustar[8] = { 'u', 's', 't', 'a', 'r', ' ', ' ', 0 } ; 24 } 25 26 /* 27 pre-POSIX.1-1988 (i.e. v7) tar header: 28 ----- 29 Link indicator: 30 '0' or 0 : Normal file 31 '1' : Hard link 32 '2' : Symbolic link 33 Some pre-POSIX.1-1988 tar implementations indicated a directory by having 34 a trailing slash (/) in the name. 35 36 Numeric values : octal with leading zeroes. 37 For historical reasons, a final NUL or space character should also be used. 38 Thus only 11 octal digits can be stored from 12 bytes field. 39 40 2001 star : introduced a base-256 coding that is indicated by 41 setting the high-order bit of the leftmost byte of a numeric field. 42 GNU-tar and BSD-tar followed this idea. 43 44 versions of tar from before the first POSIX standard from 1988 45 pad the values with spaces instead of zeroes. 46 47 UStar 48 ----- 49 UStar (Unix Standard TAR) : POSIX IEEE P1003.1 : 1988. 50 257 signature: "ustar", 0, "00" 51 265 32 Owner user name 52 297 32 Owner group name 53 329 8 Device major number 54 337 8 Device minor number 55 345 155 Filename prefix 56 57 POSIX.1-2001/pax 58 ---- 59 format is known as extended tar format or pax format 60 vendor-tagged vendor-specific enhancements. 61 tags Defined by the POSIX standard: 62 atime, mtime, path, linkpath, uname, gname, size, uid, gid, ... 63 64 65 PAX EXTENSION 66 ----------- 67 Hard links 68 A further difference from the ustar header block is that data blocks 69 for files of typeflag 1 (hard link) may be included, 70 which means that the size field may be greater than zero. 71 Archives created by pax -o linkdata shall include these data 72 blocks with the hard links. 73 * 74 75 compatiblity 76 ------------ 77 7-Zip 16.03 supports "PaxHeader/" 78 7-Zip 20.01 supports "PaxHeaders.X/" with optional "./" 79 7-Zip 21.02 supports "@PaxHeader" with optional "./" "./" 80 81 GNU tar --format=posix uses "PaxHeaders/" in folder of file 82 83 84 GNU TAR format 85 ============== 86 v7 - Unix V7 87 oldgnu - GNU tar <=1.12 : writes zero in last character in name 88 gnu - GNU tar 1.13 : doesn't write zero in last character in name 89 as 7-zip 21.07 90 ustar - POSIX.1-1988 91 posix (pax) - POSIX.1-2001 92 93 gnu tar: 94 if (S_ISCHR (st->stat.st_mode) || S_ISBLK (st->stat.st_mode)) { 95 major_t devmajor = major (st->stat.st_rdev); 96 minor_t devminor = minor (st->stat.st_rdev); } 97 */ 98 99 }}} 100