home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 May / W2KPRK.iso / apps / posix / source / PAX / PAX.H < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-17  |  11.2 KB  |  417 lines

  1. /* $Source: /u/mark/src/pax/RCS/pax.h,v $
  2.  *
  3.  * $Revision: 1.2 $
  4.  *
  5.  * pax.h - defnitions for entire program
  6.  *
  7.  * DESCRIPTION
  8.  *
  9.  *    This file contains most all of the definitions required by the PAX
  10.  *    software.  This header is included in every source file.
  11.  *
  12.  * AUTHOR
  13.  *
  14.  *     Mark H. Colburn, NAPS International (mark@jhereg.mn.org)
  15.  *
  16.  * Sponsored by The USENIX Association for public distribution. 
  17.  *
  18.  * Copyright (c) 1989 Mark H. Colburn.
  19.  * All rights reserved.
  20.  *
  21.  * Redistribution and use in source and binary forms are permitted
  22.  * provided that the above copyright notice and this paragraph are
  23.  * duplicated in all such forms and that any documentation,
  24.  * advertising materials, and other materials related to such
  25.  * distribution and use acknowledge that the software was developed
  26.  * by Mark H. Colburn and sponsored by The USENIX Association. 
  27.  *
  28.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  29.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  30.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  31.  */
  32.  
  33. #ifndef _PAX_H
  34. #define _PAX_H
  35.  
  36. /* Headers */
  37.  
  38. #include "config.h"
  39. #include "limits.h"
  40. #include <stdio.h>
  41. #ifdef __STDC__  /* Xn */
  42. #   include <stdlib.h>  /* Xn */
  43. #endif  /* Xn */
  44. #include <errno.h>
  45. #include <signal.h>
  46. #include <ctype.h>
  47. #include <sys/types.h>
  48. #ifdef _POSIX_SOURCE  /* Xn */
  49. #   include <utime.h>  /* Xn */
  50. #   include <unistd.h>  /* Xn */
  51. #else  /* Xn */
  52. #   include <sys/ioctl.h>  /* Xn */
  53. #endif  /* Xn */
  54. #include <sys/stat.h>
  55. #include "regexp.h"
  56.  
  57. #if defined(DIRENT) || defined(_POSIX_SOURCE)
  58. # ifdef PAXDIR
  59. #  include "paxdir.h"
  60. # else
  61. #  include <dirent.h>
  62. # endif
  63. #else
  64. # ifdef hpux
  65. #  include <ndir.h>
  66. # else
  67. #  ifdef XENIX_286
  68. #   include <sys/ndir.h>
  69. #  else /* XENIX_286 */
  70. #   include <sys/dir.h>
  71. #  endif /* XENIX_286 */
  72. # endif /* hpux */
  73. # define dirent direct
  74. #endif
  75.  
  76. #ifndef    major
  77. #   include <sys/sysmacros.h>
  78. #endif                /* major */
  79.  
  80. #ifdef    SYSTIME
  81. #   include <sys/time.h>
  82. #else                /* SYSTIME */
  83. #   include <time.h>
  84. #endif                /* SYSTIME */
  85.  
  86. #ifndef V7
  87. #   include <fcntl.h>
  88. #endif
  89.  
  90. #ifdef XENIX
  91. #   include <sys/inode.h>
  92. #endif
  93. #ifdef XENIX_286
  94. #include <sys/param.h>
  95. #endif /* XENIX_286 */
  96.  
  97. #include <pwd.h>
  98. #include <grp.h>
  99. #ifndef XENIX_286
  100. #   ifndef _POSIX_SOURCE  /* Xn */
  101. #       include <sys/file.h>  /* Xn */
  102. #   endif /* _POSIX_SOURCE */  /* Xn */
  103. #endif /* XENIX_286 */
  104.  
  105. /* Defines */
  106.  
  107. #ifdef _POSIX_SOURCE  /* Xn */
  108. #   define    STDIN    STDIN_FILENO        /* Standard input  file descriptor */  /* Xn */
  109. #   define    STDOUT    STDOUT_FILENO        /* Standard output file descriptor */  /* Xn */
  110. #else  /* Xn */
  111. #   define    STDIN    0        /* Standard input  file descriptor */  /* Xn */
  112. #   define    STDOUT    1        /* Standard output file descriptor */  /* Xn */
  113. #endif  /* Xn */
  114.  
  115. /*
  116.  * Open modes; there is no <fcntl.h> with v7 UNIX and other versions of
  117.  * UNIX may not have all of these defined...
  118.  */
  119.  
  120. #ifndef O_RDONLY
  121. #   define    O_RDONLY    0
  122. #endif
  123.  
  124. #ifndef O_WRONLY
  125. #   define    O_WRONLY    1
  126. #endif
  127.  
  128. #ifndef O_RDWR
  129. #   define    O_RDWR    2  /* Xn */
  130. #endif
  131.  
  132. #ifndef    O_BINARY
  133. #   define    O_BINARY    0
  134. #endif
  135.   /* Xn */
  136. /*  Xn
  137.  * Lseek symbolic constants; there is no <unistd.h> with most UNIXes, so  Xn
  138.  * all of these may not be defined...  Xn
  139.  */  /* Xn */
  140.   /* Xn */
  141. #ifndef SEEK_SET  /* Xn */
  142. #   define    SEEK_SET    0  /* Xn */
  143. #endif  /* Xn */
  144.   /* Xn */
  145. #ifndef SEEK_CUR  /* Xn */
  146. #   define    SEEK_CUR    1  /* Xn */
  147. #endif  /* Xn */
  148.   /* Xn */
  149. #ifndef SEEK_END  /* Xn */
  150. #   define    SEEK_END    2  /* Xn */
  151. #endif  /* Xn */
  152.  
  153. #ifndef NULL
  154. #   ifdef __STDC__  /* Xn */
  155. #       define     NULL         ((void *) 0)  /* Xn */
  156. #   else  /* Xn */
  157. #       define     NULL         ((char *) 0)  /* Xn */
  158. #   endif  /* Xn */
  159. #endif
  160.  
  161. #define TMAGIC        "ustar"        /* ustar and a null */
  162. #define TMAGLEN        6
  163. #define TVERSION    "00"        /* 00 and no null */
  164. #define TVERSLEN    2
  165.  
  166. /* Values used in typeflag field */
  167. #define REGTYPE        '0'        /* Regular File */
  168. #define AREGTYPE    '\0'        /* Regular File */
  169. #define LNKTYPE        '1'        /* Link */
  170. #define SYMTYPE        '2'        /* Reserved */
  171. #define CHRTYPE        '3'        /* Character Special File */
  172. #define BLKTYPE        '4'        /* Block Special File */
  173. #define DIRTYPE        '5'        /* Directory */
  174. #define FIFOTYPE    '6'        /* FIFO */
  175. #define CONTTYPE    '7'        /* Reserved */
  176. #define SOCKTYPE    'S'        /* Socket */  /* Xn */
  177.  
  178. #define BLOCKSIZE    512    /* all output is padded to 512 bytes */
  179. #define    uint    unsigned int    /* Not always in types.h */
  180. #define    ushort    unsigned short    /* Not always in types.h */
  181. #define    BLOCK    5120        /* Default archive block size */
  182. #define    H_COUNT    10        /* Number of items in ASCII header */
  183. #define    H_PRINT    "%06o%06o%06o%06o%06o%06o%06o%011lo%06o%011lo"
  184. #define    H_SCAN    "%6ho%6ho%6ho%6ho%6ho%6ho%6ho%11lo%6o%11lo"
  185. #define    H_STRLEN 70        /* ASCII header string length */
  186. #define    M_ASCII "070707"    /* ASCII magic number */
  187. #define    M_BINARY 070707        /* Binary magic number */
  188. #define    M_STRLEN 6        /* ASCII magic number length */
  189. #define    PATHELEM 256        /* Pathname element count limit */
  190. #define    S_IFSHF    12        /* File type shift (shb in stat.h) */
  191. #ifndef S_IPERM  /* Xn */
  192. #   define    S_IPERM    07777        /* File permission bits (shb in stat.h) */  /* Xn */
  193. #endif  /* Xn */
  194. #define    S_IPEXE    07000        /* Special execution bits (shb in stat.h) */
  195. #define    S_IPOPN    0777        /* Open access bits (shb in stat.h) */
  196.  
  197. /*
  198.  * Trailer pathnames. All must be of the same length. 
  199.  */
  200. #define    TRAILER    "TRAILER!!!"    /* Archive trailer (cpio compatible) */
  201. #define    TRAILZ    11        /* Trailer pathname length (including null) */
  202.  
  203. #include "port.h"
  204.  
  205.  
  206. #define    TAR        1
  207. #define    CPIO        2
  208. #define    PAX        3
  209.  
  210. #define AR_READ     0
  211. #define AR_WRITE     1
  212. #define AR_EXTRACT    2
  213. #define AR_APPEND     4
  214.  
  215. /*
  216.  * Header block on tape. 
  217.  */
  218. #define    NAMSIZ        100
  219. #define    PFIXSIZ        155
  220. #define    TUNMLEN        32
  221. #define    TGNMLEN        32
  222.  
  223. /* The checksum field is filled with this while the checksum is computed. */
  224. #define    CHKBLANKS    "        "    /* 8 blanks, no null */
  225.  
  226. /*
  227.  * Exit codes from the "tar" program 
  228.  */
  229. #define    EX_SUCCESS    0    /* success! */
  230. #define    EX_ARGSBAD    1    /* invalid args */
  231. #define    EX_BADFILE    2    /* invalid filename */
  232. #define    EX_BADARCH    3    /* bad archive */
  233. #define    EX_SYSTEM    4    /* system gave unexpected error */
  234.  
  235. #define    ROUNDUP(a,b)     (((a) % (b)) == 0 ? (a) : ((a) + ((b) - ((a) % (b)))))
  236.  
  237. /*
  238.  * Mininum value. 
  239.  */
  240. #define    MIN(a, b)    (((a) < (b)) ? (a) : (b))
  241.  
  242. /*
  243.  * Remove a file or directory. 
  244.  */
  245. #define    REMOVE(name, asb) \
  246.     (((asb)->sb_mode & S_IFMT) == S_IFDIR ? rmdir(name) : unlink(name))
  247.  
  248. /*
  249.  * Cast and reduce to unsigned short. 
  250.  */
  251. #define    USH(n)        ((n) & 0777777)
  252.  
  253.  
  254. /* Type Definitions */
  255.  
  256. /*
  257.  * Binary archive header (obsolete). 
  258.  */
  259. typedef struct {
  260.     short           b_dev;    /* Device code */
  261.     ushort          b_ino;    /* Inode number */
  262.     ushort          b_mode;    /* Type and permissions */
  263.     ushort          b_uid;    /* Owner */
  264.     ushort          b_gid;    /* Group */
  265.     short           b_nlink;    /* Number of links */
  266.     short           b_rdev;    /* Real device */
  267.     ushort          b_mtime[2];    /* Modification time (hi/lo) */
  268.     ushort          b_name;    /* Length of pathname (with null) */
  269.     ushort          b_size[2];    /* Length of data */
  270. } Binary;
  271.  
  272. /*
  273.  * File status with symbolic links. Kludged to hold symbolic link pathname
  274.  * within structure. 
  275.  */
  276. typedef struct {
  277.     struct stat     sb_stat;
  278.     char            sb_link[PATH_MAX + 1];
  279. } Stat;
  280.  
  281. #define    STAT(name, asb)        stat(name, &(asb)->sb_stat)
  282. #define    FSTAT(fd, asb)        fstat(fd, &(asb)->sb_stat)
  283.  
  284. #define    sb_dev        sb_stat.st_dev
  285. #define    sb_ino        sb_stat.st_ino
  286. #define    sb_mode        sb_stat.st_mode
  287. #define    sb_nlink    sb_stat.st_nlink
  288. #define    sb_uid        sb_stat.st_uid
  289. #define    sb_gid        sb_stat.st_gid
  290. #define    sb_rdev        sb_stat.st_rdev
  291. #define    sb_size        sb_stat.st_size
  292. #define    sb_atime    sb_stat.st_atime
  293. #define    sb_mtime    sb_stat.st_mtime
  294. #define    sb_ctime    sb_stat.st_ctime
  295.  
  296. #ifdef    S_IFLNK
  297. #    define    LSTAT(name, asb)    lstat(name, &(asb)->sb_stat)
  298. #    define    sb_blksize    sb_stat.st_blksize
  299. #    define    sb_blocks    sb_stat.st_blocks
  300. #else                /* S_IFLNK */
  301. /*
  302.  * File status without symbolic links. 
  303.  */
  304. #    define    LSTAT(name, asb)    stat(name, &(asb)->sb_stat)
  305. #endif                /* S_IFLNK */
  306.  
  307. /*
  308.  * Hard link sources. One or more are chained from each link structure. 
  309.  */
  310. typedef struct name {
  311.     struct name    *p_forw;    /* Forward chain (terminated) */
  312.     struct name    *p_back;    /* Backward chain (circular) */
  313.     char           *p_name;    /* Pathname to link from */
  314. } Path;
  315.  
  316. /*
  317.  * File linking information. One entry exists for each unique file with with
  318.  * outstanding hard links. 
  319.  */
  320. typedef struct link {
  321.     struct link    *l_forw;    /* Forward chain (terminated) */
  322.     struct link    *l_back;    /* Backward chain (terminated) */
  323.     dev_t           l_dev;    /* Device */
  324.     ino_t           l_ino;    /* Inode */
  325. #ifdef _POSIX_SOURCE  /* Xn */
  326.     nlink_t         l_nlink;    /* Unresolved link count */  /* Xn */
  327. #else  /* Xn */
  328.     ushort          l_nlink;    /* Unresolved link count */
  329. #endif  /* Xn */
  330.     OFFSET          l_size;    /* Length */
  331.     char       *l_name;    /* pathname to link from */
  332.     Path           *l_path;    /* Pathname which link to l_name */
  333. } Link;
  334.  
  335. /*
  336.  * Structure for ed-style replacement strings (-s option).
  337. */
  338. typedef struct replstr {
  339.     regexp       *comp;    /* compiled regular expression */
  340.     char       *replace;    /* replacement string */
  341.     char        print;    /* >0 if we are to print replacement */
  342.     char        global;    /* >0 if we are to replace globally */
  343.     struct replstr *next;    /* pointer to next record */
  344. } Replstr;
  345.  
  346.  
  347. /*
  348.  * This has to be included here to insure that all of the type 
  349.  * delcarations are declared for the prototypes.
  350.  */
  351. #include "func.h"
  352.  
  353.  
  354. #ifndef NO_EXTERN
  355. /* Globally Available Identifiers */
  356.  
  357. extern char    *ar_file;
  358. extern char    *bufend;
  359. extern char    *bufstart;
  360. extern char    *bufidx;
  361. extern char    *myname;
  362. extern int      archivefd;
  363. extern int      blocking;
  364. extern uint     blocksize;
  365. extern int      gid;
  366. extern int      head_standard;
  367. extern int      ar_interface;
  368. extern int      ar_format;
  369. extern int      mask;
  370. extern int      ttyf;
  371. extern int      uid;
  372. extern OFFSET    total;
  373. extern short    areof;
  374. extern short    f_append;
  375. extern short    f_create;
  376. extern short    f_extract;
  377. extern short    f_follow_links;
  378. extern short    f_interactive;
  379. extern short    f_linksleft;
  380. extern short    f_list;
  381. extern short    f_modified;
  382. extern short    f_verbose;
  383. extern short    f_link;
  384. extern short    f_owner;
  385. extern short    f_access_time;
  386. extern short    f_pass;
  387. extern short    f_quiet;  /* Xn */
  388. extern short    f_disposition;
  389. extern short    f_reverse_match;
  390. extern short    f_mtime;
  391. extern short    f_dir_create;
  392. extern short    f_unconditional;
  393. extern short    f_newer;
  394. extern time_t   now;
  395. extern uint     arvolume;
  396. extern int    names_from_stdin;
  397. extern Replstr *rplhead;
  398. extern Replstr *rpltail;
  399. extern char   **n_argv;
  400. extern int      n_argc;
  401. extern FILE    *msgfile;
  402. # if 1 && WIN_NT
  403. extern pid_t ppid;
  404. extern int globulation;
  405. # endif
  406. #endif /* NO_EXTERN */
  407.  
  408. extern char    *optarg;
  409. extern int      optind;
  410. extern int      sys_nerr;
  411. extern char    *sys_errlist[];
  412. #ifndef _POSIX_SOURCE  /* Xn */
  413. extern int      errno;
  414. #endif  /* Xn */
  415.  
  416. #endif /* _PAX_H */
  417.