1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * https://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.commons.compress.archivers.tar;
20
21 /**
22 * This interface contains all the definitions used in the package.
23 * <p>
24 * For tar formats (FORMAT_OLDGNU, FORMAT_POSIX, etc.) see GNU tar <a href="https://git.savannah.gnu.org/cgit/tar.git/tree/src/tar.h?h=v1.35">tar.h</a> and type
25 * {@code enum archive_format}.
26 * </p>
27 * <p>
28 * TODO Next major version: Update to a class.
29 * </p>
30 */
31 // CheckStyle:InterfaceIsTypeCheck OFF (bc)
32 public interface TarConstants {
33
34 /**
35 * Default record size.
36 */
37 int DEFAULT_RCDSIZE = 512;
38
39 /**
40 * Default block size.
41 */
42 int DEFAULT_BLKSIZE = DEFAULT_RCDSIZE * 20;
43
44 /**
45 * GNU format as per before tar 1.12.
46 */
47 int FORMAT_OLDGNU = 2;
48
49 /**
50 * Pure POSIX format.
51 */
52 int FORMAT_POSIX = 3;
53
54 /**
55 * xstar format used by Jörg Schilling's star.
56 */
57 int FORMAT_XSTAR = 4;
58
59 /**
60 * The length of the name field in a header buffer.
61 */
62 int NAMELEN = 100;
63
64 /**
65 * The length of the mode field in a header buffer.
66 */
67 int MODELEN = 8;
68
69 /**
70 * The length of the user id field in a header buffer.
71 */
72 int UIDLEN = 8;
73
74 /**
75 * The length of the group id field in a header buffer.
76 */
77 int GIDLEN = 8;
78
79 /**
80 * The maximum value of gid/uid in a tar archive which can be expressed in octal char notation (that's 7 sevens, octal).
81 */
82 long MAXID = 07777777L;
83
84 /**
85 * The length of the checksum field in a header buffer.
86 */
87 int CHKSUMLEN = 8;
88
89 /**
90 * Offset of the checksum field within header record.
91 *
92 * @since 1.5
93 */
94 int CHKSUM_OFFSET = 148;
95
96 /**
97 * The length of the size field in a header buffer. Includes the trailing space or NUL.
98 */
99 int SIZELEN = 12;
100
101 /**
102 * The maximum size of a file in a tar archive which can be expressed in octal char notation (that's 11 sevens, octal).
103 */
104 long MAXSIZE = 077777777777L;
105
106 /** Offset of start of magic field within header record */
107 int MAGIC_OFFSET = 257;
108
109 /**
110 * The length of the magic field in a header buffer.
111 */
112 int MAGICLEN = 6;
113
114 /**
115 * Offset of start of magic field within header record.
116 */
117 int VERSION_OFFSET = 263;
118
119 /**
120 * Previously this was regarded as part of "magic" field, but it is separate.
121 */
122 int VERSIONLEN = 2;
123
124 /**
125 * The length of the modification time field in a header buffer.
126 */
127 int MODTIMELEN = 12;
128
129 /**
130 * The length of the user name field in a header buffer.
131 */
132 int UNAMELEN = 32;
133
134 /**
135 * The length of the group name field in a header buffer.
136 */
137 int GNAMELEN = 32;
138
139 /**
140 * The length of each of the device fields (major and minor) in a header buffer.
141 */
142 int DEVLEN = 8;
143
144 /**
145 * Length of the prefix field.
146 */
147 int PREFIXLEN = 155;
148
149 /**
150 * The length of the access time field in an old GNU header buffer.
151 */
152 int ATIMELEN_GNU = 12;
153
154 /**
155 * The length of the created time field in an old GNU header buffer.
156 */
157 int CTIMELEN_GNU = 12;
158
159 /**
160 * The length of the multivolume start offset field in an old GNU header buffer.
161 */
162 int OFFSETLEN_GNU = 12;
163
164 /**
165 * The length of the long names field in an old GNU header buffer.
166 */
167 int LONGNAMESLEN_GNU = 4;
168
169 /**
170 * The length of the padding field in an old GNU header buffer.
171 */
172 int PAD2LEN_GNU = 1;
173
174 /**
175 * The sum of the length of all sparse headers in an old GNU header buffer.
176 */
177 int SPARSELEN_GNU = 96;
178
179 /**
180 * The length of the is extension field in an old GNU header buffer.
181 */
182 int ISEXTENDEDLEN_GNU = 1;
183
184 /**
185 * The length of the real size field in an old GNU header buffer.
186 */
187 int REALSIZELEN_GNU = 12;
188
189 /**
190 * The length of offset in struct sparse
191 *
192 * @since 1.20
193 */
194 int SPARSE_OFFSET_LEN = 12;
195
196 /**
197 * The length of numbytes in struct sparse
198 *
199 * @since 1.20
200 */
201 int SPARSE_NUMBYTES_LEN = 12;
202
203 /**
204 * The number of sparse headers in an old GNU header
205 *
206 * @since 1.20
207 */
208 int SPARSE_HEADERS_IN_OLDGNU_HEADER = 4;
209
210 /**
211 * The number of sparse headers in an extension header
212 *
213 * @since 1.20
214 */
215 int SPARSE_HEADERS_IN_EXTENSION_HEADER = 21;
216
217 /**
218 * The sum of the length of all sparse headers in a sparse header buffer.
219 */
220 int SPARSELEN_GNU_SPARSE = 504;
221
222 /**
223 * The length of the is extension field in a sparse header buffer.
224 */
225 int ISEXTENDEDLEN_GNU_SPARSE = 1;
226
227 /**
228 * LF_ constants represent the "link flag" of an entry, or more commonly, the "entry type". This is the "old way" of indicating a normal file.
229 */
230 byte LF_OLDNORM = 0;
231
232 /**
233 * Offset inside the header for the "link flag" field.
234 *
235 * @since 1.22
236 * @see TarArchiveEntry
237 */
238 int LF_OFFSET = 156;
239
240 /**
241 * Normal file type.
242 */
243 byte LF_NORMAL = (byte) '0';
244
245 /**
246 * Link file type.
247 */
248 byte LF_LINK = (byte) '1';
249
250 /**
251 * Symbolic link file type.
252 */
253 byte LF_SYMLINK = (byte) '2';
254
255 /**
256 * Character device file type.
257 */
258 byte LF_CHR = (byte) '3';
259
260 /**
261 * Block device file type.
262 */
263 byte LF_BLK = (byte) '4';
264
265 /**
266 * Directory file type.
267 */
268 byte LF_DIR = (byte) '5';
269
270 /**
271 * FIFO (pipe) file type.
272 */
273 byte LF_FIFO = (byte) '6';
274
275 /**
276 * Contiguous file type.
277 */
278 byte LF_CONTIG = (byte) '7';
279
280 /**
281 * Identifies the *next* file on the tape as having a long link name.
282 */
283 byte LF_GNUTYPE_LONGLINK = (byte) 'K';
284
285 /**
286 * Identifies the *next* file on the tape as having a long name.
287 */
288 byte LF_GNUTYPE_LONGNAME = (byte) 'L';
289
290 /**
291 * Sparse file type.
292 *
293 * @since 1.1.1
294 */
295 byte LF_GNUTYPE_SPARSE = (byte) 'S';
296
297 // See "http://www.opengroup.org/onlinepubs/009695399/utilities/pax.html#tag_04_100_13_02"
298
299 /**
300 * Identifies the entry as a Pax extended header.
301 *
302 * @since 1.1
303 */
304 byte LF_PAX_EXTENDED_HEADER_LC = (byte) 'x';
305
306 /**
307 * Identifies the entry as a Pax extended header (SunOS tar -E).
308 *
309 * @since 1.1
310 */
311 byte LF_PAX_EXTENDED_HEADER_UC = (byte) 'X';
312
313 /**
314 * Identifies the entry as a Pax global extended header.
315 *
316 * @since 1.1
317 */
318 byte LF_PAX_GLOBAL_EXTENDED_HEADER = (byte) 'g';
319
320 /**
321 * Identifies the entry as a multi-volume past volume #0
322 *
323 * @since 1.22
324 */
325 byte LF_MULTIVOLUME = (byte) 'M';
326
327 /**
328 * The magic tag representing a POSIX tar archive.
329 * <p>
330 * "ustar" and a null.
331 * </p>
332 */
333 String MAGIC_POSIX = "ustar\0";
334
335 /**
336 * Default version.
337 */
338 String VERSION_POSIX = "00";
339
340 /**
341 * The magic tag representing a GNU tar archive.
342 */
343 String MAGIC_GNU = "ustar ";
344
345 /**
346 * One of two possible GNU versions
347 */
348 String VERSION_GNU_SPACE = " \0";
349
350 /**
351 * One of two possible GNU versions
352 */
353 String VERSION_GNU_ZERO = "0\0";
354
355 /**
356 * The magic tag representing an Ant tar archive.
357 *
358 * @since 1.1
359 */
360 String MAGIC_ANT = "ustar\0";
361
362 /**
363 * The "version" representing an Ant tar archive.
364 *
365 * @since 1.1
366 */
367 // Does not appear to have a version, however Ant does write 8 bytes,
368 // so assume the version is 2 nulls
369 String VERSION_ANT = "\0\0";
370
371 /**
372 * The name of the GNU tar entry which contains a long name.
373 */
374 String GNU_LONGLINK = "././@LongLink"; // TODO rename as LONGLINK_GNU ?
375
376 /**
377 * The magix string used in the last four bytes of the header to identify the xstar format.
378 *
379 * @since 1.11
380 */
381 String MAGIC_XSTAR = "tar\0";
382
383 /**
384 * Offset inside the header for the xtar multivolume data
385 *
386 * @since 1.22
387 * @see TarArchiveEntry
388 */
389 int XSTAR_MULTIVOLUME_OFFSET = 464;
390
391 /**
392 * Offset inside the header for the xstar magic bytes.
393 *
394 * @since 1.11
395 */
396 int XSTAR_MAGIC_OFFSET = 508;
397
398 /**
399 * Length of the XSTAR magic.
400 *
401 * @since 1.11
402 */
403 int XSTAR_MAGIC_LEN = 4;
404
405 /**
406 * Length of the prefix field in xstar archives.
407 *
408 * @since 1.11
409 */
410 int PREFIXLEN_XSTAR = 131;
411
412 /**
413 * Offset inside the header for the prefix field in xstar archives.
414 *
415 * @since 1.22
416 * @see TarArchiveEntry
417 */
418 int XSTAR_PREFIX_OFFSET = 345;
419
420 /**
421 * Offset inside the header for the atime field in xstar archives.
422 *
423 * @since 1.22
424 * @see TarArchiveEntry
425 */
426 int XSTAR_ATIME_OFFSET = 476;
427
428 /**
429 * The length of the access time field in a xstar header buffer.
430 *
431 * @since 1.11
432 */
433 int ATIMELEN_XSTAR = 12;
434
435 /**
436 * Offset inside the header for the ctime field in xstar archives.
437 *
438 * @since 1.22
439 * @see TarArchiveEntry
440 */
441 int XSTAR_CTIME_OFFSET = 488;
442
443 /**
444 * The length of the created time field in a xstar header buffer.
445 *
446 * @since 1.11
447 */
448 int CTIMELEN_XSTAR = 12;
449 }