xref: /openbsd/bin/pax/pax.h (revision b9fc9a72)
1*b9fc9a72Sderaadt /*	$OpenBSD: pax.h,v 1.20 2015/01/16 06:39:32 deraadt 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.
2029295d1cSmillert  * 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 */
5108cab283Sjmc #define PAXPATHLEN	3072	/* maximum path length for pax. MUST be */
5208961bb1Sguenther 				/* longer than the system PATH_MAX */
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  * Pattern matching structure
75df930be7Sderaadt  *
76df930be7Sderaadt  * Used to store command line patterns
77df930be7Sderaadt  */
78df930be7Sderaadt typedef struct pattern {
79df930be7Sderaadt 	char		*pstr;		/* pattern to match, user supplied */
80df930be7Sderaadt 	char		*pend;		/* end of a prefix match */
81fd899314Smichaels 	char		*chdname;	/* the dir to change to if not NULL.  */
82df930be7Sderaadt 	int		plen;		/* length of pstr */
83df930be7Sderaadt 	int		flgs;		/* processing/state flags */
84df930be7Sderaadt #define MTCH		0x1		/* pattern has been matched */
85df930be7Sderaadt #define DIR_MTCH	0x2		/* pattern matched a directory */
86df930be7Sderaadt 	struct pattern	*fow;		/* next pattern */
87df930be7Sderaadt } PATTERN;
88df930be7Sderaadt 
89df930be7Sderaadt /*
90df930be7Sderaadt  * General Archive Structure (used internal to pax)
91df930be7Sderaadt  *
92df930be7Sderaadt  * This structure is used to pass information about archive members between
93df930be7Sderaadt  * the format independent routines and the format specific routines. When
94df930be7Sderaadt  * new archive formats are added, they must accept requests and supply info
95df930be7Sderaadt  * encoded in a structure of this type. The name fields are declared statically
96df930be7Sderaadt  * here, as there is only ONE of these floating around, size is not a major
97df930be7Sderaadt  * consideration. Eventually converting the name fields to a dynamic length
98df930be7Sderaadt  * may be required if and when the supporting operating system removes all
99df930be7Sderaadt  * restrictions on the length of pathnames it will resolve.
100df930be7Sderaadt  */
101df930be7Sderaadt typedef struct {
102df930be7Sderaadt 	int nlen;			/* file name length */
103df930be7Sderaadt 	char name[PAXPATHLEN+1];	/* file name */
104df930be7Sderaadt 	int ln_nlen;			/* link name length */
105df930be7Sderaadt 	char ln_name[PAXPATHLEN+1];	/* name to link to (if any) */
106df930be7Sderaadt 	char *org_name;			/* orig name in file system */
107df930be7Sderaadt 	PATTERN *pat;			/* ptr to pattern match (if any) */
108df930be7Sderaadt 	struct stat sb;			/* stat buffer see stat(2) */
109df930be7Sderaadt 	off_t pad;			/* bytes of padding after file xfer */
110df930be7Sderaadt 	off_t skip;			/* bytes of real data after header */
111df930be7Sderaadt 					/* IMPORTANT. The st_size field does */
112df930be7Sderaadt 					/* not always indicate the amount of */
113df930be7Sderaadt 					/* data following the header. */
1144a51f016Sotto 	u_int32_t crc;			/* file crc */
115df930be7Sderaadt 	int type;			/* type of file node */
116df930be7Sderaadt #define PAX_DIR		1		/* directory */
117df930be7Sderaadt #define PAX_CHR		2		/* character device */
118df930be7Sderaadt #define PAX_BLK		3		/* block device */
119df930be7Sderaadt #define PAX_REG		4		/* regular file */
120df930be7Sderaadt #define PAX_SLK		5		/* symbolic link */
121df930be7Sderaadt #define PAX_SCK		6		/* socket */
122df930be7Sderaadt #define PAX_FIF		7		/* fifo */
123df930be7Sderaadt #define PAX_HLK		8		/* hard link */
124df930be7Sderaadt #define PAX_HRG		9		/* hard link to a regular file */
125df930be7Sderaadt #define PAX_CTG		10		/* high performance file */
126da60b202Smillert #define PAX_GLL		11		/* GNU long symlink */
127da60b202Smillert #define PAX_GLF		12		/* GNU long file */
128df930be7Sderaadt } ARCHD;
129df930be7Sderaadt 
130df930be7Sderaadt /*
131cd90c754Sderaadt  * Format Specific Routine Table
132cd90c754Sderaadt  *
133cd90c754Sderaadt  * The format specific routine table allows new archive formats to be quickly
134cd90c754Sderaadt  * added. Overall pax operation is independent of the actual format used to
135cd90c754Sderaadt  * form the archive. Only those routines which deal directly with the archive
13608cab283Sjmc  * are tailored to the oddities of the specific format. All other routines are
137cd90c754Sderaadt  * independent of the archive format. Data flow in and out of the format
138cd90c754Sderaadt  * dependent routines pass pointers to ARCHD structure (described below).
139cd90c754Sderaadt  */
140cd90c754Sderaadt typedef struct {
141cd90c754Sderaadt 	char *name;		/* name of format, this is the name the user */
142cd90c754Sderaadt 				/* gives to -x option to select it. */
143cd90c754Sderaadt 	int bsz;		/* default block size. used when the user */
144cd90c754Sderaadt 				/* does not specify a blocksize for writing */
145cd90c754Sderaadt 				/* Appends continue to with the blocksize */
146cd90c754Sderaadt 				/* the archive is currently using. */
147cd90c754Sderaadt 	int hsz;		/* Header size in bytes. this is the size of */
148cd90c754Sderaadt 				/* the smallest header this format supports. */
149cd90c754Sderaadt 				/* Headers are assumed to fit in a BLKMULT. */
150cd90c754Sderaadt 				/* If they are bigger, get_head() and */
151cd90c754Sderaadt 				/* get_arc() must be adjusted */
152cd90c754Sderaadt 	int udev;		/* does append require unique dev/ino? some */
153cd90c754Sderaadt 				/* formats use the device and inode fields */
154cd90c754Sderaadt 				/* to specify hard links. when members in */
155cd90c754Sderaadt 				/* the archive have the same inode/dev they */
156cd90c754Sderaadt 				/* are assumed to be hard links. During */
157cd90c754Sderaadt 				/* append we may have to generate unique ids */
158cd90c754Sderaadt 				/* to avoid creating incorrect hard links */
159cd90c754Sderaadt 	int hlk;		/* does archive store hard links info? if */
160cd90c754Sderaadt 				/* not, we do not bother to look for them */
161cd90c754Sderaadt 				/* during archive write operations */
162cd90c754Sderaadt 	int blkalgn;		/* writes must be aligned to blkalgn boundary */
163cd90c754Sderaadt 	int inhead;		/* is the trailer encoded in a valid header? */
164cd90c754Sderaadt 				/* if not, trailers are assumed to be found */
165cd90c754Sderaadt 				/* in invalid headers (i.e like tar) */
166cd90c754Sderaadt 	int (*id)(char *,	/* checks if a buffer is a valid header */
167cd90c754Sderaadt 	    int);		/* returns 1 if it is, o.w. returns a 0 */
168cd90c754Sderaadt 	int (*st_rd)(void);	/* initialize routine for read. so format */
169cd90c754Sderaadt 				/* can set up tables etc before it starts */
170cd90c754Sderaadt 				/* reading an archive */
171cd90c754Sderaadt 	int (*rd)(ARCHD *,	/* read header routine. passed a pointer to */
172cd90c754Sderaadt 	    char *);		/* ARCHD. It must extract the info from the */
173cd90c754Sderaadt 				/* format and store it in the ARCHD struct. */
174cd90c754Sderaadt 				/* This routine is expected to fill all the */
175cd90c754Sderaadt 				/* fields in the ARCHD (including stat buf) */
176cd90c754Sderaadt 				/* 0 is returned when a valid header is */
177cd90c754Sderaadt 				/* found. -1 when not valid. This routine */
178cd90c754Sderaadt 				/* set the skip and pad fields so the format */
179cd90c754Sderaadt 				/* independent routines know the amount of */
180cd90c754Sderaadt 				/* padding and the number of bytes of data */
181cd90c754Sderaadt 				/* which follow the header. This info is */
182cd90c754Sderaadt 				/* used skip to the next file header */
183cd90c754Sderaadt 	off_t (*end_rd)(void);	/* read cleanup. Allows format to clean up */
184cd90c754Sderaadt 				/* and MUST RETURN THE LENGTH OF THE TRAILER */
185cd90c754Sderaadt 				/* RECORD (so append knows how many bytes */
186cd90c754Sderaadt 				/* to move back to rewrite the trailer) */
187cd90c754Sderaadt 	int (*st_wr)(void);	/* initialize routine for write operations */
188cd90c754Sderaadt 	int (*wr)(ARCHD *);	/* write archive header. Passed an ARCHD */
189cd90c754Sderaadt 				/* filled with the specs on the next file to */
190cd90c754Sderaadt 				/* archived. Returns a 1 if no file data is */
191cd90c754Sderaadt 				/* is to be stored; 0 if file data is to be */
192cd90c754Sderaadt 				/* added. A -1 is returned if a write */
193cd90c754Sderaadt 				/* operation to the archive failed. this */
194cd90c754Sderaadt 				/* function sets the skip and pad fields so */
195cd90c754Sderaadt 				/* the proper padding can be added after */
196cd90c754Sderaadt 				/* file data. This routine must NEVER write */
197cd90c754Sderaadt 				/* a flawed archive header. */
198cd90c754Sderaadt 	int (*end_wr)(void);	/* end write. write the trailer and do any */
199cd90c754Sderaadt 				/* other format specific functions needed */
20008cab283Sjmc 				/* at the end of an archive write */
201cd90c754Sderaadt 	int (*trail)(ARCHD *,	/* returns 0 if a valid trailer, -1 if not */
202cd90c754Sderaadt 	    char *, int,	/* For formats which encode the trailer */
203cd90c754Sderaadt 	    int *);		/* outside of a valid header, a return value */
204cd90c754Sderaadt 				/* of 1 indicates that the block passed to */
205cd90c754Sderaadt 				/* it can never contain a valid header (skip */
206cd90c754Sderaadt 				/* this block, no point in looking at it)  */
207cd90c754Sderaadt 				/* CAUTION: parameters to this function are */
208cd90c754Sderaadt 				/* different for trailers inside or outside */
209cd90c754Sderaadt 				/* of headers. See get_head() for details */
210cd90c754Sderaadt 	int (*options)(void);	/* process format specific options (-o) */
211cd90c754Sderaadt } FSUB;
212cd90c754Sderaadt 
213cd90c754Sderaadt /*
214df930be7Sderaadt  * Format Specific Options List
215df930be7Sderaadt  *
216df930be7Sderaadt  * Used to pass format options to the format options handler
217df930be7Sderaadt  */
218df930be7Sderaadt typedef struct oplist {
219df930be7Sderaadt 	char		*name;		/* option variable name e.g. name= */
220df930be7Sderaadt 	char		*value;		/* value for option variable */
221df930be7Sderaadt 	struct oplist	*fow;		/* next option */
222df930be7Sderaadt } OPLIST;
223df930be7Sderaadt 
224df930be7Sderaadt /*
225df930be7Sderaadt  * General Macros
226df930be7Sderaadt  */
227*b9fc9a72Sderaadt #define MINIMUM(a, b)	(((a) < (b)) ? (a) : (b))
22809c973a4Stholo #define MAJOR(x)	major(x)
22909c973a4Stholo #define MINOR(x)	minor(x)
23009c973a4Stholo #define TODEV(x, y)	makedev((x), (y))
231df930be7Sderaadt 
232df930be7Sderaadt /*
233df930be7Sderaadt  * General Defines
234df930be7Sderaadt  */
235df930be7Sderaadt #define HEX		16
236df930be7Sderaadt #define OCT		8
237df930be7Sderaadt #define _PAX_		1
238f9da32f6Smillert #define _TFILE_BASE	"paxXXXXXXXXXX"
239