home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / filutl / pdtar.arc / TAR.H < prev    next >
C/C++ Source or Header  |  1988-05-15  |  6KB  |  216 lines

  1. /*
  2.  * Header file for public domain tar (tape archive) program.
  3.  *
  4.  * @(#)tar.h 1.20 86/10/29    Public Domain.
  5.  *
  6.  * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
  7.  * MS-DOS port 2/87 by Eric Roskos.
  8.  * Minix  port 3/88 by Eric Roskos.
  9.  */
  10.  
  11. #define TRUE    1
  12. #define FALSE    0
  13.  
  14. /*
  15.  * Kludge for handling systems that can't cope with multiple
  16.  * external definitions of a variable.  In ONE routine (tar.c),
  17.  * we #define TAR_EXTERN to null; here, we set it to "extern" if
  18.  * it is not already set.
  19.  */
  20. #ifndef TAR_EXTERN
  21. #define TAR_EXTERN extern
  22. #endif
  23.  
  24. /*
  25.  * Header block on tape.
  26.  *
  27.  * I'm going to use traditional DP naming conventions here.
  28.  * A "block" is a big chunk of stuff that we do I/O on.
  29.  * A "record" is a piece of info that we care about.
  30.  * Typically many "record"s fit into a "block".
  31.  */
  32. #define    RECORDSIZE    512
  33. #define    NAMSIZ    100
  34. #define    TUNMLEN    32
  35. #define    TGNMLEN    32
  36.  
  37. union record {
  38.     char        charptr[RECORDSIZE];
  39.     struct header {
  40.         char    name[NAMSIZ];
  41.         char    mode[8];
  42.         char    uid[8];
  43.         char    gid[8];
  44.         char    size[12];
  45.         char    mtime[12];
  46.         char    chksum[8];
  47.         char    linkflag;
  48.         char    linkname[NAMSIZ];
  49.         char    magic[8];
  50.         char    uname[TUNMLEN];
  51.         char    gname[TGNMLEN];
  52.         char    devmajor[8];
  53.         char    devminor[8];
  54.     } header;
  55. };
  56.  
  57. /* The checksum field is filled with this while the checksum is computed. */
  58. #define    CHKBLANKS    "        "    /* 8 blanks, no null */
  59.  
  60. /* The magic field is filled with this if uname and gname are valid. */
  61. #define    TMAGIC        "ustar  "    /* 7 chars and a null */
  62.  
  63. /* The linkflag defines the type of file */
  64. #define    LF_OLDNORMAL    '\0'        /* Normal disk file, Unix compat */
  65. #define    LF_NORMAL    '0'        /* Normal disk file */
  66. #define    LF_LINK        '1'        /* Link to previously dumped file */
  67. #define    LF_SYMLINK    '2'        /* Symbolic link */
  68. #define    LF_CHR        '3'        /* Character special file */
  69. #define    LF_BLK        '4'        /* Block special file */
  70. #define    LF_DIR        '5'        /* Directory */
  71. #define    LF_FIFO        '6'        /* FIFO special file */
  72. #define    LF_CONTIG    '7'        /* Contiguous file */
  73. /* Further link types may be defined later. */
  74.  
  75. /*
  76.  * Exit codes from the "tar" program
  77.  */
  78. #define    EX_SUCCESS    0        /* success! */
  79. #define    EX_ARGSBAD    1        /* invalid args */
  80. #define    EX_BADFILE    2        /* invalid filename */
  81. #define    EX_BADARCH    3        /* bad archive */
  82. #define    EX_SYSTEM    4        /* system gave unexpected error */
  83.  
  84.  
  85. /*
  86.  * Global variables
  87.  */
  88. TAR_EXTERN union record    *ar_block;    /* Start of block of archive */
  89. TAR_EXTERN union record    *ar_record;    /* Current record of archive */
  90. TAR_EXTERN union record    *ar_last;    /* Last+1 record of archive block */
  91. TAR_EXTERN char        ar_reading;    /* 0 writing, !0 reading archive */
  92. TAR_EXTERN int        blocking;    /* Size of each block, in records */
  93. TAR_EXTERN int        blocksize;    /* Size of each block, in bytes */
  94. TAR_EXTERN char        *ar_file;    /* File containing archive */
  95. TAR_EXTERN char        *name_file;    /* File containing names to work on */
  96. TAR_EXTERN char        *tar;        /* Name of this program */
  97. TAR_EXTERN int        ftty;        /* used to prompt user */
  98. #ifdef MSDOS
  99. TAR_EXTERN int        physdrv;    /* physical drive # for DOS -V option */
  100. TAR_EXTERN int        devsize;    /* # blocks on physical drive */ 
  101. #endif /* MSDOS */
  102.  
  103. /*
  104.  * Flags from the command line
  105.  */
  106. TAR_EXTERN char    f_reblock;        /* -B */
  107. TAR_EXTERN char    f_create;        /* -c */
  108. TAR_EXTERN char    f_debug;        /* -d */
  109. TAR_EXTERN char    f_sayblock;        /* -D */
  110. TAR_EXTERN char    f_follow_links;        /* -h */
  111. TAR_EXTERN char    f_ignorez;        /* -i */
  112. TAR_EXTERN char    f_keep;            /* -k */
  113. TAR_EXTERN char    f_modified;        /* -m */
  114. TAR_EXTERN char    f_oldarch;        /* -o */
  115. TAR_EXTERN char    f_use_protection;    /* -p */
  116. TAR_EXTERN char    f_sorted_names;        /* -s */
  117. TAR_EXTERN char    f_list;            /* -t */
  118. TAR_EXTERN char    f_namefile;        /* -T */
  119. TAR_EXTERN char    f_verbose;        /* -v */
  120. #ifdef MSDOS
  121. TAR_EXTERN char f_phys;            /* -V */
  122. #endif
  123. TAR_EXTERN char    f_extract;        /* -x */
  124. TAR_EXTERN char    f_compress;        /* -z */
  125.  
  126. /*
  127.  * We now default to Unix Standard format rather than 4.2BSD tar format.
  128.  * The code can actually produce all three:
  129.  *    f_standard    ANSI standard
  130.  *    f_oldarch    V7
  131.  *    neither        4.2BSD
  132.  * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
  133.  * The only advantage to the "neither" option is that we can cmp(1) our
  134.  * output to the output of 4.2BSD tar, for debugging.
  135.  */
  136. #define        f_standard        (!f_oldarch)
  137.  
  138. /*
  139.  * Structure for keeping track of filenames and lists thereof.
  140.  */
  141. struct name {
  142.     struct name    *next;
  143.     short        length;
  144.     char        found;
  145.     char        name[NAMSIZ+1];
  146. };
  147.  
  148. TAR_EXTERN struct name    *namelist;    /* Points to first name in list */
  149. TAR_EXTERN struct name    *namelast;    /* Points to last name in list */
  150.  
  151. TAR_EXTERN int        archive;    /* File descriptor for archive file */
  152. TAR_EXTERN int        errors;        /* # of files in error */
  153.  
  154. /*
  155.  *
  156.  * Due to the next struct declaration, each routine that includes
  157.  * "tar.h" must also include <sys/types.h>.  I tried to make it automatic,
  158.  * but System V has no defines in <sys/types.h>, so there is no way of
  159.  * knowing when it has been included.  In addition, it cannot be included
  160.  * twice, but must be included exactly once.  Argghh!
  161.  *
  162.  * Thanks, typedef.  Thanks, USG.
  163.  */
  164. struct link {
  165.     struct link    *next;
  166.     dev_t        dev;
  167.     ino_t        ino;
  168.     short        linkcount;
  169.     char        name[NAMSIZ+1];
  170. };
  171.  
  172. TAR_EXTERN struct link    *linklist;    /* Points to first link in list */
  173.  
  174.  
  175. /*
  176.  * Error recovery stuff
  177.  */
  178. TAR_EXTERN char        read_error_flag;
  179.  
  180.  
  181. /*
  182.  * Declarations of functions available to the world.
  183.  */
  184. union record *findrec();
  185. void userec();
  186. union record *endofrecs();
  187. void anno();
  188. #define     annorec(stream, msg)    anno(stream, msg, 0)    /* Cur rec */
  189. #define    annofile(stream, msg)    anno(stream, msg, 1)    /* Saved rec */
  190.  
  191. /*
  192.  * Special definitions for MS/DOS
  193.  */
  194.  
  195. #ifdef MSDOS
  196.  
  197. /*
  198.  * Unix names/macros that aren't defined in MSC
  199.  */
  200. #define O_NDELAY    0
  201. #define major(n)    n
  202. #define minor(n)    0
  203.  
  204. /*
  205.  * the following bits of a file's mode are forced reset in an archive file
  206.  * created under DOS.  This is because DOS's stat() duplicates the (single-user)
  207.  * mode bits of DOS through the UGO fields of the mode.  This means that in
  208.  * general, a file un-tarred under Unix will be writable by everyone, which
  209.  * is almost never what someone would want.  022 makes it not writable by
  210.  * the group and others, and leaves the other bits unchanged.  You can
  211.  * adjust this if you want a different protection.
  212.  */
  213. #define DOSUMASK    022
  214.  
  215. #endif
  216.