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