Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

408 lines
11 KiB

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