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 *
024 * For tar formats (FORMAT_OLDGNU, FORMAT_POSIX, etc.) see GNU tar
025 * <I>tar.h</I> type <I>enum archive_format</I>
026 */
027// CheckStyle:InterfaceIsTypeCheck OFF (bc)
028public interface TarConstants {
029
030    /** Default record size */
031    int DEFAULT_RCDSIZE = 512;
032
033    /** Default block size */
034    int DEFAULT_BLKSIZE = DEFAULT_RCDSIZE * 20;
035
036    /**
037     * GNU format as per before tar 1.12.
038     */
039    int    FORMAT_OLDGNU = 2;
040
041    /**
042     * Pure Posix format.
043     */
044    int    FORMAT_POSIX = 3;
045
046    /**
047     * xstar format used by Jörg Schilling's star.
048     */
049    int    FORMAT_XSTAR = 4;
050
051    /**
052     * The length of the name field in a header buffer.
053     */
054    int    NAMELEN = 100;
055
056    /**
057     * The length of the mode field in a header buffer.
058     */
059    int    MODELEN = 8;
060
061    /**
062     * The length of the user id field in a header buffer.
063     */
064    int    UIDLEN = 8;
065
066    /**
067     * The length of the group id field in a header buffer.
068     */
069    int    GIDLEN = 8;
070
071    /**
072     * The maximum value of gid/uid in a tar archive which can
073     * 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     * @since 1.5
085     */
086    int    CHKSUM_OFFSET = 148;
087
088    /**
089     * The length of the size field in a header buffer.
090     * Includes the trailing space or NUL.
091     */
092    int    SIZELEN = 12;
093
094    /**
095     * The maximum size of a file in a tar archive
096     * which can be expressed in octal char notation (that's 11 sevens, octal).
097     */
098    long   MAXSIZE = 077777777777L;
099
100    /** Offset of start of magic field within header record */
101    int    MAGIC_OFFSET = 257;
102    /**
103     * The length of the magic field in a header buffer.
104     */
105    int    MAGICLEN = 6;
106
107    /** Offset of start of magic field within header record */
108    int    VERSION_OFFSET = 263;
109    /**
110     * Previously this was regarded as part of "magic" field, but it is separate.
111     */
112    int    VERSIONLEN = 2;
113
114    /**
115     * The length of the modification time field in a header buffer.
116     */
117    int    MODTIMELEN = 12;
118
119    /**
120     * The length of the user name field in a header buffer.
121     */
122    int    UNAMELEN = 32;
123
124    /**
125     * The length of the group name field in a header buffer.
126     */
127    int    GNAMELEN = 32;
128
129    /**
130     * The length of each of the device fields (major and minor) in a header buffer.
131     */
132    int    DEVLEN = 8;
133
134    /**
135     * Length of the prefix field.
136     *
137     */
138    int    PREFIXLEN = 155;
139
140    /**
141     * The length of the access time field in an old GNU header buffer.
142     *
143     */
144    int    ATIMELEN_GNU = 12;
145
146    /**
147     * The length of the created time field in an old GNU header buffer.
148     *
149     */
150    int    CTIMELEN_GNU = 12;
151
152    /**
153     * The length of the multivolume start offset field in an old GNU header buffer.
154     *
155     */
156    int    OFFSETLEN_GNU = 12;
157
158    /**
159     * The length of the long names field in an old GNU header buffer.
160     *
161     */
162    int    LONGNAMESLEN_GNU = 4;
163
164    /**
165     * The length of the padding field in an old GNU header buffer.
166     *
167     */
168    int    PAD2LEN_GNU = 1;
169
170    /**
171     * The sum of the length of all sparse headers in an old GNU header buffer.
172     *
173     */
174    int    SPARSELEN_GNU = 96;
175
176    /**
177     * The length of the is extension field in an old GNU header buffer.
178     *
179     */
180    int    ISEXTENDEDLEN_GNU = 1;
181
182    /**
183     * The length of the real size field in an old GNU header buffer.
184     *
185     */
186    int    REALSIZELEN_GNU = 12;
187
188    /**
189     * The length of offset in struct sparse
190     * @since 1.20
191     */
192    int    SPARSE_OFFSET_LEN = 12;
193
194    /**
195     * The length of numbytes in struct sparse
196     * @since 1.20
197     */
198    int    SPARSE_NUMBYTES_LEN = 12;
199
200    /**
201     *  The number of sparse headers in an old GNU header
202     * @since 1.20
203     */
204    int    SPARSE_HEADERS_IN_OLDGNU_HEADER = 4;
205
206    /**
207     *  The number of sparse headers in an extension header
208     * @since 1.20
209     */
210    int    SPARSE_HEADERS_IN_EXTENSION_HEADER = 21;
211
212    /**
213     * The sum of the length of all sparse headers in a sparse header buffer.
214     *
215     */
216    int    SPARSELEN_GNU_SPARSE = 504;
217
218    /**
219     * The length of the is extension field in a sparse header buffer.
220     *
221     */
222    int    ISEXTENDEDLEN_GNU_SPARSE = 1;
223
224    /**
225     * LF_ constants represent the "link flag" of an entry, or more commonly,
226     * the "entry type". This is the "old way" of indicating a normal file.
227     */
228    byte   LF_OLDNORM = 0;
229
230    /**
231     * Normal file type.
232     */
233    byte   LF_NORMAL = (byte) '0';
234
235    /**
236     * Link file type.
237     */
238    byte   LF_LINK = (byte) '1';
239
240    /**
241     * Symbolic link file type.
242     */
243    byte   LF_SYMLINK = (byte) '2';
244
245    /**
246     * Character device file type.
247     */
248    byte   LF_CHR = (byte) '3';
249
250    /**
251     * Block device file type.
252     */
253    byte   LF_BLK = (byte) '4';
254
255    /**
256     * Directory file type.
257     */
258    byte   LF_DIR = (byte) '5';
259
260    /**
261     * FIFO (pipe) file type.
262     */
263    byte   LF_FIFO = (byte) '6';
264
265    /**
266     * Contiguous file type.
267     */
268    byte   LF_CONTIG = (byte) '7';
269
270    /**
271     * Identifies the *next* file on the tape as having a long linkname.
272     */
273    byte LF_GNUTYPE_LONGLINK = (byte) 'K';
274
275    /**
276     * Identifies the *next* file on the tape as having a long name.
277     */
278    byte LF_GNUTYPE_LONGNAME = (byte) 'L';
279
280    /**
281     * Sparse file type.
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     * @since 1.1
291     */
292    byte LF_PAX_EXTENDED_HEADER_LC = (byte) 'x';
293
294    /**
295     * Identifies the entry as a Pax extended header (SunOS tar -E).
296     *
297     * @since 1.1
298     */
299    byte LF_PAX_EXTENDED_HEADER_UC = (byte) 'X';
300
301    /**
302     * Identifies the entry as a Pax global extended header.
303     *
304     * @since 1.1
305     */
306    byte LF_PAX_GLOBAL_EXTENDED_HEADER = (byte) 'g';
307
308    /**
309     * The magic tag representing a POSIX tar archive.
310     */
311    String MAGIC_POSIX = "ustar\0";
312    String VERSION_POSIX = "00";
313
314    /**
315     * The magic tag representing a GNU tar archive.
316     */
317    String MAGIC_GNU = "ustar ";
318    // Appear to be two possible GNU versions
319    String VERSION_GNU_SPACE = " \0";
320    String VERSION_GNU_ZERO  = "0\0";
321
322    /**
323     * The magic tag representing an Ant tar archive.
324     *
325     * @since 1.1
326     */
327    String MAGIC_ANT = "ustar\0";
328
329    /**
330     * The "version" representing an Ant tar archive.
331     *
332     * @since 1.1
333     */
334    // Does not appear to have a version, however Ant does write 8 bytes,
335    // so assume the version is 2 nulls
336    String VERSION_ANT = "\0\0";
337
338    /**
339     * The name of the GNU tar entry which contains a long name.
340     */
341    String GNU_LONGLINK = "././@LongLink"; // TODO rename as LONGLINK_GNU ?
342
343    /**
344     * The magix string used in the last four bytes of the header to
345     * identify the xstar format.
346     * @since 1.11
347     */
348    String MAGIC_XSTAR = "tar\0";
349
350    /**
351     * Offset inside the header for the xstar magic bytes.
352     * @since 1.11
353     */
354    int XSTAR_MAGIC_OFFSET = 508;
355
356    /**
357     * Length of the XSTAR magic.
358     * @since 1.11
359     */
360    int XSTAR_MAGIC_LEN = 4;
361
362    /**
363     * Length of the prefix field in xstar archives.
364     *
365     * @since 1.11
366     */
367    int PREFIXLEN_XSTAR = 131;
368
369    /**
370     * The length of the access time field in a xstar header buffer.
371     *
372     * @since 1.11
373     */
374    int ATIMELEN_XSTAR = 12;
375
376    /**
377     * The length of the created time field in a xstar header buffer.
378     *
379     * @since 1.11
380     */
381    int CTIMELEN_XSTAR = 12;
382}