pax.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. #ifndef _PAX_H
  33. #define _PAX_H
  34. /* Headers */
  35. #include "config.h"
  36. #include "limits.h"
  37. #include <stdio.h>
  38. #include <errno.h>
  39. #include <signal.h>
  40. #include <ctype.h>
  41. #include <sys/types.h>
  42. #ifndef _POSIX_SOURCE
  43. #include <sys/ioctl.h>
  44. #endif
  45. #include <sys/stat.h>
  46. #include "regexp.h"
  47. #if defined(DIRENT) || defined(_POSIX_SOURCE)
  48. # ifdef PAXDIR
  49. # include "paxdir.h"
  50. # else
  51. # include <dirent.h>
  52. # endif
  53. #else
  54. # ifdef hpux
  55. # include <ndir.h>
  56. # else
  57. # ifdef XENIX_286
  58. # include <sys/ndir.h>
  59. # else XENIX_286
  60. # include <sys/dir.h>
  61. # endif XENIX_286
  62. # endif /* hpux */
  63. # define dirent direct
  64. #endif
  65. #ifdef _POSIX_SOURCE
  66. #define major(x) 0
  67. #define minor(x) 0
  68. #else
  69. #ifndef major
  70. # include <sys/sysmacros.h>
  71. #endif /* major */
  72. #endif
  73. #ifdef SYSTIME
  74. # include <sys/time.h>
  75. #else /* SYSTIME */
  76. # include <time.h>
  77. #endif /* SYSTIME */
  78. #ifndef V7
  79. # include <fcntl.h>
  80. #endif
  81. #ifdef XENIX
  82. # include <sys/inode.h>
  83. #endif
  84. #ifdef XENIX_286
  85. #include <sys/param.h>
  86. #endif XENIX_286
  87. #include <pwd.h>
  88. #include <grp.h>
  89. #ifndef XENIX_286
  90. #ifndef _POSIX_SOURCE
  91. #include <sys/file.h>
  92. #endif
  93. #endif /* XENIX_286 */
  94. #ifdef _POSIX_SOURCE
  95. #include <unistd.h>
  96. #include <stdlib.h>
  97. #endif
  98. /* Defines */
  99. #define STDIN 0 /* Standard input file descriptor */
  100. #define STDOUT 1 /* Standard output file descriptor */
  101. /*
  102. * Open modes; there is no <fcntl.h> with v7 UNIX and other versions of
  103. * UNIX may not have all of these defined...
  104. */
  105. #ifndef O_RDONLY
  106. # define O_RDONLY 0
  107. #endif
  108. #ifndef O_WRONLY
  109. # define O_WRONLY 1
  110. #endif
  111. #ifndef O_RDWR
  112. # define O_WRONLY 2
  113. #endif
  114. #ifndef O_BINARY
  115. # define O_BINARY 0
  116. #endif
  117. #ifndef NULL
  118. # define NULL 0
  119. #endif
  120. #define TMAGIC "ustar" /* ustar and a null */
  121. #define TMAGLEN 6
  122. #define TVERSION "00" /* 00 and no null */
  123. #define TVERSLEN 2
  124. /* Values used in typeflag field */
  125. #define REGTYPE '0' /* Regular File */
  126. #define AREGTYPE '\0' /* Regular File */
  127. #define LNKTYPE '1' /* Link */
  128. #define SYMTYPE '2' /* Reserved */
  129. #define CHRTYPE '3' /* Character Special File */
  130. #define BLKTYPE '4' /* Block Special File */
  131. #define DIRTYPE '5' /* Directory */
  132. #define FIFOTYPE '6' /* FIFO */
  133. #define CONTTYPE '7' /* Reserved */
  134. #define BLOCKSIZE 512 /* all output is padded to 512 bytes */
  135. #define uint unsigned int /* Not always in types.h */
  136. #define ushort unsigned short /* Not always in types.h */
  137. #define BLOCK 5120 /* Default archive block size */
  138. #define H_COUNT 10 /* Number of items in ASCII header */
  139. #define H_PRINT "%06o%06o%06o%06o%06o%06o%06o%011lo%06o%011lo"
  140. #define H_SCAN "%6ho%6ho%6ho%6ho%6ho%6ho%6ho%11lo%6o%11lo"
  141. #define H_STRLEN 70 /* ASCII header string length */
  142. #define M_ASCII "070707" /* ASCII magic number */
  143. #define M_BINARY 070707 /* Binary magic number */
  144. #define M_STRLEN 6 /* ASCII magic number length */
  145. #define PATHELEM 256 /* Pathname element count limit */
  146. #define S_IFSHF 12 /* File type shift (shb in stat.h) */
  147. #define S_IPERM 07777 /* File permission bits (shb in stat.h) */
  148. #define S_IPEXE 07000 /* Special execution bits (shb in stat.h) */
  149. #define S_IPOPN 0777 /* Open access bits (shb in stat.h) */
  150. #ifdef _POSIX_SOURCE
  151. /* hack: depend on knowing bits out of stat.h for S_ISREG, etc. */
  152. #define S_IFMT 0170000
  153. #define S_IFREG 0100000
  154. #define S_IFDIR 0040000
  155. #define S_IFCHR 0020000
  156. #define S_IFBLK 0060000
  157. #define S_IFIFO 0010000
  158. #endif
  159. /*
  160. * Trailer pathnames. All must be of the same length.
  161. */
  162. #define TRAILER "TRAILER!!!" /* Archive trailer (cpio compatible) */
  163. #define TRAILZ 11 /* Trailer pathname length (including null) */
  164. #include "port.h"
  165. #define TAR 1
  166. #define CPIO 2
  167. #define PAX 3
  168. #define AR_READ 0
  169. #define AR_WRITE 1
  170. #define AR_EXTRACT 2
  171. #define AR_APPEND 4
  172. /*
  173. * Header block on tape.
  174. */
  175. #define NAMSIZ 100
  176. #define PFIXSIZ 155
  177. #define TUNMLEN 32
  178. #define TGNMLEN 32
  179. /* The checksum field is filled with this while the checksum is computed. */
  180. #define CHKBLANKS " " /* 8 blanks, no null */
  181. /*
  182. * Exit codes from the "tar" program
  183. */
  184. #define EX_SUCCESS 0 /* success! */
  185. #define EX_ARGSBAD 1 /* invalid args */
  186. #define EX_BADFILE 2 /* invalid filename */
  187. #define EX_BADARCH 3 /* bad archive */
  188. #define EX_SYSTEM 4 /* system gave unexpected error */
  189. #define ROUNDUP(a,b) (((a) % (b)) == 0 ? (a) : ((a) + ((b) - ((a) % (b)))))
  190. /*
  191. * Mininum value.
  192. */
  193. #define MIN(a, b) (((a) < (b)) ? (a) : (b))
  194. /*
  195. * Remove a file or directory.
  196. */
  197. #ifdef _POSIX_SOURCE
  198. #define REMOVE(name, asb) \
  199. (S_ISDIR((asb)->sb_mode)? rmdir(name) : unlink(name))
  200. #else
  201. #define REMOVE(name, asb) \
  202. (((asb)->sb_mode & S_IFMT) == S_IFDIR ? rmdir(name) : unlink(name))
  203. #endif
  204. /*
  205. * Cast and reduce to unsigned short.
  206. */
  207. #define USH(n) (((ushort) (n)) & 0177777)
  208. /* Type Definitions */
  209. /*
  210. * Binary archive header (obsolete).
  211. */
  212. typedef struct {
  213. short b_dev; /* Device code */
  214. ushort b_ino; /* Inode number */
  215. ushort b_mode; /* Type and permissions */
  216. ushort b_uid; /* Owner */
  217. ushort b_gid; /* Group */
  218. short b_nlink; /* Number of links */
  219. short b_rdev; /* Real device */
  220. ushort b_mtime[2]; /* Modification time (hi/lo) */
  221. ushort b_name; /* Length of pathname (with null) */
  222. ushort b_size[2]; /* Length of data */
  223. } Binary;
  224. /*
  225. * File status with symbolic links. Kludged to hold symbolic link pathname
  226. * within structure.
  227. */
  228. typedef struct {
  229. struct stat sb_stat;
  230. char sb_link[PATH_MAX + 1];
  231. } Stat;
  232. #define STAT(name, asb) stat(name, &(asb)->sb_stat)
  233. #define FSTAT(fd, asb) fstat(fd, &(asb)->sb_stat)
  234. #define sb_dev sb_stat.st_dev
  235. #define sb_ino sb_stat.st_ino
  236. #define sb_mode sb_stat.st_mode
  237. #define sb_nlink sb_stat.st_nlink
  238. #define sb_uid sb_stat.st_uid
  239. #define sb_gid sb_stat.st_gid
  240. #define sb_rdev sb_stat.st_rdev
  241. #define sb_size sb_stat.st_size
  242. #define sb_atime sb_stat.st_atime
  243. #define sb_mtime sb_stat.st_mtime
  244. #define sb_ctime sb_stat.st_ctime
  245. #ifdef S_IFLNK
  246. # define LSTAT(name, asb) lstat(name, &(asb)->sb_stat)
  247. # define sb_blksize sb_stat.st_blksize
  248. # define sb_blocks sb_stat.st_blocks
  249. #else /* S_IFLNK */
  250. /*
  251. * File status without symbolic links.
  252. */
  253. # define LSTAT(name, asb) stat(name, &(asb)->sb_stat)
  254. #endif /* S_IFLNK */
  255. /*
  256. * Hard link sources. One or more are chained from each link structure.
  257. */
  258. typedef struct name {
  259. struct name *p_forw; /* Forward chain (terminated) */
  260. struct name *p_back; /* Backward chain (circular) */
  261. char *p_name; /* Pathname to link from */
  262. } Path;
  263. /*
  264. * File linking information. One entry exists for each unique file with with
  265. * outstanding hard links.
  266. */
  267. typedef struct link {
  268. struct link *l_forw; /* Forward chain (terminated) */
  269. struct link *l_back; /* Backward chain (terminated) */
  270. dev_t l_dev; /* Device */
  271. ino_t l_ino; /* Inode */
  272. ushort l_nlink; /* Unresolved link count */
  273. OFFSET l_size; /* Length */
  274. char *l_name; /* pathname to link from */
  275. Path *l_path; /* Pathname which link to l_name */
  276. } Link;
  277. /*
  278. * Structure for ed-style replacement strings (-s option).
  279. */
  280. typedef struct replstr {
  281. regexp *comp; /* compiled regular expression */
  282. char *replace; /* replacement string */
  283. char print; /* >0 if we are to print replacement */
  284. char global; /* >0 if we are to replace globally */
  285. struct replstr *next; /* pointer to next record */
  286. } Replstr;
  287. /*
  288. * This has to be included here to insure that all of the type
  289. * delcarations are declared for the prototypes.
  290. */
  291. #ifndef STRERROR
  292. /* boofheads have a different interface than standard, so rename */
  293. #define strerror xstrerror
  294. #endif
  295. #include "func.h"
  296. #ifndef NO_EXTERN
  297. /* Globally Available Identifiers */
  298. extern char *ar_file;
  299. extern char *bufend;
  300. extern char *bufstart;
  301. extern char *bufidx;
  302. extern char *myname;
  303. extern int archivefd;
  304. extern int blocking;
  305. extern uint blocksize;
  306. extern int gid;
  307. extern int head_standard;
  308. extern int ar_interface;
  309. extern int ar_format;
  310. extern int mask;
  311. extern int ttyf;
  312. extern int uid;
  313. extern OFFSET total;
  314. extern short areof;
  315. extern short f_append;
  316. extern short f_create;
  317. extern short f_extract;
  318. extern short f_follow_links;
  319. extern short f_interactive;
  320. extern short f_linksleft;
  321. extern short f_list;
  322. extern short f_modified;
  323. extern short f_verbose;
  324. extern short f_link;
  325. extern short f_owner;
  326. extern short f_access_time;
  327. extern short f_pass;
  328. extern short f_pass;
  329. extern short f_disposition;
  330. extern short f_reverse_match;
  331. extern short f_mtime;
  332. extern short f_dir_create;
  333. extern short f_unconditional;
  334. extern short f_newer;
  335. extern time_t now;
  336. extern uint arvolume;
  337. extern int names_from_stdin;
  338. extern Replstr *rplhead;
  339. extern Replstr *rpltail;
  340. extern char **n_argv;
  341. extern int n_argc;
  342. extern FILE *msgfile;
  343. #endif /* NO_EXTERN */
  344. extern char *optarg;
  345. extern int optind;
  346. #ifndef _POSIX_SOURCE
  347. extern int sys_nerr;
  348. extern char *sys_errlist[];
  349. #endif
  350. extern int errno;
  351. #endif /* _PAX_H */