Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
tar.h
Go to the documentation of this file.
1/* GNU tar Archive Format description.
2
3 Copyright 1988-2019 Free Software Foundation, Inc.
4
5 This file is part of GNU tar.
6
7 GNU tar is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 GNU tar is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20/* tar Header Block, from POSIX 1003.1-1990. */
21
22/* POSIX header. */
23
25{ /* byte offset */
26 char name[100]; /* 0 */
27 char mode[8]; /* 100 */
28 char uid[8]; /* 108 */
29 char gid[8]; /* 116 */
30 char size[12]; /* 124 */
31 char mtime[12]; /* 136 */
32 char chksum[8]; /* 148 */
33 char typeflag; /* 156 */
34 char linkname[100]; /* 157 */
35 char magic[6]; /* 257 */
36 char version[2]; /* 263 */
37 char uname[32]; /* 265 */
38 char gname[32]; /* 297 */
39 char devmajor[8]; /* 329 */
40 char devminor[8]; /* 337 */
41 char prefix[155]; /* 345 */
42 /* 500 */
43};
44
45#define TMAGIC "ustar" /* ustar and a null */
46#define TMAGLEN 6
47#define TVERSION "00" /* 00 and no null */
48#define TVERSLEN 2
49
50/* Values used in typeflag field. */
51#define REGTYPE '0' /* regular file */
52#define AREGTYPE '\0' /* regular file */
53#define LNKTYPE '1' /* link */
54#define SYMTYPE '2' /* reserved */
55#define CHRTYPE '3' /* character special */
56#define BLKTYPE '4' /* block special */
57#define DIRTYPE '5' /* directory */
58#define FIFOTYPE '6' /* FIFO special */
59#define CONTTYPE '7' /* reserved */
60
61#define XHDTYPE 'x' /* Extended header referring to the
62 next file in the archive */
63#define XGLTYPE 'g' /* Global extended header */
64
65/* Bits used in the mode field, values in octal. */
66#define TSUID 04000 /* set UID on execution */
67#define TSGID 02000 /* set GID on execution */
68#define TSVTX 01000 /* reserved */
69 /* file permissions */
70#define TUREAD 00400 /* read by owner */
71#define TUWRITE 00200 /* write by owner */
72#define TUEXEC 00100 /* execute/search by owner */
73#define TGREAD 00040 /* read by group */
74#define TGWRITE 00020 /* write by group */
75#define TGEXEC 00010 /* execute/search by group */
76#define TOREAD 00004 /* read by other */
77#define TOWRITE 00002 /* write by other */
78#define TOEXEC 00001 /* execute/search by other */
79
80/* tar Header Block, GNU extensions. */
81
82/* 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/* *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/* Descriptor for a single file hole. */
98struct sparse
99{ /* byte offset */
100 char offset[12]; /* 0 */
101 char numbytes[12]; /* 12 */
102 /* 24 */
103};
104
105/* 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. */
114#define SPARSES_IN_EXTRA_HEADER 16
115#define SPARSES_IN_OLDGNU_HEADER 4
116#define SPARSES_IN_SPARSE_HEADER 21
117
118/* 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. */
123struct sparse_header
124{ /* byte offset */
126 /* 0 */
127 char isextended; /* 504 */
128 /* 505 */
129};
130
131/* 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. */
139struct oldgnu_header
140{ /* byte offset */
141 char unused_pad1[345]; /* 0 */
142 char atime[12]; /* 345 Incr. archive: atime of the file */
143 char ctime[12]; /* 357 Incr. archive: ctime of the file */
144 char offset[12]; /* 369 Multivolume archive: the offset of
145 the start of this volume */
146 char longnames[4]; /* 381 Not used */
147 char unused_pad2; /* 385 */
149 /* 386 */
150 char isextended; /* 482 Sparse file: Extension sparse header
151 follows */
152 char realsize[12]; /* 483 Sparse file: Real size*/
153 /* 495 */
154};
155
156/* 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 " /* 7 chars and a null */
161
162/* 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/* 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/* Identifies the *next* file on the tape as having a long linkname. */
176#define GNUTYPE_LONGLINK 'K'
177
178/* Identifies the *next* file on the tape as having a long name. */
179#define GNUTYPE_LONGNAME 'L'
180
181/* This is the continuation of a file that began on another volume. */
182#define GNUTYPE_MULTIVOL 'M'
183
184/* This is for sparse files. */
185#define GNUTYPE_SPARSE 'S'
186
187/* This file is a tape/volume header. Ignore it on extraction. */
188#define GNUTYPE_VOLHDR 'V'
189
190/* Solaris extended header */
191#define SOLARIS_XHDTYPE 'X'
192
193/* J@"org Schilling star header */
195struct star_header
196{ /* byte offset */
197 char name[100]; /* 0 */
198 char mode[8]; /* 100 */
199 char uid[8]; /* 108 */
200 char gid[8]; /* 116 */
201 char size[12]; /* 124 */
202 char mtime[12]; /* 136 */
203 char chksum[8]; /* 148 */
204 char typeflag; /* 156 */
205 char linkname[100]; /* 157 */
206 char magic[6]; /* 257 */
207 char version[2]; /* 263 */
208 char uname[32]; /* 265 */
209 char gname[32]; /* 297 */
210 char devmajor[8]; /* 329 */
211 char devminor[8]; /* 337 */
212 char prefix[131]; /* 345 */
213 char atime[12]; /* 476 */
214 char ctime[12]; /* 488 */
215 /* 500 */
216};
218#define SPARSES_IN_STAR_HEADER 4
219#define SPARSES_IN_STAR_EXT_HEADER 21
221struct star_in_header
223 char fill[345]; /* 0 Everything that is before t_prefix */
224 char prefix[1]; /* 345 t_name prefix */
225 char fill2; /* 346 */
226 char fill3[8]; /* 347 */
227 char isextended; /* 355 */
229 char realsize[12]; /* 452 Actual size of the file */
230 char offset[12]; /* 464 Offset of multivolume contents */
231 char atime[12]; /* 476 */
232 char ctime[12]; /* 488 */
233 char mfill[8]; /* 500 */
234 char xmagic[4]; /* 508 "tar" */
235};
241};
242
243/* END */
244
245
246/* tar Header Block, overall structure. */
247
248/* tar files are made in basic blocks of this size. */
249#define BLOCKSIZE 512
253 DEFAULT_FORMAT, /* format to be decided later */
254 V7_FORMAT, /* old V7 tar format */
255 OLDGNU_FORMAT, /* GNU format as per before tar 1.12 */
256 USTAR_FORMAT, /* POSIX.1-1988 (ustar) format */
257 POSIX_FORMAT, /* POSIX.1-2001 format */
258 STAR_FORMAT, /* Star format defined in 1994 */
259 GNU_FORMAT /* Same as OLDGNU_FORMAT with one exception:
260 see FIXME note for to_chars() function
261 (create.c:189) */
262};
263
264/* Information about a sparse file. */
265struct sp_array
267 off_t offset;
268 off_t numbytes;
269};
271struct xheader
273 struct obstack *stk;
274 size_t size;
275 char *buffer;
276 uintmax_t string_length;
277};
278
279/* Information about xattrs for a file. */
280struct xattr_array
282 char *xkey;
283 char *xval_ptr;
284 size_t xval_len;
285 };
287struct tar_stat_info
289 char *orig_file_name; /* name of file read from the archive header */
290 char *file_name; /* name of file for the current archive entry
291 after being normalized. */
292 bool had_trailing_slash; /* true if the current archive entry had a
293 trailing slash before it was normalized. */
294 char *link_name; /* name of link for the current archive entry. */
296 char *uname; /* user name of owner */
297 char *gname; /* group name of owner */
299 char *cntx_name; /* SELinux context for the current archive entry. */
301 char *acls_a_ptr; /* Access ACLs for the current archive entry. */
302 size_t acls_a_len; /* Access ACLs for the current archive entry. */
304 char *acls_d_ptr; /* Default ACLs for the current archive entry. */
305 size_t acls_d_len; /* Default ACLs for the current archive entry. */
307 struct _stat stat; /* regular filesystem stat */
308
309 /* STAT doesn't always have access, data modification, and status
310 change times in a convenient form, so store them separately. */
311 struct timespec atime;
312 struct timespec mtime;
313 struct timespec ctime;
315 off_t archive_file_size; /* Size of file as stored in the archive.
316 Equals stat.st_size for non-sparse files */
318 bool is_sparse; /* Is the file sparse */
319
320 /* For sparse files: */
321 unsigned sparse_major;
322 unsigned sparse_minor;
323 size_t sparse_map_avail; /* Index to the first unused element in
324 sparse_map array. Zero if the file is
325 not sparse */
326 size_t sparse_map_size; /* Size of the sparse map */
327 struct sp_array *sparse_map;
329 off_t real_size; /* The real size of sparse file */
330 bool real_size_set; /* True when GNU.sparse.realsize is set in
331 archived file */
333 bool sparse_name_done; /* Set to true if 'GNU.sparse.name' header was
334 processed pax header parsing. Following 'path'
335 header (lower priority) will be ignored. */
337 size_t xattr_map_size; /* Size of the xattr map */
338 struct xattr_array *xattr_map;
339
340 /* Extended headers */
341 struct xheader xhdr;
342
343 /* For dumpdirs */
344 bool is_dumpdir; /* Is the member a dumpdir? */
345 bool skipped; /* The member contents is already read
346 (for GNUTYPE_DUMPDIR) */
347 char *dumpdir; /* Contents of the dump directory */
348
349 /* Parent directory, if creating an archive. This is null if the
350 file is at the top level. */
351 struct tar_stat_info *parent;
352
353 /* Directory stream. If this is not null, it is in control of FD,
354 and should be closed instead of FD. */
355 DIR *dirstream;
356
357 /* File descriptor, if creating an archive, and if a directory or a
358 regular file or a contiguous file.
359
360 It is zero if no file descriptor is available, either because it
361 was never needed or because it was open and then closed to
362 conserve on file descriptors. (Standard input is never used
363 here, so zero cannot be a valid file descriptor.)
364
365 It is negative if it could not be reopened after it was closed.
366 Negate it to find out what errno was when the reopen failed. */
367 int fd;
368
369 /* Exclusion list */
370 struct exclist *exclude_list;
371};
382};
Definition obstack.h:175
Definition tar.h:139
char unused_pad1[345]
Definition tar.h:140
char longnames[4]
Definition tar.h:145
char isextended
Definition tar.h:149
char unused_pad2
Definition tar.h:146
char realsize[12]
Definition tar.h:151
char offset[12]
Definition tar.h:143
char ctime[12]
Definition tar.h:142
char atime[12]
Definition tar.h:141
struct sparse sp[SPARSES_IN_OLDGNU_HEADER]
Definition tar.h:147
Definition tar.h:25
char magic[6]
Definition tar.h:35
char typeflag
Definition tar.h:33
char mtime[12]
Definition tar.h:31
char devminor[8]
Definition tar.h:40
char mode[8]
Definition tar.h:27
char uname[32]
Definition tar.h:37
char size[12]
Definition tar.h:30
char gname[32]
Definition tar.h:38
char version[2]
Definition tar.h:36
char devmajor[8]
Definition tar.h:39
char linkname[100]
Definition tar.h:34
char uid[8]
Definition tar.h:28
char prefix[155]
Definition tar.h:41
char chksum[8]
Definition tar.h:32
char gid[8]
Definition tar.h:29
char name[100]
Definition tar.h:26
Definition tar.h:265
off_t numbytes
Definition tar.h:267
off_t offset
Definition tar.h:266
Definition tar.h:123
char isextended
Definition tar.h:126
struct sparse sp[SPARSES_IN_SPARSE_HEADER]
Definition tar.h:124
Definition tar.h:98
char numbytes[12]
Definition tar.h:100
char offset[12]
Definition tar.h:99
Definition tar.h:237
char isextended
Definition tar.h:239
struct sparse sp[SPARSES_IN_STAR_EXT_HEADER]
Definition tar.h:238
Definition tar.h:195
char magic[6]
Definition tar.h:205
char typeflag
Definition tar.h:203
char mtime[12]
Definition tar.h:201
char devminor[8]
Definition tar.h:210
char mode[8]
Definition tar.h:197
char uname[32]
Definition tar.h:207
char size[12]
Definition tar.h:200
char gname[32]
Definition tar.h:208
char version[2]
Definition tar.h:206
char ctime[12]
Definition tar.h:213
char devmajor[8]
Definition tar.h:209
char linkname[100]
Definition tar.h:204
char atime[12]
Definition tar.h:212
char uid[8]
Definition tar.h:198
char prefix[131]
Definition tar.h:211
char chksum[8]
Definition tar.h:202
char gid[8]
Definition tar.h:199
char name[100]
Definition tar.h:196
Definition tar.h:221
char isextended
Definition tar.h:226
char realsize[12]
Definition tar.h:228
char fill2
Definition tar.h:224
char prefix[1]
Definition tar.h:223
char fill3[8]
Definition tar.h:225
char xmagic[4]
Definition tar.h:233
struct sparse sp[SPARSES_IN_STAR_HEADER]
Definition tar.h:227
char offset[12]
Definition tar.h:229
char fill[345]
Definition tar.h:222
char ctime[12]
Definition tar.h:231
char atime[12]
Definition tar.h:230
char mfill[8]
Definition tar.h:232
Definition tar.h:287
char * acls_a_ptr
Definition tar.h:300
bool skipped
Definition tar.h:344
struct sp_array * sparse_map
Definition tar.h:326
size_t acls_a_len
Definition tar.h:301
char * gname
Definition tar.h:296
struct xheader xhdr
Definition tar.h:340
unsigned sparse_minor
Definition tar.h:321
off_t real_size
Definition tar.h:328
size_t sparse_map_avail
Definition tar.h:322
size_t sparse_map_size
Definition tar.h:325
off_t archive_file_size
Definition tar.h:314
bool had_trailing_slash
Definition tar.h:291
int fd
Definition tar.h:366
char * acls_d_ptr
Definition tar.h:303
char * file_name
Definition tar.h:289
DIR * dirstream
Definition tar.h:354
char * dumpdir
Definition tar.h:346
struct exclist * exclude_list
Definition tar.h:369
bool is_dumpdir
Definition tar.h:343
struct xattr_array * xattr_map
Definition tar.h:337
struct _stat stat
Definition tar.h:306
struct tar_stat_info * parent
Definition tar.h:350
bool is_sparse
Definition tar.h:317
char * orig_file_name
Definition tar.h:288
struct timespec mtime
Definition tar.h:311
unsigned sparse_major
Definition tar.h:320
bool real_size_set
Definition tar.h:329
struct timespec ctime
Definition tar.h:312
bool sparse_name_done
Definition tar.h:332
char * uname
Definition tar.h:295
char * cntx_name
Definition tar.h:298
size_t xattr_map_size
Definition tar.h:336
struct timespec atime
Definition tar.h:310
char * link_name
Definition tar.h:293
size_t acls_d_len
Definition tar.h:304
Definition tar.h:280
char * xkey
Definition tar.h:281
char * xval_ptr
Definition tar.h:282
size_t xval_len
Definition tar.h:283
Definition tar.h:271
struct obstack * stk
Definition tar.h:272
size_t size
Definition tar.h:273
uintmax_t string_length
Definition tar.h:275
char * buffer
Definition tar.h:274
#define SPARSES_IN_STAR_EXT_HEADER
Definition tar.h:218
#define SPARSES_IN_STAR_HEADER
Definition tar.h:217
#define SPARSES_IN_SPARSE_HEADER
Definition tar.h:115
#define SPARSES_IN_OLDGNU_HEADER
Definition tar.h:114
archive_format
Definition tar.h:251
@ GNU_FORMAT
Definition tar.h:258
@ OLDGNU_FORMAT
Definition tar.h:254
@ DEFAULT_FORMAT
Definition tar.h:252
@ POSIX_FORMAT
Definition tar.h:256
@ STAR_FORMAT
Definition tar.h:257
@ USTAR_FORMAT
Definition tar.h:255
@ V7_FORMAT
Definition tar.h:253
#define BLOCKSIZE
Definition tar.h:248
Definition tar.h:373
struct posix_header header
Definition tar.h:375
char buffer[BLOCKSIZE]
Definition tar.h:374