    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 sum of the length of all sparse headers in a sparse header buffer.
    190     *
    191     */
    192    int    SPARSELEN_GNU_SPARSE = 504;
    193
    194    /**
    195     * The length of the is extension field in a sparse header buffer.
    196     *
    197     */
    198    int    ISEXTENDEDLEN_GNU_SPARSE = 1;
    199
    200    /**
    201     * LF_ constants represent the "link flag" of an entry, or more commonly,
    202     * the "entry type". This is the "old way" of indicating a normal file.
    203     */
    204    byte   LF_OLDNORM = 0;
    205
    206    /**
    207     * Normal file type.
    208     */
    209    byte   LF_NORMAL = (byte) '0';
    210
    211    /**
    212     * Link file type.
    213     */
    214    byte   LF_LINK = (byte) '1';
    215
    216    /**
    217     * Symbolic link file type.
    218     */
    219    byte   LF_SYMLINK = (byte) '2';
    220
    221    /**
    222     * Character device file type.
    223     */
    224    byte   LF_CHR = (byte) '3';
    225
    226    /**
    227     * Block device file type.
    228     */
    229    byte   LF_BLK = (byte) '4';
    230
    231    /**
    232     * Directory file type.
    233     */
    234    byte   LF_DIR = (byte) '5';
    235
    236    /**
    237     * FIFO (pipe) file type.
    238     */
    239    byte   LF_FIFO = (byte) '6';
    240
    241    /**
    242     * Contiguous file type.
    243     */
    244    byte   LF_CONTIG = (byte) '7';
    245
    246    /**
    247     * Identifies the *next* file on the tape as having a long linkname.
    248     */
    249    byte LF_GNUTYPE_LONGLINK = (byte) 'K';
    250
    251    /**
    252     * Identifies the *next* file on the tape as having a long name.
    253     */
    254    byte LF_GNUTYPE_LONGNAME = (byte) 'L';
    255
    256    /**
    257     * Sparse file type.
    258     * @since 1.1.1
    259     */
    260    byte LF_GNUTYPE_SPARSE = (byte) 'S';
    261
    262    // See "http://www.opengroup.org/onlinepubs/009695399/utilities/pax.html#tag_04_100_13_02"
    263
    264    /**
    265     * Identifies the entry as a Pax extended header.
    266     * @since 1.1
    267     */
    268    byte LF_PAX_EXTENDED_HEADER_LC = (byte) 'x';
    269
    270    /**
    271     * Identifies the entry as a Pax extended header (SunOS tar -E).
    272     *
    273     * @since 1.1
    274     */
    275    byte LF_PAX_EXTENDED_HEADER_UC = (byte) 'X';
    276
    277    /**
    278     * Identifies the entry as a Pax global extended header.
    279     *
    280     * @since 1.1
    281     */
    282    byte LF_PAX_GLOBAL_EXTENDED_HEADER = (byte) 'g';
    283
    284    /**
    285     * The magic tag representing a POSIX tar archive.
    286     */
    287    String MAGIC_POSIX = "ustar\0";
    288    String VERSION_POSIX = "00";
    289
    290    /**
    291     * The magic tag representing a GNU tar archive.
    292     */
    293    String MAGIC_GNU = "ustar ";
    294    // Appear to be two possible GNU versions
    295    String VERSION_GNU_SPACE = " \0";
    296    String VERSION_GNU_ZERO  = "0\0";
    297
    298    /**
    299     * The magic tag representing an Ant tar archive.
    300     *
    301     * @since 1.1
    302     */
    303    String MAGIC_ANT = "ustar\0";
    304
    305    /**
    306     * The "version" representing an Ant tar archive.
    307     *
    308     * @since 1.1
    309     */
    310    // Does not appear to have a version, however Ant does write 8 bytes,
    311    // so assume the version is 2 nulls
    312    String VERSION_ANT = "\0\0";
    313
    314    /**
    315     * The name of the GNU tar entry which contains a long name.
    316     */
    317    String GNU_LONGLINK = "././@LongLink"; // TODO rename as LONGLINK_GNU ?
    318
    319    /**
    320     * The magix string used in the last four bytes of the header to
    321     * identify the xstar format.
    322     * @since 1.11
    323     */
    324    String MAGIC_XSTAR = "tar\0";
    325
    326    /**
    327     * Offset inside the header for the xstar magic bytes.
    328     * @since 1.11
    329     */
    330    int XSTAR_MAGIC_OFFSET = 508;
    331
    332    /**
    333     * Length of the XSTAR magic.
    334     * @since 1.11
    335     */
    336    int XSTAR_MAGIC_LEN = 4;
    337
    338    /**
    339     * Length of the prefix field in xstar archives.
    340     *
    341     * @since 1.11
    342     */
    343    int PREFIXLEN_XSTAR = 131;
    344
    345    /**
    346     * The length of the access time field in a xstar header buffer.
    347     *
    348     * @since 1.11
    349     */
    350    int ATIMELEN_XSTAR = 12;
    351
    352    /**
    353     * The length of the created time field in a xstar header buffer.
    354     *
    355     * @since 1.11
    356     */
    357    int CTIMELEN_XSTAR = 12;
    358}