xref: /openbsd/bin/pax/pax.h (revision fd899314)
1*fd899314Smichaels /*	$OpenBSD: pax.h,v 1.7 1997/02/27 23:32:59 michaels Exp $	*/
2df930be7Sderaadt /*	$NetBSD: pax.h,v 1.3 1995/03/21 09:07:41 cgd Exp $	*/
3df930be7Sderaadt 
4df930be7Sderaadt /*-
5df930be7Sderaadt  * Copyright (c) 1992 Keith Muller.
6df930be7Sderaadt  * Copyright (c) 1992, 1993
7df930be7Sderaadt  *	The Regents of the University of California.  All rights reserved.
8df930be7Sderaadt  *
9df930be7Sderaadt  * This code is derived from software contributed to Berkeley by
10df930be7Sderaadt  * Keith Muller of the University of California, San Diego.
11df930be7Sderaadt  *
12df930be7Sderaadt  * Redistribution and use in source and binary forms, with or without
13df930be7Sderaadt  * modification, are permitted provided that the following conditions
14df930be7Sderaadt  * are met:
15df930be7Sderaadt  * 1. Redistributions of source code must retain the above copyright
16df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer.
17df930be7Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
18df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer in the
19df930be7Sderaadt  *    documentation and/or other materials provided with the distribution.
20df930be7Sderaadt  * 3. All advertising materials mentioning features or use of this software
21df930be7Sderaadt  *    must display the following acknowledgement:
22df930be7Sderaadt  *	This product includes software developed by the University of
23df930be7Sderaadt  *	California, Berkeley and its contributors.
24df930be7Sderaadt  * 4. Neither the name of the University nor the names of its contributors
25df930be7Sderaadt  *    may be used to endorse or promote products derived from this software
26df930be7Sderaadt  *    without specific prior written permission.
27df930be7Sderaadt  *
28df930be7Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29df930be7Sderaadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30df930be7Sderaadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31df930be7Sderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32df930be7Sderaadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33df930be7Sderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34df930be7Sderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35df930be7Sderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36df930be7Sderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37df930be7Sderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38df930be7Sderaadt  * SUCH DAMAGE.
39df930be7Sderaadt  *
40df930be7Sderaadt  *	@(#)pax.h	8.2 (Berkeley) 4/18/94
41df930be7Sderaadt  */
42df930be7Sderaadt 
43df930be7Sderaadt /*
44df930be7Sderaadt  * BSD PAX global data structures and constants.
45df930be7Sderaadt  */
46df930be7Sderaadt 
47df930be7Sderaadt #define	MAXBLK		32256	/* MAX blocksize supported (posix SPEC) */
48df930be7Sderaadt 				/* WARNING: increasing MAXBLK past 32256 */
49df930be7Sderaadt 				/* will violate posix spec. */
50df930be7Sderaadt #define BLKMULT		512	/* blocksize must be even mult of 512 bytes */
51df930be7Sderaadt 				/* Don't even think of changing this */
52df930be7Sderaadt #define DEVBLK		8192	/* default read blksize for devices */
53df930be7Sderaadt #define FILEBLK		10240	/* default read blksize for files */
54df930be7Sderaadt #define PAXPATHLEN	3072	/* maximium path length for pax. MUST be */
55df930be7Sderaadt 				/* longer than the system MAXPATHLEN */
56df930be7Sderaadt 
57df930be7Sderaadt /*
58df930be7Sderaadt  * Pax modes of operation
59df930be7Sderaadt  */
60df930be7Sderaadt #define	LIST		0	/* List the file in an archive */
61df930be7Sderaadt #define	EXTRACT		1	/* extract the files in an archive */
62df930be7Sderaadt #define ARCHIVE		2	/* write a new archive */
63df930be7Sderaadt #define APPND		3	/* append to the end of an archive */
64df930be7Sderaadt #define	COPY		4	/* copy files to destination dir */
65df930be7Sderaadt #define DEFOP		LIST	/* if no flags default is to LIST */
66df930be7Sderaadt 
67df930be7Sderaadt /*
68df930be7Sderaadt  * Device type of the current archive volume
69df930be7Sderaadt  */
70df930be7Sderaadt #define ISREG		0	/* regular file */
71df930be7Sderaadt #define ISCHR		1	/* character device */
72df930be7Sderaadt #define ISBLK		2	/* block device */
73df930be7Sderaadt #define ISTAPE		3	/* tape drive */
74df930be7Sderaadt #define ISPIPE		4	/* pipe/socket */
75df930be7Sderaadt 
76df930be7Sderaadt /*
77df930be7Sderaadt  * Format Specific Routine Table
78df930be7Sderaadt  *
79df930be7Sderaadt  * The format specific routine table allows new archive formats to be quickly
80df930be7Sderaadt  * added. Overall pax operation is independent of the actual format used to
81df930be7Sderaadt  * form the archive. Only those routines which deal directly with the archive
82df930be7Sderaadt  * are tailored to the oddities of the specifc format. All other routines are
83df930be7Sderaadt  * independent of the archive format. Data flow in and out of the format
84df930be7Sderaadt  * dependent routines pass pointers to ARCHD structure (described below).
85df930be7Sderaadt  */
86df930be7Sderaadt typedef struct {
87df930be7Sderaadt 	char *name;		/* name of format, this is the name the user */
88df930be7Sderaadt 				/* gives to -x option to select it. */
89df930be7Sderaadt 	int bsz;		/* default block size. used when the user */
90df930be7Sderaadt 				/* does not specify a blocksize for writing */
91df930be7Sderaadt 				/* Appends continue to with the blocksize */
92df930be7Sderaadt 				/* the archive is currently using.*/
93df930be7Sderaadt 	int hsz;		/* Header size in bytes. this is the size of */
94df930be7Sderaadt 				/* the smallest header this format supports. */
95df930be7Sderaadt 				/* Headers are assumed to fit in a BLKMULT. */
96df930be7Sderaadt 				/* If they are bigger, get_head() and */
97df930be7Sderaadt 				/* get_arc() must be adjusted */
98df930be7Sderaadt 	int udev;		/* does append require unique dev/ino? some */
99df930be7Sderaadt 				/* formats use the device and inode fields */
100df930be7Sderaadt 				/* to specify hard links. when members in */
101df930be7Sderaadt 				/* the archive have the same inode/dev they */
102df930be7Sderaadt 				/* are assumed to be hard links. During */
103df930be7Sderaadt 				/* append we may have to generate unique ids */
104df930be7Sderaadt 				/* to avoid creating incorrect hard links */
105df930be7Sderaadt 	int hlk;		/* does archive store hard links info? if */
106df930be7Sderaadt 				/* not, we do not bother to look for them */
107df930be7Sderaadt 				/* during archive write operations */
108df930be7Sderaadt 	int blkalgn;		/* writes must be aligned to blkalgn boundry */
109df930be7Sderaadt 	int inhead;		/* is the trailer encoded in a valid header? */
110df930be7Sderaadt 				/* if not, trailers are assumed to be found */
111df930be7Sderaadt 				/* in invalid headers (i.e like tar) */
112df930be7Sderaadt 	int (*id)();		/* checks if a buffer is a valid header */
113df930be7Sderaadt 				/* returns 1 if it is, o.w. returns a 0 */
114df930be7Sderaadt 	int (*st_rd)();		/* initialize routine for read. so format */
115df930be7Sderaadt 				/* can set up tables etc before it starts */
116df930be7Sderaadt 				/* reading an archive */
117df930be7Sderaadt 	int (*rd)();		/* read header routine. passed a pointer to */
118df930be7Sderaadt 				/* ARCHD. It must extract the info from the */
119df930be7Sderaadt 				/* format and store it in the ARCHD struct. */
120df930be7Sderaadt 				/* This routine is expected to fill all the */
121df930be7Sderaadt 				/* fields in the ARCHD (including stat buf) */
122df930be7Sderaadt 				/* 0 is returned when a valid header is */
123df930be7Sderaadt 				/* found. -1 when not valid. This routine */
124df930be7Sderaadt 				/* set the skip and pad fields so the format */
125df930be7Sderaadt 				/* independent routines know the amount of */
126df930be7Sderaadt 				/* padding and the number of bytes of data */
127df930be7Sderaadt 				/* which follow the header. This info is */
128df930be7Sderaadt 				/* used skip to the next file header */
129df930be7Sderaadt 	off_t (*end_rd)();	/* read cleanup. Allows format to clean up */
130df930be7Sderaadt 				/* and MUST RETURN THE LENGTH OF THE TRAILER */
131df930be7Sderaadt 				/* RECORD (so append knows how many bytes */
132df930be7Sderaadt 				/* to move back to rewrite the trailer) */
133df930be7Sderaadt 	int (*st_wr)();		/* initialize routine for write operations */
134df930be7Sderaadt 	int (*wr)();		/* write archive header. Passed an ARCHD */
135df930be7Sderaadt 				/* filled with the specs on the next file to */
136df930be7Sderaadt 				/* archived. Returns a 1 if no file data is */
137df930be7Sderaadt 				/* is to be stored; 0 if file data is to be */
138df930be7Sderaadt 				/* added. A -1 is returned if a write */
139df930be7Sderaadt 				/* operation to the archive failed. this */
140df930be7Sderaadt 				/* function sets the skip and pad fields so */
141df930be7Sderaadt 				/* the proper padding can be added after */
142df930be7Sderaadt 				/* file data. This routine must NEVER write */
143df930be7Sderaadt 				/* a flawed archive header. */
144df930be7Sderaadt 	int (*end_wr)();	/* end write. write the trailer and do any */
145df930be7Sderaadt 				/* other format specific functions needed */
146df930be7Sderaadt 				/* at the ecnd of a archive write */
147df930be7Sderaadt 	int (*trail)();		/* returns 0 if a valid trailer, -1 if not */
148df930be7Sderaadt 				/* For formats which encode the trailer */
149df930be7Sderaadt 				/* outside of a valid header, a return value */
150df930be7Sderaadt 				/* of 1 indicates that the block passed to */
151df930be7Sderaadt 				/* it can never contain a valid header (skip */
152df930be7Sderaadt 				/* this block, no point in looking at it)  */
153df930be7Sderaadt 				/* CAUTION: parameters to this function are */
154df930be7Sderaadt 				/* different for trailers inside or outside */
155df930be7Sderaadt 				/* of headers. See get_head() for details */
156df930be7Sderaadt 	int (*rd_data)();	/* read/process file data from the archive */
157df930be7Sderaadt 	int (*wr_data)();	/* write/process file data to the archive */
158df930be7Sderaadt 	int (*options)();	/* process format specific options (-o) */
159df930be7Sderaadt } FSUB;
160df930be7Sderaadt 
161df930be7Sderaadt /*
162df930be7Sderaadt  * Pattern matching structure
163df930be7Sderaadt  *
164df930be7Sderaadt  * Used to store command line patterns
165df930be7Sderaadt  */
166df930be7Sderaadt typedef struct pattern {
167df930be7Sderaadt 	char		*pstr;		/* pattern to match, user supplied */
168df930be7Sderaadt 	char		*pend;		/* end of a prefix match */
169*fd899314Smichaels 	char		*chdname;	/* the dir to change to if not NULL.  */
170df930be7Sderaadt 	int		plen;		/* length of pstr */
171df930be7Sderaadt 	int		flgs;		/* processing/state flags */
172df930be7Sderaadt #define MTCH		0x1		/* pattern has been matched */
173df930be7Sderaadt #define DIR_MTCH	0x2		/* pattern matched a directory */
174df930be7Sderaadt 	struct pattern	*fow;		/* next pattern */
175df930be7Sderaadt } PATTERN;
176df930be7Sderaadt 
177df930be7Sderaadt /*
178df930be7Sderaadt  * General Archive Structure (used internal to pax)
179df930be7Sderaadt  *
180df930be7Sderaadt  * This structure is used to pass information about archive members between
181df930be7Sderaadt  * the format independent routines and the format specific routines. When
182df930be7Sderaadt  * new archive formats are added, they must accept requests and supply info
183df930be7Sderaadt  * encoded in a structure of this type. The name fields are declared statically
184df930be7Sderaadt  * here, as there is only ONE of these floating around, size is not a major
185df930be7Sderaadt  * consideration. Eventually converting the name fields to a dynamic length
186df930be7Sderaadt  * may be required if and when the supporting operating system removes all
187df930be7Sderaadt  * restrictions on the length of pathnames it will resolve.
188df930be7Sderaadt  */
189df930be7Sderaadt typedef struct {
190df930be7Sderaadt 	int nlen;			/* file name length */
191df930be7Sderaadt 	char name[PAXPATHLEN+1];	/* file name */
192df930be7Sderaadt 	int ln_nlen;			/* link name length */
193df930be7Sderaadt 	char ln_name[PAXPATHLEN+1];	/* name to link to (if any) */
194df930be7Sderaadt 	char *org_name;			/* orig name in file system */
195df930be7Sderaadt 	PATTERN *pat;			/* ptr to pattern match (if any) */
196df930be7Sderaadt 	struct stat sb;			/* stat buffer see stat(2) */
197df930be7Sderaadt 	off_t pad;			/* bytes of padding after file xfer */
198df930be7Sderaadt 	off_t skip;			/* bytes of real data after header */
199df930be7Sderaadt 					/* IMPORTANT. The st_size field does */
200df930be7Sderaadt 					/* not always indicate the amount of */
201df930be7Sderaadt 					/* data following the header. */
202df930be7Sderaadt 	u_long crc;			/* file crc */
203df930be7Sderaadt 	int type;			/* type of file node */
204df930be7Sderaadt #define PAX_DIR		1		/* directory */
205df930be7Sderaadt #define PAX_CHR		2		/* character device */
206df930be7Sderaadt #define PAX_BLK		3		/* block device */
207df930be7Sderaadt #define PAX_REG		4		/* regular file */
208df930be7Sderaadt #define PAX_SLK		5		/* symbolic link */
209df930be7Sderaadt #define PAX_SCK		6		/* socket */
210df930be7Sderaadt #define PAX_FIF		7		/* fifo */
211df930be7Sderaadt #define PAX_HLK		8		/* hard link */
212df930be7Sderaadt #define PAX_HRG		9		/* hard link to a regular file */
213df930be7Sderaadt #define PAX_CTG		10		/* high performance file */
214df930be7Sderaadt } ARCHD;
215df930be7Sderaadt 
216df930be7Sderaadt /*
217df930be7Sderaadt  * Format Specific Options List
218df930be7Sderaadt  *
219df930be7Sderaadt  * Used to pass format options to the format options handler
220df930be7Sderaadt  */
221df930be7Sderaadt typedef struct oplist {
222df930be7Sderaadt 	char		*name;		/* option variable name e.g. name= */
223df930be7Sderaadt 	char		*value;		/* value for option variable */
224df930be7Sderaadt 	struct oplist	*fow;		/* next option */
225df930be7Sderaadt } OPLIST;
226df930be7Sderaadt 
227df930be7Sderaadt /*
228df930be7Sderaadt  * General Macros
229df930be7Sderaadt  */
230df930be7Sderaadt #ifndef MIN
231df930be7Sderaadt #define        MIN(a,b) (((a)<(b))?(a):(b))
232df930be7Sderaadt #endif
23309c973a4Stholo #define MAJOR(x)        major(x)
23409c973a4Stholo #define MINOR(x)        minor(x)
23509c973a4Stholo #define TODEV(x, y)	makedev((x), (y))
236df930be7Sderaadt 
237df930be7Sderaadt /*
238df930be7Sderaadt  * General Defines
239df930be7Sderaadt  */
240df930be7Sderaadt #define HEX	16
241df930be7Sderaadt #define OCT	8
242df930be7Sderaadt #define _PAX_	1
243