]> Dogcows Code - chaz/tar/blob - src/tar.h
(decode_header): Added initial support for POSIX extended
[chaz/tar] / src / tar.h
1 /* GNU tar Archive Format description.
2
3 Copyright (C) 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 2000, 2001, 2003 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14 Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 /* If OLDGNU_COMPATIBILITY is not zero, tar produces archives which, by
21 default, are readable by older versions of GNU tar. This can be
22 overriden by using --posix; in this case, POSIXLY_CORRECT in environment
23 may be set for enforcing stricter conformance. If OLDGNU_COMPATIBILITY
24 is zero or undefined, tar will eventually produces archives which, by
25 default, POSIX compatible; then either using --posix or defining
26 POSIXLY_CORRECT enforces stricter conformance.
27
28 This #define will disappear in a few years. FP, June 1995. */
29 #define OLDGNU_COMPATIBILITY 1
30
31 /* tar Header Block, from POSIX 1003.1-1990. */
32
33 /* POSIX header. */
34
35 struct posix_header
36 { /* byte offset */
37 char name[100]; /* 0 */
38 char mode[8]; /* 100 */
39 char uid[8]; /* 108 */
40 char gid[8]; /* 116 */
41 char size[12]; /* 124 */
42 char mtime[12]; /* 136 */
43 char chksum[8]; /* 148 */
44 char typeflag; /* 156 */
45 char linkname[100]; /* 157 */
46 char magic[6]; /* 257 */
47 char version[2]; /* 263 */
48 char uname[32]; /* 265 */
49 char gname[32]; /* 297 */
50 char devmajor[8]; /* 329 */
51 char devminor[8]; /* 337 */
52 char prefix[155]; /* 345 */
53 /* 500 */
54 };
55
56 struct star_header
57 { /* byte offset */
58 char name[100]; /* 0 */
59 char mode[8]; /* 100 */
60 char uid[8]; /* 108 */
61 char gid[8]; /* 116 */
62 char size[12]; /* 124 */
63 char mtime[12]; /* 136 */
64 char chksum[8]; /* 148 */
65 char typeflag; /* 156 */
66 char linkname[100]; /* 157 */
67 char magic[6]; /* 257 */
68 char version[2]; /* 263 */
69 char uname[32]; /* 265 */
70 char gname[32]; /* 297 */
71 char devmajor[8]; /* 329 */
72 char devminor[8]; /* 337 */
73 char prefix[131]; /* 345 */
74 char atime[12]; /* 476 */
75 char ctime[12]; /* 488 */
76 /* 500 */
77 };
78
79 #define TMAGIC "ustar" /* ustar and a null */
80 #define TMAGLEN 6
81 #define TVERSION "00" /* 00 and no null */
82 #define TVERSLEN 2
83
84 /* Values used in typeflag field. */
85 #define REGTYPE '0' /* regular file */
86 #define AREGTYPE '\0' /* regular file */
87 #define LNKTYPE '1' /* link */
88 #define SYMTYPE '2' /* reserved */
89 #define CHRTYPE '3' /* character special */
90 #define BLKTYPE '4' /* block special */
91 #define DIRTYPE '5' /* directory */
92 #define FIFOTYPE '6' /* FIFO special */
93 #define CONTTYPE '7' /* reserved */
94
95 #define XHDTYPE 'x' /* Extended header referring to the
96 next file in the archive */
97 #define XGLTYPE 'g' /* Global extended header */
98
99 /* Bits used in the mode field, values in octal. */
100 #define TSUID 04000 /* set UID on execution */
101 #define TSGID 02000 /* set GID on execution */
102 #define TSVTX 01000 /* reserved */
103 /* file permissions */
104 #define TUREAD 00400 /* read by owner */
105 #define TUWRITE 00200 /* write by owner */
106 #define TUEXEC 00100 /* execute/search by owner */
107 #define TGREAD 00040 /* read by group */
108 #define TGWRITE 00020 /* write by group */
109 #define TGEXEC 00010 /* execute/search by group */
110 #define TOREAD 00004 /* read by other */
111 #define TOWRITE 00002 /* write by other */
112 #define TOEXEC 00001 /* execute/search by other */
113
114 /* tar Header Block, GNU extensions. */
115
116 /* In GNU tar, SYMTYPE is for to symbolic links, and CONTTYPE is for
117 contiguous files, so maybe disobeying the `reserved' comment in POSIX
118 header description. I suspect these were meant to be used this way, and
119 should not have really been `reserved' in the published standards. */
120
121 /* *BEWARE* *BEWARE* *BEWARE* that the following information is still
122 boiling, and may change. Even if the OLDGNU format description should be
123 accurate, the so-called GNU format is not yet fully decided. It is
124 surely meant to use only extensions allowed by POSIX, but the sketch
125 below repeats some ugliness from the OLDGNU format, which should rather
126 go away. Sparse files should be saved in such a way that they do *not*
127 require two passes at archive creation time. Huge files get some POSIX
128 fields to overflow, alternate solutions have to be sought for this. */
129
130 /* Descriptor for a single file hole. */
131
132 struct sparse
133 { /* byte offset */
134 char offset[12]; /* 0 */
135 char numbytes[12]; /* 12 */
136 /* 24 */
137 };
138
139 /* Sparse files are not supported in POSIX ustar format. For sparse files
140 with a POSIX header, a GNU extra header is provided which holds overall
141 sparse information and a few sparse descriptors. When an old GNU header
142 replaces both the POSIX header and the GNU extra header, it holds some
143 sparse descriptors too. Whether POSIX or not, if more sparse descriptors
144 are still needed, they are put into as many successive sparse headers as
145 necessary. The following constants tell how many sparse descriptors fit
146 in each kind of header able to hold them. */
147
148 #define SPARSES_IN_EXTRA_HEADER 16
149 #define SPARSES_IN_OLDGNU_HEADER 4
150 #define SPARSES_IN_SPARSE_HEADER 21
151
152 /* The GNU extra header contains some information GNU tar needs, but not
153 foreseen in POSIX header format. It is only used after a POSIX header
154 (and never with old GNU headers), and immediately follows this POSIX
155 header, when typeflag is a letter rather than a digit, so signaling a GNU
156 extension. */
157
158 struct extra_header
159 { /* byte offset */
160 char atime[12]; /* 0 */
161 char ctime[12]; /* 12 */
162 char offset[12]; /* 24 */
163 char realsize[12]; /* 36 */
164 char longnames[4]; /* 48 */
165 char unused_pad1[68]; /* 52 */
166 struct sparse sp[SPARSES_IN_EXTRA_HEADER];
167 /* 120 */
168 char isextended; /* 504 */
169 /* 505 */
170 };
171
172 /* Extension header for sparse files, used immediately after the GNU extra
173 header, and used only if all sparse information cannot fit into that
174 extra header. There might even be many such extension headers, one after
175 the other, until all sparse information has been recorded. */
176
177 struct sparse_header
178 { /* byte offset */
179 struct sparse sp[SPARSES_IN_SPARSE_HEADER];
180 /* 0 */
181 char isextended; /* 504 */
182 /* 505 */
183 };
184
185 /* The old GNU format header conflicts with POSIX format in such a way that
186 POSIX archives may fool old GNU tar's, and POSIX tar's might well be
187 fooled by old GNU tar archives. An old GNU format header uses the space
188 used by the prefix field in a POSIX header, and cumulates information
189 normally found in a GNU extra header. With an old GNU tar header, we
190 never see any POSIX header nor GNU extra header. Supplementary sparse
191 headers are allowed, however. */
192
193 struct oldgnu_header
194 { /* byte offset */
195 char unused_pad1[345]; /* 0 */
196 char atime[12]; /* 345 */
197 char ctime[12]; /* 357 */
198 char offset[12]; /* 369 */
199 char longnames[4]; /* 381 */
200 char unused_pad2; /* 385 */
201 struct sparse sp[SPARSES_IN_OLDGNU_HEADER];
202 /* 386 */
203 char isextended; /* 482 */
204 char realsize[12]; /* 483 */
205 /* 495 */
206 };
207
208 /* OLDGNU_MAGIC uses both magic and version fields, which are contiguous.
209 Found in an archive, it indicates an old GNU header format, which will be
210 hopefully become obsolescent. With OLDGNU_MAGIC, uname and gname are
211 valid, though the header is not truly POSIX conforming. */
212 #define OLDGNU_MAGIC "ustar " /* 7 chars and a null */
213
214 /* The standards committee allows only capital A through capital Z for
215 user-defined expansion. Other letters in use include:
216
217 'A' Solaris Access Control List
218 'E' Solaris Extended Attribute File
219 'I' Inode only, as in 'star'
220 'X' POSIX 1003.1-2001 eXtended (VU version) */
221
222 /* This is a dir entry that contains the names of files that were in the
223 dir at the time the dump was made. */
224 #define GNUTYPE_DUMPDIR 'D'
225
226 /* Identifies the *next* file on the tape as having a long linkname. */
227 #define GNUTYPE_LONGLINK 'K'
228
229 /* Identifies the *next* file on the tape as having a long name. */
230 #define GNUTYPE_LONGNAME 'L'
231
232 /* This is the continuation of a file that began on another volume. */
233 #define GNUTYPE_MULTIVOL 'M'
234
235 /* For storing filenames that do not fit into the main header. */
236 #define GNUTYPE_NAMES 'N'
237
238 /* This is for sparse files. */
239 #define GNUTYPE_SPARSE 'S'
240
241 /* This file is a tape/volume header. Ignore it on extraction. */
242 #define GNUTYPE_VOLHDR 'V'
243
244 /* tar Header Block, overall structure. */
245
246 /* tar files are made in basic blocks of this size. */
247 #define BLOCKSIZE 512
248
249 enum archive_format
250 {
251 DEFAULT_FORMAT, /* format to be decided later */
252 V7_FORMAT, /* old V7 tar format */
253 OLDGNU_FORMAT, /* GNU format as per before tar 1.12 */
254 POSIX_FORMAT, /* restricted, pure POSIX format */
255 STAR_FORMAT, /* Star format defined in 1994 */
256 GNU_FORMAT /* POSIX format with GNU extensions */
257 };
258
259 struct tar_stat_info
260 {
261 char *orig_file_name; /* name of file read from the archive header */
262 char *file_name; /* name of file for the current archive entry
263 after being normalized. */
264 int had_trailing_slash; /* nonzero if the current archive entry had a
265 trailing slash before it was normalized. */
266 char *link_name; /* name of link for the current archive entry. */
267
268 unsigned int devminor; /* device minor number */
269 unsigned int devmajor; /* device major number */
270 char *uname; /* user name of owner */
271 char *gname; /* group name of owner */
272 struct stat stat; /* regular filesystem stat */
273 };
274
275 union block
276 {
277 char buffer[BLOCKSIZE];
278 struct posix_header header;
279 struct star_header star_header;
280 struct extra_header extra_header;
281 struct oldgnu_header oldgnu_header;
282 struct sparse_header sparse_header;
283 };
284
285 /* End of Format description. */
This page took 0.045363 seconds and 5 git commands to generate.