xref: /csrg-svn/bin/pax/pax.h (revision 57545)
157119Smuller /*-
257119Smuller  * Copyright (c) 1992 Keith Muller.
357119Smuller  * Copyright (c) 1992 The Regents of the University of California.
457119Smuller  * All rights reserved.
557119Smuller  *
657119Smuller  * This code is derived from software contributed to Berkeley by
757119Smuller  * Keith Muller of the University of California, San Diego.
857119Smuller  *
957119Smuller  * %sccs.include.redist.c%
1057119Smuller  *
11*57545Smuller  *	@(#)pax.h	1.2 (Berkeley) 01/14/93
1257119Smuller  */
1357119Smuller 
1457119Smuller /*
1557119Smuller  * BSD PAX global data structures and constants.
1657119Smuller  */
1757119Smuller 
1857119Smuller #define	MAXBLK		32256	/* MAX blocksize supported (posix SPEC) */
1957119Smuller 				/* WARNING: increasing MAXBLK past 32256 */
2057119Smuller 				/* will violate posix spec. */
2157119Smuller #define BLKMULT		512	/* blocksize must be even mult of 512 bytes */
2257119Smuller 				/* Don't even think of changing this */
2357119Smuller #define DEVBLK		8192	/* default read blksize for devices */
2457119Smuller #define FILEBLK		10240	/* default read blksize for files */
2557119Smuller #define PAXPATHLEN	3072	/* maximium path length for pax. MUST be */
26*57545Smuller 				/* longer than the system MAXPATHLEN */
2757119Smuller 
2857119Smuller /*
2957119Smuller  * Pax modes of operation
3057119Smuller  */
3157119Smuller #define	LIST		0	/* List the file in an archive */
3257119Smuller #define	EXTRACT		1	/* extract the files in an archive */
3357119Smuller #define ARCHIVE		2	/* write a new archive */
3457119Smuller #define APPND		3	/* append to the end of an archive */
3557119Smuller #define	COPY		4	/* copy files to destination dir */
3657119Smuller #define DEFOP		LIST	/* if no flags default is to LIST */
3757119Smuller 
3857119Smuller /*
3957119Smuller  * Device type of the current archive volume
4057119Smuller  */
4157119Smuller #define ISREG		0	/* regular file */
4257119Smuller #define ISCHR		1	/* character device */
4357119Smuller #define ISBLK		2	/* block device */
4457119Smuller #define ISTAPE		3	/* tape drive */
4557119Smuller #define ISPIPE		4	/* pipe/socket */
4657119Smuller 
4757119Smuller /*
4857119Smuller  * Format Specific Routine Table
4957119Smuller  *
5057119Smuller  * The format specific routine table allows new archive formats to be quickly
5157119Smuller  * added. Overall pax operation is independent of the actual format used to
5257119Smuller  * form the archive. Only those routines which deal directly with the archive
5357119Smuller  * are tailored to the oddities of the specifc format. All other routines are
5457119Smuller  * independent of the archive format. Data flow in and out of the format
55*57545Smuller  * dependent routines pass pointers to ARCHD structure (described below).
5657119Smuller  */
5757119Smuller typedef struct {
5857119Smuller 	char *name;		/* name of format, this is the name the user */
59*57545Smuller 				/* gives to -x option to select it. */
6057119Smuller 	int bsz;		/* default block size. used when the user */
6157119Smuller 				/* does not specify a blocksize for writing */
6257119Smuller 				/* Appends continue to with the blocksize */
6357119Smuller 				/* the archive is currently using.*/
6457119Smuller 	int hsz;		/* Header size in bytes. this is the size of */
6557119Smuller 				/* the smallest header this format supports. */
6657119Smuller 				/* Headers are assumed to fit in a BLKMULT. */
6757119Smuller 				/* If they are bigger, get_head() and */
6857119Smuller 				/* get_arc() must be adjusted */
69*57545Smuller 	int udev;		/* does append require unique dev/ino? some */
7057119Smuller 				/* formats use the device and inode fields */
7157119Smuller 				/* to specify hard links. when members in */
7257119Smuller 				/* the archive have the same inode/dev they */
7357119Smuller 				/* are assumed to be hard links. During */
7457119Smuller 				/* append we may have to generate unique ids */
75*57545Smuller 				/* to avoid creating incorrect hard links */
7657119Smuller 	int hlk;		/* does archive store hard links info? if */
77*57545Smuller 				/* not, we do not bother to look for them */
78*57545Smuller 				/* during archive write operations */
7957119Smuller 	int blkalgn;		/* writes must be aligned to blkalgn boundry */
8057119Smuller 	int inhead;		/* is the trailer encoded in a valid header? */
81*57545Smuller 				/* if not, trailers are assumed to be found */
82*57545Smuller 				/* in invalid headers (i.e like tar) */
8357119Smuller 	int (*id)();		/* checks if a buffer is a valid header */
8457119Smuller 				/* returns 1 if it is, o.w. returns a 0 */
8557119Smuller 	int (*st_rd)();		/* initialize routine for read. so format */
8657119Smuller 				/* can set up tables etc before it starts */
87*57545Smuller 				/* reading an archive */
8857119Smuller 	int (*rd)();		/* read header routine. passed a pointer to */
8957119Smuller 				/* ARCHD. It must extract the info from the */
9057119Smuller 				/* format and store it in the ARCHD struct. */
91*57545Smuller 				/* This routine is expected to fill all the */
92*57545Smuller 				/* fields in the ARCHD (including stat buf) */
9357119Smuller 				/* 0 is returned when a valid header is */
9457119Smuller 				/* found. -1 when not valid. This routine */
9557119Smuller 				/* set the skip and pad fields so the format */
9657119Smuller 				/* independent routines know the amount of */
97*57545Smuller 				/* padding and the number of bytes of data */
98*57545Smuller 				/* which follow the header. This info is */
99*57545Smuller 				/* used skip to the next file header */
100*57545Smuller 	off_t (*end_rd)();	/* read cleanup. Allows format to clean up */
101*57545Smuller 				/* and MUST RETURN THE LENGTH OF THE TRAILER */
102*57545Smuller 				/* RECORD (so append knows how many bytes */
103*57545Smuller 				/* to move back to rewrite the trailer) */
10457119Smuller 	int (*st_wr)();		/* initialize routine for write operations */
10557119Smuller 	int (*wr)();		/* write archive header. Passed an ARCHD */
10657119Smuller 				/* filled with the specs on the next file to */
10757119Smuller 				/* archived. Returns a 1 if no file data is */
10857119Smuller 				/* is to be stored; 0 if file data is to be */
10957119Smuller 				/* added. A -1 is returned if a write */
11057119Smuller 				/* operation to the archive failed. this */
11157119Smuller 				/* function sets the skip and pad fields so */
11257119Smuller 				/* the proper padding can be added after */
11357119Smuller 				/* file data. This routine must NEVER write */
11457119Smuller 				/* a flawed archive header. */
11557119Smuller 	int (*end_wr)();	/* end write. write the trailer and do any */
11657119Smuller 				/* other format specific functions needed */
11757119Smuller 				/* at the ecnd of a archive write */
11857119Smuller 	int (*trail)();		/* returns 0 if a valid trailer, -1 if not */
11957119Smuller 				/* For formats which encode the trailer */
12057119Smuller 				/* outside of a valid header, a return value */
12157119Smuller 				/* of 1 indicates that the block passed to */
12257119Smuller 				/* it can never contain a valid header (skip */
12357119Smuller 				/* this block, no point in looking at it)  */
12457119Smuller 				/* CAUTION: parameters to this function are */
12557119Smuller 				/* different for trailers inside or outside */
126*57545Smuller 				/* of headers. See get_head() for details */
127*57545Smuller 	int (*rd_data)();	/* read/process file data from the archive */
128*57545Smuller 	int (*wr_data)();	/* write/process file data to the archive */
129*57545Smuller 	int (*options)();	/* process format specific options (-o) */
13057119Smuller } FSUB;
13157119Smuller 
13257119Smuller /*
13357119Smuller  * Pattern matching structure
13457119Smuller  *
13557119Smuller  * Used to store command line patterns
13657119Smuller  */
13757119Smuller typedef struct pattern {
13857119Smuller 	char		*pstr;		/* pattern to match, user supplied */
13957119Smuller 	int		plen;		/* length of pstr */
14057119Smuller 	int		flgs;		/* processing/state flags */
14157119Smuller #define MTCH		0x1		/* this pattern has been matched */
14257119Smuller #define DIR_MTCH	0x2		/* this pattern matched a directory */
14357119Smuller 	struct pattern	*fow;		/* next pattern */
14457119Smuller } PATTERN;
14557119Smuller 
14657119Smuller /*
14757119Smuller  * General Archive Structure (used internal to pax)
14857119Smuller  *
14957119Smuller  * This structure is used to pass information about archive members between
15057119Smuller  * the format independent routines and the format specific routines. When
15157119Smuller  * new archive formats are added, they must accept requests and supply info
15257119Smuller  * encoded in a structure of this type. The name fields are declared statically
153*57545Smuller  * here, as there is only ONE of these floating around, size is not a major
154*57545Smuller  * consideration. Eventually converting the name fields to a dynamic length
155*57545Smuller  * may be required if and when the supporting operating system removes all
156*57545Smuller  * restrictions on the length of pathnames it will resolve.
15757119Smuller  */
15857119Smuller typedef struct {
15957119Smuller 	int nlen;			/* file name length */
16057119Smuller 	char name[PAXPATHLEN+1];	/* file name */
16157119Smuller 	int ln_nlen;			/* link name length */
16257119Smuller 	char ln_name[PAXPATHLEN+1];	/* name to link to (if any) */
16357119Smuller 	char *org_name;			/* orig name in file system */
16457119Smuller 	PATTERN *pat;			/* ptr to pattern match (if any) */
16557119Smuller 	struct stat sb;			/* stat buffer see stat(2) */
16657119Smuller 	off_t pad;			/* bytes of padding after file xfer */
16757119Smuller 	off_t skip;			/* bytes of real data after header */
168*57545Smuller 					/* IMPORTANT. The st_size field does */
169*57545Smuller 					/* not always indicate the amount of */
170*57545Smuller 					/* data following the header. */
17157119Smuller 	u_long crc;			/* file crc */
17257119Smuller 	int type;			/* type of file node */
17357119Smuller #define PAX_DIR		1		/* directory */
17457119Smuller #define PAX_CHR		2		/* character device */
17557119Smuller #define PAX_BLK		3		/* block device */
17657119Smuller #define PAX_REG		4		/* regular file */
17757119Smuller #define PAX_SLK		5		/* symbolic link */
17857119Smuller #define PAX_SCK		6		/* socket */
17957119Smuller #define PAX_FIF		7		/* fifo */
18057119Smuller #define PAX_HLK		8		/* hard link */
181*57545Smuller #define PAX_HRG		9		/* hard link to a regular file */
18257119Smuller #define PAX_CTG		10		/* high performance file */
18357119Smuller } ARCHD;
18457119Smuller 
18557119Smuller /*
18657119Smuller  * Format Specific Options List
18757119Smuller  *
18857119Smuller  * Used to pass format options to the format options handler
18957119Smuller  */
19057119Smuller typedef struct oplist {
19157119Smuller 	char		*name;		/* option variable name e.g. name= */
19257119Smuller 	char		*value;		/* value for option variable */
19357119Smuller 	struct oplist	*fow;		/* next option */
19457119Smuller } OPLIST;
19557119Smuller 
19657119Smuller /*
19757119Smuller  * General Macros
19857119Smuller  */
19957119Smuller #ifndef MIN
20057119Smuller #define        MIN(a,b) (((a)<(b))?(a):(b))
20157119Smuller #endif
20257119Smuller #define MAJOR(x)        (((unsigned)(x) >> 8) & 0xff)
20357119Smuller #define MINOR(x)        ((x) & 0xff)
20457119Smuller #define TODEV(x, y)	(((unsigned)(x) << 8) | ((unsigned)(y)))
20557119Smuller 
20657119Smuller /*
20757119Smuller  * General Defines
20857119Smuller  */
20957119Smuller #define HEX	16
21057119Smuller #define OCT	8
211*57545Smuller #define _PAX_	1
212