Back to index

avfs  1.0.1
gtar.h
Go to the documentation of this file.
00001 /* Format of tar archives.
00002    Copyright (C) 1988, 92, 93, 94, 96, 97 Free Software Foundation, Inc.
00003 
00004    This program is free software; you can redistribute it and/or modify it
00005    under the terms of the GNU General Public License as published by the
00006    Free Software Foundation; either version 2, or (at your option) any later
00007    version.
00008 
00009    This program is distributed in the hope that it will be useful, but
00010    WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
00012    Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License along
00015    with this program; if not, write to the Free Software Foundation, Inc.,
00016    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00017 
00018 /* GNU tar Archive Format description.  */
00019 
00020 /* If OLDGNU_COMPATIBILITY is not zero, tar produces archives which, by
00021    default, are readable by older versions of GNU tar.  This can be
00022    overriden by using --posix; in this case, POSIXLY_CORRECT in environment
00023    may be set for enforcing stricter conformance.  If OLDGNU_COMPATIBILITY
00024    is zero or undefined, tar will eventually produces archives which, by
00025    default, POSIX compatible; then either using --posix or defining
00026    POSIXLY_CORRECT enforces stricter conformance.
00027 
00028    This #define will disappear in a few years.  FP, June 1995.  */
00029 #define OLDGNU_COMPATIBILITY 1
00030 
00031 /*---------------------------------------------.
00032 | `tar' Header Block, from POSIX 1003.1-1990.  |
00033 `---------------------------------------------*/
00034 
00035 /* POSIX header.  */
00036 
00037 struct posix_header
00038 {                           /* byte offset */
00039   char name[100];           /*   0 */
00040   char mode[8];                    /* 100 */
00041   char uid[8];                     /* 108 */
00042   char gid[8];                     /* 116 */
00043   char size[12];            /* 124 */
00044   char mtime[12];           /* 136 */
00045   char chksum[8];           /* 148 */
00046   char typeflag;            /* 156 */
00047   char linkname[100];              /* 157 */
00048   char magic[6];            /* 257 */
00049   char version[2];          /* 263 */
00050   char uname[32];           /* 265 */
00051   char gname[32];           /* 297 */
00052   char devmajor[8];         /* 329 */
00053   char devminor[8];         /* 337 */
00054   char prefix[155];         /* 345 */
00055                             /* 500 */
00056 };
00057 
00058 #define TMAGIC   "ustar"    /* ustar and a null */
00059 #define TMAGLEN  6
00060 #define TVERSION "00"              /* 00 and no null */
00061 #define TVERSLEN 2
00062 
00063 /* Values used in typeflag field.  */
00064 #define REGTYPE       '0'          /* regular file */
00065 #define AREGTYPE '\0'              /* regular file */
00066 #define LNKTYPE  '1'        /* link */
00067 #define SYMTYPE  '2'        /* reserved */
00068 #define CHRTYPE  '3'        /* character special */
00069 #define BLKTYPE  '4'        /* block special */
00070 #define DIRTYPE  '5'        /* directory */
00071 #define FIFOTYPE '6'        /* FIFO special */
00072 #define CONTTYPE '7'        /* reserved */
00073 
00074 /* Bits used in the mode field, values in octal.  */
00075 #define TSUID    04000             /* set UID on execution */
00076 #define TSGID    02000             /* set GID on execution */
00077 #define TSVTX    01000             /* reserved */
00078                             /* file permissions */
00079 #define TUREAD   00400             /* read by owner */
00080 #define TUWRITE  00200             /* write by owner */
00081 #define TUEXEC   00100             /* execute/search by owner */
00082 #define TGREAD   00040             /* read by group */
00083 #define TGWRITE  00020             /* write by group */
00084 #define TGEXEC   00010             /* execute/search by group */
00085 #define TOREAD   00004             /* read by other */
00086 #define TOWRITE  00002             /* write by other */
00087 #define TOEXEC   00001             /* execute/search by other */
00088 
00089 /*-------------------------------------.
00090 | `tar' Header Block, GNU extensions.  |
00091 `-------------------------------------*/
00092 
00093 /* In GNU tar, SYMTYPE is for to symbolic links, and CONTTYPE is for
00094    contiguous files, so maybe disobeying the `reserved' comment in POSIX
00095    header description.  I suspect these were meant to be used this way, and
00096    should not have really been `reserved' in the published standards.  */
00097 
00098 /* *BEWARE* *BEWARE* *BEWARE* that the following information is still
00099    boiling, and may change.  Even if the OLDGNU format description should be
00100    accurate, the so-called GNU format is not yet fully decided.  It is
00101    surely meant to use only extensions allowed by POSIX, but the sketch
00102    below repeats some ugliness from the OLDGNU format, which should rather
00103    go away.  Sparse files should be saved in such a way that they do *not*
00104    require two passes at archive creation time.  Huge files get some POSIX
00105    fields to overflow, alternate solutions have to be sought for this.  */
00106 
00107 /* Descriptor for a single file hole.  */
00108 
00109 struct sparse
00110 {                           /* byte offset */
00111   char offset[12];          /*   0 */
00112   char numbytes[12];        /*  12 */
00113                             /*  24 */
00114 };
00115 
00116 /* Sparse files are not supported in POSIX ustar format.  For sparse files
00117    with a POSIX header, a GNU extra header is provided which holds overall
00118    sparse information and a few sparse descriptors.  When an old GNU header
00119    replaces both the POSIX header and the GNU extra header, it holds some
00120    sparse descriptors too.  Whether POSIX or not, if more sparse descriptors
00121    are still needed, they are put into as many successive sparse headers as
00122    necessary.  The following constants tell how many sparse descriptors fit
00123    in each kind of header able to hold them.  */
00124 
00125 #define SPARSES_IN_EXTRA_HEADER  16
00126 #define SPARSES_IN_OLDGNU_HEADER 4
00127 #define SPARSES_IN_SPARSE_HEADER 21
00128 
00129 /* The GNU extra header contains some information GNU tar needs, but not
00130    foreseen in POSIX header format.  It is only used after a POSIX header
00131    (and never with old GNU headers), and immediately follows this POSIX
00132    header, when typeflag is a letter rather than a digit, so signaling a GNU
00133    extension.  */
00134 
00135 struct extra_header
00136 {                           /* byte offset */
00137   char atime[12];           /*   0 */
00138   char ctime[12];           /*  12 */
00139   char offset[12];          /*  24 */
00140   char realsize[12];        /*  36 */
00141   char longnames[4];        /*  48 */
00142   char unused_pad1[68];            /*  52 */
00143   struct sparse sp[SPARSES_IN_EXTRA_HEADER];
00144                             /* 120 */
00145   char isextended;          /* 504 */
00146                             /* 505 */
00147 };
00148 
00149 /* Extension header for sparse files, used immediately after the GNU extra
00150    header, and used only if all sparse information cannot fit into that
00151    extra header.  There might even be many such extension headers, one after
00152    the other, until all sparse information has been recorded.  */
00153 
00154 struct sparse_header
00155 {                           /* byte offset */
00156   struct sparse sp[SPARSES_IN_SPARSE_HEADER];
00157                             /*   0 */
00158   char isextended;          /* 504 */
00159                             /* 505 */
00160 };
00161 
00162 /* The old GNU format header conflicts with POSIX format in such a way that
00163    POSIX archives may fool old GNU tar's, and POSIX tar's might well be
00164    fooled by old GNU tar archives.  An old GNU format header uses the space
00165    used by the prefix field in a POSIX header, and cumulates information
00166    normally found in a GNU extra header.  With an old GNU tar header, we
00167    never see any POSIX header nor GNU extra header.  Supplementary sparse
00168    headers are allowed, however.  */
00169 
00170 struct oldgnu_header
00171 {                           /* byte offset */
00172   char unused_pad1[345];    /*   0 */
00173   char atime[12];           /* 345 */
00174   char ctime[12];           /* 357 */
00175   char offset[12];          /* 369 */
00176   char longnames[4];        /* 381 */
00177   char unused_pad2;         /* 385 */
00178   struct sparse sp[SPARSES_IN_OLDGNU_HEADER];
00179                             /* 386 */
00180   char isextended;          /* 482 */
00181   char realsize[12];        /* 483 */
00182                             /* 495 */
00183 };
00184 
00185 /* OLDGNU_MAGIC uses both magic and version fields, which are contiguous.
00186    Found in an archive, it indicates an old GNU header format, which will be
00187    hopefully become obsolescent.  With OLDGNU_MAGIC, uname and gname are
00188    valid, though the header is not truly POSIX conforming.  */
00189 #define OLDGNU_MAGIC "ustar  "     /* 7 chars and a null */
00190 
00191 /* The standards committee allows only capital A through capital Z for
00192    user-defined expansion.  */
00193 
00194 /* This is a dir entry that contains the names of files that were in the
00195    dir at the time the dump was made.  */
00196 #define GNUTYPE_DUMPDIR     'D'
00197 
00198 /* Identifies the *next* file on the tape as having a long linkname.  */
00199 #define GNUTYPE_LONGLINK 'K'
00200 
00201 /* Identifies the *next* file on the tape as having a long name.  */
00202 #define GNUTYPE_LONGNAME 'L'
00203 
00204 /* This is the continuation of a file that began on another volume.  */
00205 #define GNUTYPE_MULTIVOL 'M'
00206 
00207 /* For storing filenames that do not fit into the main header.  */
00208 #define GNUTYPE_NAMES 'N'
00209 
00210 /* This is for sparse files.  */
00211 #define GNUTYPE_SPARSE 'S'
00212 
00213 /* This file is a tape/volume header.  Ignore it on extraction.  */
00214 #define GNUTYPE_VOLHDR 'V'
00215 
00216 /*--------------------------------------.
00217 | tar Header Block, overall structure.  |
00218 `--------------------------------------*/
00219 
00220 /* tar files are made in basic blocks of this size.  */
00221 #define BLOCKSIZE 512
00222 
00223 enum archive_format
00224 {
00225   DEFAULT_FORMAT,           /* format to be decided later */
00226   V7_FORMAT,                /* old V7 tar format */
00227   OLDGNU_FORMAT,            /* GNU format as per before tar 1.12 */
00228   POSIX_FORMAT,                    /* restricted, pure POSIX format */
00229   GNU_FORMAT                /* POSIX format with GNU extensions */
00230 };
00231 
00232 union block
00233 {
00234   char buffer[BLOCKSIZE];
00235   struct posix_header header;
00236   struct extra_header extra_header;
00237   struct oldgnu_header oldgnu_header;
00238   struct sparse_header sparse_header;
00239 };
00240 
00241 /* End of Format description.  */