pax.h revision 1557
1227614Sluigi/*-
2262151Sluigi * Copyright (c) 1992 Keith Muller.
3227614Sluigi * Copyright (c) 1992, 1993
4227614Sluigi *	The Regents of the University of California.  All rights reserved.
5227614Sluigi *
6227614Sluigi * This code is derived from software contributed to Berkeley by
7227614Sluigi * Keith Muller of the University of California, San Diego.
8227614Sluigi *
9227614Sluigi * Redistribution and use in source and binary forms, with or without
10227614Sluigi * modification, are permitted provided that the following conditions
11227614Sluigi * are met:
12227614Sluigi * 1. Redistributions of source code must retain the above copyright
13227614Sluigi *    notice, this list of conditions and the following disclaimer.
14227614Sluigi * 2. Redistributions in binary form must reproduce the above copyright
15227614Sluigi *    notice, this list of conditions and the following disclaimer in the
16227614Sluigi *    documentation and/or other materials provided with the distribution.
17227614Sluigi * 3. All advertising materials mentioning features or use of this software
18227614Sluigi *    must display the following acknowledgement:
19227614Sluigi *	This product includes software developed by the University of
20227614Sluigi *	California, Berkeley and its contributors.
21227614Sluigi * 4. Neither the name of the University nor the names of its contributors
22227614Sluigi *    may be used to endorse or promote products derived from this software
23227614Sluigi *    without specific prior written permission.
24227614Sluigi *
25227614Sluigi * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26227614Sluigi * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27227614Sluigi * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28227614Sluigi * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29262151Sluigi * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30228276Sluigi * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31228276Sluigi * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32228276Sluigi * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33262151Sluigi * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34262151Sluigi * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35262151Sluigi * SUCH DAMAGE.
36227614Sluigi *
37227614Sluigi *	@(#)pax.h	8.2 (Berkeley) 4/18/94
38262151Sluigi */
39227614Sluigi
40227614Sluigi/*
41228276Sluigi * BSD PAX global data structures and constants.
42228276Sluigi */
43228276Sluigi
44228276Sluigi#define	MAXBLK		32256	/* MAX blocksize supported (posix SPEC) */
45228276Sluigi				/* WARNING: increasing MAXBLK past 32256 */
46228276Sluigi				/* will violate posix spec. */
47228276Sluigi#define BLKMULT		512	/* blocksize must be even mult of 512 bytes */
48228276Sluigi				/* Don't even think of changing this */
49227614Sluigi#define DEVBLK		8192	/* default read blksize for devices */
50227614Sluigi#define FILEBLK		10240	/* default read blksize for files */
51262151Sluigi#define PAXPATHLEN	3072	/* maximium path length for pax. MUST be */
52234140Sluigi				/* longer than the system MAXPATHLEN */
53262151Sluigi
54262151Sluigi/*
55234140Sluigi * Pax modes of operation
56234140Sluigi */
57234140Sluigi#define	LIST		0	/* List the file in an archive */
58234140Sluigi#define	EXTRACT		1	/* extract the files in an archive */
59234140Sluigi#define ARCHIVE		2	/* write a new archive */
60234140Sluigi#define APPND		3	/* append to the end of an archive */
61234140Sluigi#define	COPY		4	/* copy files to destination dir */
62234140Sluigi#define DEFOP		LIST	/* if no flags default is to LIST */
63234140Sluigi
64262151Sluigi/*
65234140Sluigi * Device type of the current archive volume
66234140Sluigi */
67234140Sluigi#define ISREG		0	/* regular file */
68234140Sluigi#define ISCHR		1	/* character device */
69234140Sluigi#define ISBLK		2	/* block device */
70234140Sluigi#define ISTAPE		3	/* tape drive */
71227614Sluigi#define ISPIPE		4	/* pipe/socket */
72227614Sluigi
73234140Sluigi/*
74234140Sluigi * Format Specific Routine Table
75234140Sluigi *
76234140Sluigi * The format specific routine table allows new archive formats to be quickly
77234229Sluigi * added. Overall pax operation is independent of the actual format used to
78234140Sluigi * form the archive. Only those routines which deal directly with the archive
79234140Sluigi * are tailored to the oddities of the specifc format. All other routines are
80234140Sluigi * independent of the archive format. Data flow in and out of the format
81234229Sluigi * dependent routines pass pointers to ARCHD structure (described below).
82234229Sluigi */
83234140Sluigitypedef struct {
84234140Sluigi	char *name;		/* name of format, this is the name the user */
85234140Sluigi				/* gives to -x option to select it. */
86234140Sluigi	int bsz;		/* default block size. used when the user */
87234140Sluigi				/* does not specify a blocksize for writing */
88234227Sluigi				/* Appends continue to with the blocksize */
89234227Sluigi				/* the archive is currently using.*/
90234227Sluigi	int hsz;		/* Header size in bytes. this is the size of */
91234140Sluigi				/* the smallest header this format supports. */
92234140Sluigi				/* Headers are assumed to fit in a BLKMULT. */
93234140Sluigi				/* If they are bigger, get_head() and */
94234140Sluigi				/* get_arc() must be adjusted */
95234140Sluigi	int udev;		/* does append require unique dev/ino? some */
96234140Sluigi				/* formats use the device and inode fields */
97234140Sluigi				/* to specify hard links. when members in */
98234140Sluigi				/* the archive have the same inode/dev they */
99234140Sluigi				/* are assumed to be hard links. During */
100234140Sluigi				/* append we may have to generate unique ids */
101234140Sluigi				/* to avoid creating incorrect hard links */
102234140Sluigi	int hlk;		/* does archive store hard links info? if */
103234227Sluigi				/* not, we do not bother to look for them */
104234227Sluigi				/* during archive write operations */
105234227Sluigi	int blkalgn;		/* writes must be aligned to blkalgn boundry */
106234140Sluigi	int inhead;		/* is the trailer encoded in a valid header? */
107234140Sluigi				/* if not, trailers are assumed to be found */
108234140Sluigi				/* in invalid headers (i.e like tar) */
109234140Sluigi	int (*id)();		/* checks if a buffer is a valid header */
110262151Sluigi				/* returns 1 if it is, o.w. returns a 0 */
111227614Sluigi	int (*st_rd)();		/* initialize routine for read. so format */
112262151Sluigi				/* can set up tables etc before it starts */
113228276Sluigi				/* reading an archive */
114227614Sluigi	int (*rd)();		/* read header routine. passed a pointer to */
115227614Sluigi				/* ARCHD. It must extract the info from the */
116262151Sluigi				/* format and store it in the ARCHD struct. */
117227614Sluigi				/* This routine is expected to fill all the */
118262151Sluigi				/* fields in the ARCHD (including stat buf) */
119227614Sluigi				/* 0 is returned when a valid header is */
120227614Sluigi				/* found. -1 when not valid. This routine */
121262151Sluigi				/* set the skip and pad fields so the format */
122262151Sluigi				/* independent routines know the amount of */
123227614Sluigi				/* padding and the number of bytes of data */
124227614Sluigi				/* which follow the header. This info is */
125227614Sluigi				/* used skip to the next file header */
126227614Sluigi	off_t (*end_rd)();	/* read cleanup. Allows format to clean up */
127234140Sluigi				/* and MUST RETURN THE LENGTH OF THE TRAILER */
128262151Sluigi				/* RECORD (so append knows how many bytes */
129262151Sluigi				/* to move back to rewrite the trailer) */
130262151Sluigi	int (*st_wr)();		/* initialize routine for write operations */
131262151Sluigi	int (*wr)();		/* write archive header. Passed an ARCHD */
132262151Sluigi				/* filled with the specs on the next file to */
133227614Sluigi				/* archived. Returns a 1 if no file data is */
134262151Sluigi				/* is to be stored; 0 if file data is to be */
135262151Sluigi				/* added. A -1 is returned if a write */
136262151Sluigi				/* operation to the archive failed. this */
137262151Sluigi				/* function sets the skip and pad fields so */
138227614Sluigi				/* the proper padding can be added after */
139227614Sluigi				/* file data. This routine must NEVER write */
140227614Sluigi				/* a flawed archive header. */
141227614Sluigi	int (*end_wr)();	/* end write. write the trailer and do any */
142227614Sluigi				/* other format specific functions needed */
143227614Sluigi				/* at the ecnd of a archive write */
144262151Sluigi	int (*trail)();		/* returns 0 if a valid trailer, -1 if not */
145262151Sluigi				/* For formats which encode the trailer */
146262151Sluigi				/* outside of a valid header, a return value */
147228276Sluigi				/* of 1 indicates that the block passed to */
148262151Sluigi				/* it can never contain a valid header (skip */
149262151Sluigi				/* this block, no point in looking at it)  */
150227614Sluigi				/* CAUTION: parameters to this function are */
151262151Sluigi				/* different for trailers inside or outside */
152262151Sluigi				/* of headers. See get_head() for details */
153262151Sluigi	int (*rd_data)();	/* read/process file data from the archive */
154227614Sluigi	int (*wr_data)();	/* write/process file data to the archive */
155227614Sluigi	int (*options)();	/* process format specific options (-o) */
156270252Sluigi} FSUB;
157227614Sluigi
158270252Sluigi/*
159262151Sluigi * Pattern matching structure
160227614Sluigi *
161262151Sluigi * Used to store command line patterns
162262151Sluigi */
163262151Sluigitypedef struct pattern {
164262151Sluigi	char		*pstr;		/* pattern to match, user supplied */
165262151Sluigi	char		*pend;		/* end of a prefix match */
166228276Sluigi	int		plen;		/* length of pstr */
167262151Sluigi	int		flgs;		/* processing/state flags */
168262151Sluigi#define MTCH		0x1		/* pattern has been matched */
169228276Sluigi#define DIR_MTCH	0x2		/* pattern matched a directory */
170238985Sluigi	struct pattern	*fow;		/* next pattern */
171227614Sluigi} PATTERN;
172262151Sluigi
173262151Sluigi/*
174270252Sluigi * General Archive Structure (used internal to pax)
175262151Sluigi *
176227614Sluigi * This structure is used to pass information about archive members between
177227614Sluigi * the format independent routines and the format specific routines. When
178227614Sluigi * new archive formats are added, they must accept requests and supply info
179227614Sluigi * encoded in a structure of this type. The name fields are declared statically
180228276Sluigi * here, as there is only ONE of these floating around, size is not a major
181262151Sluigi * consideration. Eventually converting the name fields to a dynamic length
182262151Sluigi * may be required if and when the supporting operating system removes all
183262151Sluigi * restrictions on the length of pathnames it will resolve.
184228276Sluigi */
185228276Sluigitypedef struct {
186228276Sluigi	int nlen;			/* file name length */
187228276Sluigi	char name[PAXPATHLEN+1];	/* file name */
188262151Sluigi	int ln_nlen;			/* link name length */
189262151Sluigi	char ln_name[PAXPATHLEN+1];	/* name to link to (if any) */
190228276Sluigi	char *org_name;			/* orig name in file system */
191262151Sluigi	PATTERN *pat;			/* ptr to pattern match (if any) */
192228276Sluigi	struct stat sb;			/* stat buffer see stat(2) */
193228276Sluigi	off_t pad;			/* bytes of padding after file xfer */
194228276Sluigi	off_t skip;			/* bytes of real data after header */
195228276Sluigi					/* IMPORTANT. The st_size field does */
196262151Sluigi					/* not always indicate the amount of */
197262151Sluigi					/* data following the header. */
198262151Sluigi	u_long crc;			/* file crc */
199262151Sluigi	int type;			/* type of file node */
200262151Sluigi#define PAX_DIR		1		/* directory */
201262151Sluigi#define PAX_CHR		2		/* character device */
202262151Sluigi#define PAX_BLK		3		/* block device */
203262151Sluigi#define PAX_REG		4		/* regular file */
204262151Sluigi#define PAX_SLK		5		/* symbolic link */
205262151Sluigi#define PAX_SCK		6		/* socket */
206262151Sluigi#define PAX_FIF		7		/* fifo */
207262151Sluigi#define PAX_HLK		8		/* hard link */
208262151Sluigi#define PAX_HRG		9		/* hard link to a regular file */
209262151Sluigi#define PAX_CTG		10		/* high performance file */
210262151Sluigi} ARCHD;
211262151Sluigi
212262151Sluigi/*
213262151Sluigi * Format Specific Options List
214262151Sluigi *
215262151Sluigi * Used to pass format options to the format options handler
216262151Sluigi */
217262151Sluigitypedef struct oplist {
218262151Sluigi	char		*name;		/* option variable name e.g. name= */
219262151Sluigi	char		*value;		/* value for option variable */
220262151Sluigi	struct oplist	*fow;		/* next option */
221262151Sluigi} OPLIST;
222262151Sluigi
223262151Sluigi/*
224262151Sluigi * General Macros
225229939Sluigi */
226270252Sluigi#ifndef MIN
227227614Sluigi#define        MIN(a,b) (((a)<(b))?(a):(b))
228262151Sluigi#endif
229262151Sluigi#define MAJOR(x)        (((unsigned)(x) >> 8) & 0xff)
230262151Sluigi#define MINOR(x)        ((x) & 0xff)
231262151Sluigi#define TODEV(x, y)	(((unsigned)(x) << 8) | ((unsigned)(y)))
232262151Sluigi
233262151Sluigi/*
234232238Sluigi * General Defines
235262151Sluigi */
236262151Sluigi#define HEX	16
237262151Sluigi#define OCT	8
238227614Sluigi#define _PAX_	1
239270252Sluigi