1@comment GNU tar Archive Format description. 2@comment 3@comment Copyright 1988-2021 Free Software Foundation, Inc. 4@comment 5@comment This file is part of GNU tar. 6@comment 7@comment GNU tar is free software; you can redistribute it and/or modify 8@comment it under the terms of the GNU General Public License as published by 9@comment the Free Software Foundation; either version 3 of the License, or 10@comment (at your option) any later version. 11@comment 12@comment GNU tar is distributed in the hope that it will be useful, 13@comment but WITHOUT ANY WARRANTY; without even the implied warranty of 14@comment MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15@comment GNU General Public License for more details. 16@comment 17@comment You should have received a copy of the GNU General Public License 18@comment along with this program. If not, see <http://www.gnu.org/licenses/>. 19 20/*@r{ tar Header Block, from POSIX 1003.1-1990. }*/ 21 22/*@r{ POSIX header. }*/ 23 24struct posix_header 25@{ /*@r{ byte offset }*/ 26 char name[100]; /*@r{ 0 }*/ 27 char mode[8]; /*@r{ 100 }*/ 28 char uid[8]; /*@r{ 108 }*/ 29 char gid[8]; /*@r{ 116 }*/ 30 char size[12]; /*@r{ 124 }*/ 31 char mtime[12]; /*@r{ 136 }*/ 32 char chksum[8]; /*@r{ 148 }*/ 33 char typeflag; /*@r{ 156 }*/ 34 char linkname[100]; /*@r{ 157 }*/ 35 char magic[6]; /*@r{ 257 }*/ 36 char version[2]; /*@r{ 263 }*/ 37 char uname[32]; /*@r{ 265 }*/ 38 char gname[32]; /*@r{ 297 }*/ 39 char devmajor[8]; /*@r{ 329 }*/ 40 char devminor[8]; /*@r{ 337 }*/ 41 char prefix[155]; /*@r{ 345 }*/ 42 /*@r{ 500 }*/ 43@}; 44 45#define TMAGIC "ustar" /*@r{ ustar and a null }*/ 46#define TMAGLEN 6 47#define TVERSION "00" /*@r{ 00 and no null }*/ 48#define TVERSLEN 2 49 50/*@r{ Values used in typeflag field. }*/ 51#define REGTYPE '0' /*@r{ regular file }*/ 52#define AREGTYPE '\0' /*@r{ regular file }*/ 53#define LNKTYPE '1' /*@r{ link }*/ 54#define SYMTYPE '2' /*@r{ reserved }*/ 55#define CHRTYPE '3' /*@r{ character special }*/ 56#define BLKTYPE '4' /*@r{ block special }*/ 57#define DIRTYPE '5' /*@r{ directory }*/ 58#define FIFOTYPE '6' /*@r{ FIFO special }*/ 59#define CONTTYPE '7' /*@r{ reserved }*/ 60 61#define XHDTYPE 'x' /*@r{ Extended header referring to the 62 next file in the archive }*/ 63#define XGLTYPE 'g' /*@r{ Global extended header }*/ 64 65/*@r{ Bits used in the mode field, values in octal. }*/ 66#define TSUID 04000 /*@r{ set UID on execution }*/ 67#define TSGID 02000 /*@r{ set GID on execution }*/ 68#define TSVTX 01000 /*@r{ reserved }*/ 69 /*@r{ file permissions }*/ 70#define TUREAD 00400 /*@r{ read by owner }*/ 71#define TUWRITE 00200 /*@r{ write by owner }*/ 72#define TUEXEC 00100 /*@r{ execute/search by owner }*/ 73#define TGREAD 00040 /*@r{ read by group }*/ 74#define TGWRITE 00020 /*@r{ write by group }*/ 75#define TGEXEC 00010 /*@r{ execute/search by group }*/ 76#define TOREAD 00004 /*@r{ read by other }*/ 77#define TOWRITE 00002 /*@r{ write by other }*/ 78#define TOEXEC 00001 /*@r{ execute/search by other }*/ 79 80/*@r{ tar Header Block, GNU extensions. }*/ 81 82/*@r{ In GNU tar, SYMTYPE is for to symbolic links, and CONTTYPE is for 83 contiguous files, so maybe disobeying the "reserved" comment in POSIX 84 header description. I suspect these were meant to be used this way, and 85 should not have really been "reserved" in the published standards. }*/ 86 87/*@r{ *BEWARE* *BEWARE* *BEWARE* that the following information is still 88 boiling, and may change. Even if the OLDGNU format description should be 89 accurate, the so-called GNU format is not yet fully decided. It is 90 surely meant to use only extensions allowed by POSIX, but the sketch 91 below repeats some ugliness from the OLDGNU format, which should rather 92 go away. Sparse files should be saved in such a way that they do *not* 93 require two passes at archive creation time. Huge files get some POSIX 94 fields to overflow, alternate solutions have to be sought for this. }*/ 95 96/*@r{ Descriptor for a single file hole. }*/ 97 98struct sparse 99@{ /*@r{ byte offset }*/ 100 char offset[12]; /*@r{ 0 }*/ 101 char numbytes[12]; /*@r{ 12 }*/ 102 /*@r{ 24 }*/ 103@}; 104 105/*@r{ Sparse files are not supported in POSIX ustar format. For sparse files 106 with a POSIX header, a GNU extra header is provided which holds overall 107 sparse information and a few sparse descriptors. When an old GNU header 108 replaces both the POSIX header and the GNU extra header, it holds some 109 sparse descriptors too. Whether POSIX or not, if more sparse descriptors 110 are still needed, they are put into as many successive sparse headers as 111 necessary. The following constants tell how many sparse descriptors fit 112 in each kind of header able to hold them. }*/ 113 114#define SPARSES_IN_EXTRA_HEADER 16 115#define SPARSES_IN_OLDGNU_HEADER 4 116#define SPARSES_IN_SPARSE_HEADER 21 117 118/*@r{ Extension header for sparse files, used immediately after the GNU extra 119 header, and used only if all sparse information cannot fit into that 120 extra header. There might even be many such extension headers, one after 121 the other, until all sparse information has been recorded. }*/ 122 123struct sparse_header 124@{ /*@r{ byte offset }*/ 125 struct sparse sp[SPARSES_IN_SPARSE_HEADER]; 126 /*@r{ 0 }*/ 127 char isextended; /*@r{ 504 }*/ 128 /*@r{ 505 }*/ 129@}; 130 131/*@r{ The old GNU format header conflicts with POSIX format in such a way that 132 POSIX archives may fool old GNU tar's, and POSIX tar's might well be 133 fooled by old GNU tar archives. An old GNU format header uses the space 134 used by the prefix field in a POSIX header, and cumulates information 135 normally found in a GNU extra header. With an old GNU tar header, we 136 never see any POSIX header nor GNU extra header. Supplementary sparse 137 headers are allowed, however. }*/ 138 139struct oldgnu_header 140@{ /*@r{ byte offset }*/ 141 char unused_pad1[345]; /*@r{ 0 }*/ 142 char atime[12]; /*@r{ 345 Incr. archive: atime of the file }*/ 143 char ctime[12]; /*@r{ 357 Incr. archive: ctime of the file }*/ 144 char offset[12]; /*@r{ 369 Multivolume archive: the offset of 145 the start of this volume }*/ 146 char longnames[4]; /*@r{ 381 Not used }*/ 147 char unused_pad2; /*@r{ 385 }*/ 148 struct sparse sp[SPARSES_IN_OLDGNU_HEADER]; 149 /*@r{ 386 }*/ 150 char isextended; /*@r{ 482 Sparse file: Extension sparse header 151 follows }*/ 152 char realsize[12]; /*@r{ 483 Sparse file: Real size}*/ 153 /*@r{ 495 }*/ 154@}; 155 156/*@r{ OLDGNU_MAGIC uses both magic and version fields, which are contiguous. 157 Found in an archive, it indicates an old GNU header format, which will be 158 hopefully become obsolescent. With OLDGNU_MAGIC, uname and gname are 159 valid, though the header is not truly POSIX conforming. }*/ 160#define OLDGNU_MAGIC "ustar " /*@r{ 7 chars and a null }*/ 161 162/*@r{ The standards committee allows only capital A through capital Z for 163 user-defined expansion. Other letters in use include: 164 165 'A' Solaris Access Control List 166 'E' Solaris Extended Attribute File 167 'I' Inode only, as in 'star' 168 'N' Obsolete GNU tar, for file names that do not fit into the main header. 169 'X' POSIX 1003.1-2001 eXtended (VU version) }*/ 170 171/*@r{ This is a dir entry that contains the names of files that were in the 172 dir at the time the dump was made. }*/ 173#define GNUTYPE_DUMPDIR 'D' 174 175/*@r{ Identifies the *next* file on the tape as having a long linkname. }*/ 176#define GNUTYPE_LONGLINK 'K' 177 178/*@r{ Identifies the *next* file on the tape as having a long name. }*/ 179#define GNUTYPE_LONGNAME 'L' 180 181/*@r{ This is the continuation of a file that began on another volume. }*/ 182#define GNUTYPE_MULTIVOL 'M' 183 184/*@r{ This is for sparse files. }*/ 185#define GNUTYPE_SPARSE 'S' 186 187/*@r{ This file is a tape/volume header. Ignore it on extraction. }*/ 188#define GNUTYPE_VOLHDR 'V' 189 190/*@r{ Solaris extended header }*/ 191#define SOLARIS_XHDTYPE 'X' 192 193/*@r{ J@"org Schilling star header }*/ 194 195struct star_header 196@{ /*@r{ byte offset }*/ 197 char name[100]; /*@r{ 0 }*/ 198 char mode[8]; /*@r{ 100 }*/ 199 char uid[8]; /*@r{ 108 }*/ 200 char gid[8]; /*@r{ 116 }*/ 201 char size[12]; /*@r{ 124 }*/ 202 char mtime[12]; /*@r{ 136 }*/ 203 char chksum[8]; /*@r{ 148 }*/ 204 char typeflag; /*@r{ 156 }*/ 205 char linkname[100]; /*@r{ 157 }*/ 206 char magic[6]; /*@r{ 257 }*/ 207 char version[2]; /*@r{ 263 }*/ 208 char uname[32]; /*@r{ 265 }*/ 209 char gname[32]; /*@r{ 297 }*/ 210 char devmajor[8]; /*@r{ 329 }*/ 211 char devminor[8]; /*@r{ 337 }*/ 212 char prefix[131]; /*@r{ 345 }*/ 213 char atime[12]; /*@r{ 476 }*/ 214 char ctime[12]; /*@r{ 488 }*/ 215 /*@r{ 500 }*/ 216@}; 217 218#define SPARSES_IN_STAR_HEADER 4 219#define SPARSES_IN_STAR_EXT_HEADER 21 220 221struct star_in_header 222@{ 223 char fill[345]; /*@r{ 0 Everything that is before t_prefix }*/ 224 char prefix[1]; /*@r{ 345 t_name prefix }*/ 225 char fill2; /*@r{ 346 }*/ 226 char fill3[8]; /*@r{ 347 }*/ 227 char isextended; /*@r{ 355 }*/ 228 struct sparse sp[SPARSES_IN_STAR_HEADER]; /*@r{ 356 }*/ 229 char realsize[12]; /*@r{ 452 Actual size of the file }*/ 230 char offset[12]; /*@r{ 464 Offset of multivolume contents }*/ 231 char atime[12]; /*@r{ 476 }*/ 232 char ctime[12]; /*@r{ 488 }*/ 233 char mfill[8]; /*@r{ 500 }*/ 234 char xmagic[4]; /*@r{ 508 "tar" }*/ 235@}; 236 237struct star_ext_header 238@{ 239 struct sparse sp[SPARSES_IN_STAR_EXT_HEADER]; 240 char isextended; 241@}; 242 243