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