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