home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gtak212.zip / 1.10 / tar.h < prev    next >
C/C++ Source or Header  |  1992-12-13  |  12KB  |  358 lines

  1. /*****************************************************************************
  2.  * $Id: tar.h,v 1.7 1992/12/13 09:39:27 ak Exp $
  3.  *****************************************************************************
  4.  * $Log: tar.h,v $
  5.  * Revision 1.7  1992/12/13  09:39:27  ak
  6.  * K.U.R: f_archive/f_reset_archive added to support the "archived" bit.
  7.  *
  8.  * Revision 1.6  1992/10/25  10:20:37  ak
  9.  * Don't archive/extract ctime+atime if a single -p or --same-perm is
  10.  * specified. It make trouble on incremental backups and file transfers.
  11.  * Added an option --all-timestamps or twice -p to archive/extract
  12.  * ctime+atime.
  13.  *
  14.  * Revision 1.5  1992/09/26  08:31:55  ak
  15.  * *** empty log message ***
  16.  *
  17.  * Revision 1.4  1992/09/20  07:46:53  ak
  18.  * Fixes from Kai Uwe Rommel
  19.  *   --checkpoints instead of --semi-verbose (1.11)
  20.  *   -g filenames
  21.  *
  22.  * Revision 1.3  1992/09/12  15:57:02  ak
  23.  * - Usenet patches for GNU TAR 1.10
  24.  * - Bugfixes and patches of Kai Uwe Rommel:
  25.  *         filename conversion for FAT
  26.  *         EMX 0.8e
  27.  *         -0..1 alias for a: b:
  28.  *         -2..7 alias for +++TAPE$x
  29.  *
  30.  * Revision 1.2  1992/09/02  20:08:51  ak
  31.  * Version AK200
  32.  * - Tape access
  33.  * - Quick file access
  34.  * - OS/2 extended attributes
  35.  * - Some OS/2 fixes
  36.  * - Some fixes of Kai Uwe Rommel
  37.  *
  38.  * Revision 1.1.1.1  1992/09/02  19:22:51  ak
  39.  * Original GNU Tar 1.10 with some filenames changed for FAT compatibility.
  40.  *
  41.  * Revision 1.1  1992/09/02  19:22:50  ak
  42.  * Initial revision
  43.  *
  44.  *****************************************************************************/
  45.  
  46. /*
  47.  * Modified by Andreas Kaiser July 92.
  48.  * See CHANGES.AK for info.
  49.  */
  50.  
  51. /*
  52.  
  53.     Copyright (C) 1988 Free Software Foundation
  54.  
  55. GNU tar is distributed in the hope that it will be useful, but WITHOUT ANY
  56. WARRANTY.  No author or distributor accepts responsibility to anyone
  57. for the consequences of using it or for whether it serves any
  58. particular purpose or works at all, unless he says so in writing.
  59. Refer to the GNU tar General Public License for full details.
  60.  
  61. Everyone is granted permission to copy, modify and redistribute GNU tar,
  62. but only under the conditions described in the GNU tar General Public
  63. License.  A copy of this license is supposed to have been given to you
  64. along with GNU tar so you can know your rights and responsibilities.  It
  65. should be in a file named COPYING.  Among other things, the copyright
  66. notice and this notice must be preserved on all copies.
  67.  
  68. In other words, go ahead and share GNU tar, but don't try to stop
  69. anyone else from sharing it farther.  Help stamp out software hoarding!
  70. */
  71.  
  72. /*
  73.  * Header file for tar (tape archive) program.
  74.  *
  75.  * @(#)tar.h 1.24 87/11/06
  76.  *
  77.  * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
  78.  */
  79.  
  80. #include "testpad.h"
  81.  
  82. /* major() and minor() macros (among other things) defined here for hpux */
  83. #ifdef hpux
  84. #include <sys/mknod.h>
  85. #endif
  86.  
  87. /*
  88.  * Kludge for handling systems that can't cope with multiple
  89.  * external definitions of a variable.  In ONE routine (tar.c),
  90.  * we #define TAR_EXTERN to null; here, we set it to "extern" if
  91.  * it is not already set.
  92.  */
  93. #ifndef TAR_EXTERN
  94. #define TAR_EXTERN extern
  95. #endif
  96.  
  97. #if defined(USG) && !defined(XENIX) && !defined(HAVE_SIZE_T)
  98. typedef int size_t;
  99. #endif
  100.  
  101. /*
  102.  * Header block on tape.
  103.  *
  104.  * I'm going to use traditional DP naming conventions here.
  105.  * A "block" is a big chunk of stuff that we do I/O on.
  106.  * A "record" is a piece of info that we care about.
  107.  * Typically many "record"s fit into a "block".
  108.  */
  109. #define    RECORDSIZE    512
  110. #define    NAMSIZ        100
  111. #define    TUNMLEN        32
  112. #define    TGNMLEN        32
  113. #define SPARSE_EXT_HDR  21
  114. #define SPARSE_IN_HDR    4
  115.  
  116. struct sparse {
  117.     char offset[12];
  118.     char numbytes[12];
  119. };
  120.  
  121. struct sp_array {
  122.     int offset;
  123.     int numbytes;
  124. };
  125.  
  126. union record {
  127.     char        charptr[RECORDSIZE];
  128.     struct header {
  129.         char    name[NAMSIZ];
  130.         char    mode[8];
  131.         char    uid[8];
  132.         char    gid[8];
  133.         char    size[12];
  134.         char    mtime[12];
  135.         char    chksum[8];
  136.         char    linkflag;
  137.         char    linkname[NAMSIZ];
  138.         char    magic[8];
  139.         char    uname[TUNMLEN];
  140.         char    gname[TGNMLEN];
  141.         char    devmajor[8];
  142.         char    devminor[8];
  143.         /* these following fields were added by JF for gnu */
  144.         /* and are NOT standard */
  145.         char    atime[12];
  146.         char    ctime[12];
  147.         char    offset[12];
  148.         char    longnames[4];
  149. #ifdef NEEDPAD
  150.         char    pad;
  151. #endif
  152.         struct    sparse sp[SPARSE_IN_HDR];
  153.         char    isextended;
  154.         char    realsize[12];        /* true size of the sparse file */
  155. /*        char    ending_blanks[12];*/    /* number of nulls at the
  156.                            end of the file, if any */
  157.     } header;
  158.     struct extended_header {
  159.         struct sparse sp[21];
  160.         char isextended;
  161.     } ext_hdr;
  162. };
  163.  
  164. /* The checksum field is filled with this while the checksum is computed. */
  165. #define    CHKBLANKS    "        "    /* 8 blanks, no null */
  166.  
  167. /* The magic field is filled with this if uname and gname are valid. */
  168. #define    TMAGIC        "ustar  "    /* 7 chars and a null */
  169.  
  170. /* The linkflag defines the type of file */
  171. #define    LF_OLDNORMAL    '\0'        /* Normal disk file, Unix compat */
  172. #define    LF_NORMAL    '0'        /* Normal disk file */
  173. #define    LF_LINK        '1'        /* Link to previously dumped file */
  174. #define    LF_SYMLINK    '2'        /* Symbolic link */
  175. #define    LF_CHR        '3'        /* Character special file */
  176. #define    LF_BLK        '4'        /* Block special file */
  177. #define    LF_DIR        '5'        /* Directory */
  178. #define    LF_FIFO        '6'        /* FIFO special file */
  179. #define    LF_CONTIG    '7'        /* Contiguous file */
  180. /* Further link types may be defined later. */
  181.  
  182. /* Note that the standards committee allows only capital A through
  183.    capital Z for user-defined expansion.  This means that defining something
  184.    as, say '8' is a *bad* idea. */
  185. #define LF_DUMPDIR    'D'        /* This is a dir entry that contains
  186.                        the names of files that were in
  187.                        the dir at the time the dump
  188.                        was made */
  189. #define LF_MULTIVOL    'M'        /* This is the continuation
  190.                        of a file that began on another
  191.                        volume */
  192. #define LF_NAMES    'N'        /* For storing filenames that didn't
  193.                        fit in 100 characters */
  194. #define LF_SPARSE    'S'        /* This is for sparse files */
  195. #define LF_VOLHDR    'V'        /* This file is a tape/volume header */
  196.                     /* Ignore it on extraction */
  197. #define LF_EATTR    'A'        /* extended attributes (OS/2) */
  198.  
  199. /*
  200.  * Exit codes from the "tar" program
  201.  */
  202. #define    EX_SUCCESS    0        /* success! */
  203. #define    EX_ARGSBAD    1        /* invalid args */
  204. #define    EX_BADFILE    2        /* invalid filename */
  205. #define    EX_BADARCH    3        /* bad archive */
  206. #define    EX_SYSTEM    4        /* system gave unexpected error */
  207. #define EX_BADVOL    5        /* Special error code means
  208.                        Tape volume doesn't match the one
  209.                        specified on the command line */
  210.  
  211. /*
  212.  * Global variables
  213.  */
  214. TAR_EXTERN union record    *ar_block;    /* Start of block of archive */
  215. TAR_EXTERN union record    *ar_record;    /* Current record of archive */
  216. TAR_EXTERN union record    *ar_last;    /* Last+1 record of archive block */
  217. TAR_EXTERN char        ar_reading;    /* 0 writing, !0 reading archive */
  218. TAR_EXTERN int        blocking;    /* Size of each block, in records */
  219. TAR_EXTERN int        blocksize;    /* Size of each block, in bytes */
  220. TAR_EXTERN char        *ar_file;    /* File containing archive */
  221. TAR_EXTERN char        *info_script;    /* Script to run at end of each tape change */
  222. TAR_EXTERN char        *name_file;    /* File containing names to work on */
  223. TAR_EXTERN char        *tar;        /* Name of this program */
  224. TAR_EXTERN struct sp_array *sparsearray;/* Pointer to the start of the scratch space */
  225. TAR_EXTERN int        sp_array_size;    /* Initial size of the sparsearray */
  226. TAR_EXTERN int         tot_written;    /* Total written to output */
  227. TAR_EXTERN struct re_pattern_buffer
  228.               *label_pattern;    /* compiled regex for extract label */
  229. TAR_EXTERN int        is_device;    /* Archive is device */
  230.  
  231. /*
  232.  * Flags from the command line
  233.  */
  234. TAR_EXTERN int cmd_mode;
  235. #define CMD_NONE    0
  236. #define CMD_CAT        1        /* -A */
  237. #define CMD_CREATE    2        /* -c */
  238. #define CMD_DIFF    3        /* -d */
  239. #define CMD_APPEND    4        /* -r */
  240. #define CMD_LIST    5        /* -t */
  241. #define CMD_UPDATE    6        /* -u */
  242. #define CMD_EXTRACT    7        /* -x */
  243. #define CMD_DELETE    8        /* -D */
  244. #define CMD_VERSION    9        /* +version */
  245.  
  246.                     /* -[0-9][lmh] */
  247.             /* CMD_CAT       -A */
  248.                     /* -b */
  249. TAR_EXTERN int    f_reblock;        /* -B */
  250.             /* CMD_CREATE       -c */
  251.                     /* -C */
  252.             /* CMD_DIFF       -d */
  253. /* TAR_EXTERN char    f_dironly;    /* -D */
  254. TAR_EXTERN int    f_checkpoints;        /* -E */
  255.                     /* -f */
  256. TAR_EXTERN int    f_run_script_at_end;    /* -F */
  257. TAR_EXTERN int     f_gnudump;        /* -G */
  258. TAR_EXTERN int    f_follow_links;        /* -h */
  259. TAR_EXTERN int    f_host;            /* -H */
  260. TAR_EXTERN int    f_ignorez;        /* -i */
  261.             /* CMD_DELETE       -J */
  262. TAR_EXTERN int    f_keep;            /* -k */
  263. TAR_EXTERN int    f_startfile;        /* -K */
  264. TAR_EXTERN int    f_local_filesys;    /* -l */
  265. TAR_EXTERN int  tape_length;        /* -L */
  266. TAR_EXTERN int    f_modified;        /* -m */
  267. TAR_EXTERN int     f_multivol;        /* -M */
  268. TAR_EXTERN int    f_new_files;        /* -N */
  269. TAR_EXTERN int    f_oldarch;        /* -o */
  270. TAR_EXTERN int  f_exstdout;        /* -O */
  271. TAR_EXTERN int    f_use_protection;    /* -p */
  272. TAR_EXTERN int  f_absolute_paths;    /* -P */
  273. TAR_EXTERN int    f_sayblock;        /* -R */
  274. TAR_EXTERN int  f_show_omitted_dirs;    /* +show-omitted-dirs */
  275. TAR_EXTERN int    f_sorted_names;        /* -s */
  276. TAR_EXTERN int    f_sparse_files;        /* -S  ... JK */
  277. TAR_EXTERN int    f_namefile;        /* -T */
  278.             /* CMD_UPDATE       -u */
  279. TAR_EXTERN int    f_verbose;        /* -v */
  280. TAR_EXTERN char *f_volhdr;        /* -V */
  281. TAR_EXTERN int  f_confirm;        /* -w */
  282. TAR_EXTERN int  f_verify;        /* -W */
  283.             /* CMD_EXTRACT     -x */
  284. TAR_EXTERN int  f_exclude;        /* -X */
  285. TAR_EXTERN int     f_no_recursion;        /* -Y */
  286. TAR_EXTERN int     f_compress;        /* -z */
  287. TAR_EXTERN int    f_buffered;        /* -Z */
  288. TAR_EXTERN int    f_do_chown;        /* +do-chown */
  289. TAR_EXTERN int  f_totals;        /* +totals */
  290. TAR_EXTERN char    *f_map_file;        /* +tape-directory */
  291. TAR_EXTERN int    f_one_level;        /* +no-recursion */
  292. TAR_EXTERN int    f_fat;            /* +fat */
  293. #ifdef OS2
  294. TAR_EXTERN int    f_archive;        /* +modified */
  295. TAR_EXTERN int    f_reset_archive;    /* +reset-archive */
  296. TAR_EXTERN int    f_all_timestamps;    /* +all-timestamps */
  297. #endif
  298.  
  299. /*
  300.  * We now default to Unix Standard format rather than 4.2BSD tar format.
  301.  * The code can actually produce all three:
  302.  *    f_standard    ANSI standard
  303.  *    f_oldarch    V7
  304.  *    neither        4.2BSD
  305.  * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
  306.  * The only advantage to the "neither" option is that we can cmp our
  307.  * output to the output of 4.2BSD tar, for debugging.
  308.  */
  309. #define        f_standard        (!f_oldarch)
  310.  
  311. /*
  312.  * Structure for keeping track of filenames and lists thereof.
  313.  */
  314. struct name {
  315.     struct name    *next;
  316.     short        length;        /* cached strlen(name) */
  317.     char        found;        /* A matching file has been found */
  318.     char        firstch;    /* First char is literally matched */
  319.     char        regexp;        /* This name is a regexp, not literal */
  320.     char        *change_dir;    /* JF set with the -C option */
  321.     char        *dir_contents;    /* JF for f_gnudump */
  322.     char        fake;        /* dummy entry */
  323.     char        name[1];
  324. };
  325.  
  326. TAR_EXTERN struct name    *namelist;    /* Points to first name in list */
  327. TAR_EXTERN struct name    *namelast;    /* Points to last name in list */
  328.  
  329. TAR_EXTERN int        archive;    /* File descriptor for archive file */
  330. TAR_EXTERN int        errors;        /* # of files in error */
  331.  
  332. TAR_EXTERN char *gnu_dumpfile;
  333.  
  334. /*
  335.  * Error recovery stuff
  336.  */
  337. TAR_EXTERN char        read_error_flag;
  338.  
  339.  
  340. /*
  341.  * Declarations of functions available to the world.
  342.  */
  343. union record *findrec();
  344. void userec();
  345. union record *endofrecs();
  346. void anno();
  347.  
  348. /* Do not prototype these for BSD--see port.c [DOPRNT_MSG].  */
  349. #if defined(__STDC__) && (!defined(BSD42) || defined(STDC_MSG))
  350. void msg(char *, ...);
  351. void msg_perror(char *, ...);
  352. #else
  353. void msg();
  354. void msg_perror();
  355. #endif
  356. /* #define     annorec(stream, msg)    anno(stream, msg, 0)    /* Cur rec */
  357. /* #define    annofile(stream, msg)    anno(stream, msg, 1)    /* Saved rec */
  358.