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