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