xref: /original-bsd/bin/pax/pax.h (revision e58c8952)
1 /*-
2  * Copyright (c) 1992 Keith Muller.
3  * Copyright (c) 1992, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * Keith Muller of the University of California, San Diego.
8  *
9  * %sccs.include.redist.c%
10  *
11  *	@(#)pax.h	8.2 (Berkeley) 04/18/94
12  */
13 
14 /*
15  * BSD PAX global data structures and constants.
16  */
17 
18 #define	MAXBLK		32256	/* MAX blocksize supported (posix SPEC) */
19 				/* WARNING: increasing MAXBLK past 32256 */
20 				/* will violate posix spec. */
21 #define BLKMULT		512	/* blocksize must be even mult of 512 bytes */
22 				/* Don't even think of changing this */
23 #define DEVBLK		8192	/* default read blksize for devices */
24 #define FILEBLK		10240	/* default read blksize for files */
25 #define PAXPATHLEN	3072	/* maximium path length for pax. MUST be */
26 				/* longer than the system MAXPATHLEN */
27 
28 /*
29  * Pax modes of operation
30  */
31 #define	LIST		0	/* List the file in an archive */
32 #define	EXTRACT		1	/* extract the files in an archive */
33 #define ARCHIVE		2	/* write a new archive */
34 #define APPND		3	/* append to the end of an archive */
35 #define	COPY		4	/* copy files to destination dir */
36 #define DEFOP		LIST	/* if no flags default is to LIST */
37 
38 /*
39  * Device type of the current archive volume
40  */
41 #define ISREG		0	/* regular file */
42 #define ISCHR		1	/* character device */
43 #define ISBLK		2	/* block device */
44 #define ISTAPE		3	/* tape drive */
45 #define ISPIPE		4	/* pipe/socket */
46 
47 /*
48  * Format Specific Routine Table
49  *
50  * The format specific routine table allows new archive formats to be quickly
51  * added. Overall pax operation is independent of the actual format used to
52  * form the archive. Only those routines which deal directly with the archive
53  * are tailored to the oddities of the specifc format. All other routines are
54  * independent of the archive format. Data flow in and out of the format
55  * dependent routines pass pointers to ARCHD structure (described below).
56  */
57 typedef struct {
58 	char *name;		/* name of format, this is the name the user */
59 				/* gives to -x option to select it. */
60 	int bsz;		/* default block size. used when the user */
61 				/* does not specify a blocksize for writing */
62 				/* Appends continue to with the blocksize */
63 				/* the archive is currently using.*/
64 	int hsz;		/* Header size in bytes. this is the size of */
65 				/* the smallest header this format supports. */
66 				/* Headers are assumed to fit in a BLKMULT. */
67 				/* If they are bigger, get_head() and */
68 				/* get_arc() must be adjusted */
69 	int udev;		/* does append require unique dev/ino? some */
70 				/* formats use the device and inode fields */
71 				/* to specify hard links. when members in */
72 				/* the archive have the same inode/dev they */
73 				/* are assumed to be hard links. During */
74 				/* append we may have to generate unique ids */
75 				/* to avoid creating incorrect hard links */
76 	int hlk;		/* does archive store hard links info? if */
77 				/* not, we do not bother to look for them */
78 				/* during archive write operations */
79 	int blkalgn;		/* writes must be aligned to blkalgn boundry */
80 	int inhead;		/* is the trailer encoded in a valid header? */
81 				/* if not, trailers are assumed to be found */
82 				/* in invalid headers (i.e like tar) */
83 	int (*id)();		/* checks if a buffer is a valid header */
84 				/* returns 1 if it is, o.w. returns a 0 */
85 	int (*st_rd)();		/* initialize routine for read. so format */
86 				/* can set up tables etc before it starts */
87 				/* reading an archive */
88 	int (*rd)();		/* read header routine. passed a pointer to */
89 				/* ARCHD. It must extract the info from the */
90 				/* format and store it in the ARCHD struct. */
91 				/* This routine is expected to fill all the */
92 				/* fields in the ARCHD (including stat buf) */
93 				/* 0 is returned when a valid header is */
94 				/* found. -1 when not valid. This routine */
95 				/* set the skip and pad fields so the format */
96 				/* independent routines know the amount of */
97 				/* padding and the number of bytes of data */
98 				/* which follow the header. This info is */
99 				/* used skip to the next file header */
100 	off_t (*end_rd)();	/* read cleanup. Allows format to clean up */
101 				/* and MUST RETURN THE LENGTH OF THE TRAILER */
102 				/* RECORD (so append knows how many bytes */
103 				/* to move back to rewrite the trailer) */
104 	int (*st_wr)();		/* initialize routine for write operations */
105 	int (*wr)();		/* write archive header. Passed an ARCHD */
106 				/* filled with the specs on the next file to */
107 				/* archived. Returns a 1 if no file data is */
108 				/* is to be stored; 0 if file data is to be */
109 				/* added. A -1 is returned if a write */
110 				/* operation to the archive failed. this */
111 				/* function sets the skip and pad fields so */
112 				/* the proper padding can be added after */
113 				/* file data. This routine must NEVER write */
114 				/* a flawed archive header. */
115 	int (*end_wr)();	/* end write. write the trailer and do any */
116 				/* other format specific functions needed */
117 				/* at the ecnd of a archive write */
118 	int (*trail)();		/* returns 0 if a valid trailer, -1 if not */
119 				/* For formats which encode the trailer */
120 				/* outside of a valid header, a return value */
121 				/* of 1 indicates that the block passed to */
122 				/* it can never contain a valid header (skip */
123 				/* this block, no point in looking at it)  */
124 				/* CAUTION: parameters to this function are */
125 				/* different for trailers inside or outside */
126 				/* of headers. See get_head() for details */
127 	int (*rd_data)();	/* read/process file data from the archive */
128 	int (*wr_data)();	/* write/process file data to the archive */
129 	int (*options)();	/* process format specific options (-o) */
130 } FSUB;
131 
132 /*
133  * Pattern matching structure
134  *
135  * Used to store command line patterns
136  */
137 typedef struct pattern {
138 	char		*pstr;		/* pattern to match, user supplied */
139 	char		*pend;		/* end of a prefix match */
140 	int		plen;		/* length of pstr */
141 	int		flgs;		/* processing/state flags */
142 #define MTCH		0x1		/* pattern has been matched */
143 #define DIR_MTCH	0x2		/* pattern matched a directory */
144 	struct pattern	*fow;		/* next pattern */
145 } PATTERN;
146 
147 /*
148  * General Archive Structure (used internal to pax)
149  *
150  * This structure is used to pass information about archive members between
151  * the format independent routines and the format specific routines. When
152  * new archive formats are added, they must accept requests and supply info
153  * encoded in a structure of this type. The name fields are declared statically
154  * here, as there is only ONE of these floating around, size is not a major
155  * consideration. Eventually converting the name fields to a dynamic length
156  * may be required if and when the supporting operating system removes all
157  * restrictions on the length of pathnames it will resolve.
158  */
159 typedef struct {
160 	int nlen;			/* file name length */
161 	char name[PAXPATHLEN+1];	/* file name */
162 	int ln_nlen;			/* link name length */
163 	char ln_name[PAXPATHLEN+1];	/* name to link to (if any) */
164 	char *org_name;			/* orig name in file system */
165 	PATTERN *pat;			/* ptr to pattern match (if any) */
166 	struct stat sb;			/* stat buffer see stat(2) */
167 	off_t pad;			/* bytes of padding after file xfer */
168 	off_t skip;			/* bytes of real data after header */
169 					/* IMPORTANT. The st_size field does */
170 					/* not always indicate the amount of */
171 					/* data following the header. */
172 	u_long crc;			/* file crc */
173 	int type;			/* type of file node */
174 #define PAX_DIR		1		/* directory */
175 #define PAX_CHR		2		/* character device */
176 #define PAX_BLK		3		/* block device */
177 #define PAX_REG		4		/* regular file */
178 #define PAX_SLK		5		/* symbolic link */
179 #define PAX_SCK		6		/* socket */
180 #define PAX_FIF		7		/* fifo */
181 #define PAX_HLK		8		/* hard link */
182 #define PAX_HRG		9		/* hard link to a regular file */
183 #define PAX_CTG		10		/* high performance file */
184 } ARCHD;
185 
186 /*
187  * Format Specific Options List
188  *
189  * Used to pass format options to the format options handler
190  */
191 typedef struct oplist {
192 	char		*name;		/* option variable name e.g. name= */
193 	char		*value;		/* value for option variable */
194 	struct oplist	*fow;		/* next option */
195 } OPLIST;
196 
197 /*
198  * General Macros
199  */
200 #ifndef MIN
201 #define        MIN(a,b) (((a)<(b))?(a):(b))
202 #endif
203 #define MAJOR(x)        (((unsigned)(x) >> 8) & 0xff)
204 #define MINOR(x)        ((x) & 0xff)
205 #define TODEV(x, y)	(((unsigned)(x) << 8) | ((unsigned)(y)))
206 
207 /*
208  * General Defines
209  */
210 #define HEX	16
211 #define OCT	8
212 #define _PAX_	1
213