001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.commons.compress.archivers.tar;
020
021/**
022 * This interface contains all the definitions used in the package.
023 * <p>
024 * 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
025 * {@code enum archive_format}.
026 * </p>
027 */
028// CheckStyle:InterfaceIsTypeCheck OFF (bc)
029public interface TarConstants {
030
031    /** Default record size */
032    int DEFAULT_RCDSIZE = 512;
033
034    /** Default block size */
035    int DEFAULT_BLKSIZE = DEFAULT_RCDSIZE * 20;
036
037    /**
038     * GNU format as per before tar 1.12.
039     */
040    int FORMAT_OLDGNU = 2;
041
042    /**
043     * Pure Posix format.
044     */
045    int FORMAT_POSIX = 3;
046
047    /**
048     * xstar format used by Jörg Schilling's star.
049     */
050    int FORMAT_XSTAR = 4;
051
052    /**
053     * The length of the name field in a header buffer.
054     */
055    int NAMELEN = 100;
056
057    /**
058     * The length of the mode field in a header buffer.
059     */
060    int MODELEN = 8;
061
062    /**
063     * The length of the user id field in a header buffer.
064     */
065    int UIDLEN = 8;
066
067    /**
068     * The length of the group id field in a header buffer.
069     */
070    int GIDLEN = 8;
071
072    /**
073     * The maximum value of gid/uid in a tar archive which can be expressed in octal char notation (that's 7 sevens, octal).
074     */
075    long MAXID = 07777777L;
076
077    /**
078     * The length of the checksum field in a header buffer.
079     */
080    int CHKSUMLEN = 8;
081
082    /**
083     * Offset of the checksum field within header record.
084     *
085     * @since 1.5
086     */
087    int CHKSUM_OFFSET = 148;
088
089    /**
090     * The length of the size field in a header buffer. Includes the trailing space or NUL.
091     */
092    int SIZELEN = 12;
093
094    /**
095     * The maximum size of a file in a tar archive which can be expressed in octal char notation (that's 11 sevens, octal).
096     */
097    long MAXSIZE = 077777777777L;
098
099    /** 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}