xref: /csrg-svn/bin/pax/pax.h (revision 66890)
157119Smuller /*-
257119Smuller  * Copyright (c) 1992 Keith Muller.
360676Sbostic  * Copyright (c) 1992, 1993
460676Sbostic  *	The Regents of the University of California.  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*66890Sbostic  *	@(#)pax.h	8.2 (Berkeley) 04/18/94
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 */
2657545Smuller 				/* 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
5557545Smuller  * 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 */
5957545Smuller 				/* 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 */
6957545Smuller 	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 */
7557545Smuller 				/* to avoid creating incorrect hard links */
7657119Smuller 	int hlk;		/* does archive store hard links info? if */
7757545Smuller 				/* not, we do not bother to look for them */
7857545Smuller 				/* 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? */
8157545Smuller 				/* if not, trailers are assumed to be found */
8257545Smuller 				/* 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 */
8757545Smuller 				/* 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. */
9157545Smuller 				/* This routine is expected to fill all the */
9257545Smuller 				/* 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 */
9757545Smuller 				/* padding and the number of bytes of data */
9857545Smuller 				/* which follow the header. This info is */
9957545Smuller 				/* used skip to the next file header */
10057545Smuller 	off_t (*end_rd)();	/* read cleanup. Allows format to clean up */
10157545Smuller 				/* and MUST RETURN THE LENGTH OF THE TRAILER */
10257545Smuller 				/* RECORD (so append knows how many bytes */
10357545Smuller 				/* 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 */
12657545Smuller 				/* of headers. See get_head() for details */
12757545Smuller 	int (*rd_data)();	/* read/process file data from the archive */
12857545Smuller 	int (*wr_data)();	/* write/process file data to the archive */
12957545Smuller 	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 */
139*66890Sbostic 	char		*pend;		/* end of a prefix match */
14057119Smuller 	int		plen;		/* length of pstr */
14157119Smuller 	int		flgs;		/* processing/state flags */
142*66890Sbostic #define MTCH		0x1		/* pattern has been matched */
143*66890Sbostic #define DIR_MTCH	0x2		/* pattern matched a directory */
14457119Smuller 	struct pattern	*fow;		/* next pattern */
14557119Smuller } PATTERN;
14657119Smuller 
14757119Smuller /*
14857119Smuller  * General Archive Structure (used internal to pax)
14957119Smuller  *
15057119Smuller  * This structure is used to pass information about archive members between
15157119Smuller  * the format independent routines and the format specific routines. When
15257119Smuller  * new archive formats are added, they must accept requests and supply info
15357119Smuller  * encoded in a structure of this type. The name fields are declared statically
15457545Smuller  * here, as there is only ONE of these floating around, size is not a major
15557545Smuller  * consideration. Eventually converting the name fields to a dynamic length
15657545Smuller  * may be required if and when the supporting operating system removes all
15757545Smuller  * restrictions on the length of pathnames it will resolve.
15857119Smuller  */
15957119Smuller typedef struct {
16057119Smuller 	int nlen;			/* file name length */
16157119Smuller 	char name[PAXPATHLEN+1];	/* file name */
16257119Smuller 	int ln_nlen;			/* link name length */
16357119Smuller 	char ln_name[PAXPATHLEN+1];	/* name to link to (if any) */
16457119Smuller 	char *org_name;			/* orig name in file system */
16557119Smuller 	PATTERN *pat;			/* ptr to pattern match (if any) */
16657119Smuller 	struct stat sb;			/* stat buffer see stat(2) */
16757119Smuller 	off_t pad;			/* bytes of padding after file xfer */
16857119Smuller 	off_t skip;			/* bytes of real data after header */
16957545Smuller 					/* IMPORTANT. The st_size field does */
17057545Smuller 					/* not always indicate the amount of */
17157545Smuller 					/* data following the header. */
17257119Smuller 	u_long crc;			/* file crc */
17357119Smuller 	int type;			/* type of file node */
17457119Smuller #define PAX_DIR		1		/* directory */
17557119Smuller #define PAX_CHR		2		/* character device */
17657119Smuller #define PAX_BLK		3		/* block device */
17757119Smuller #define PAX_REG		4		/* regular file */
17857119Smuller #define PAX_SLK		5		/* symbolic link */
17957119Smuller #define PAX_SCK		6		/* socket */
18057119Smuller #define PAX_FIF		7		/* fifo */
18157119Smuller #define PAX_HLK		8		/* hard link */
18257545Smuller #define PAX_HRG		9		/* hard link to a regular file */
18357119Smuller #define PAX_CTG		10		/* high performance file */
18457119Smuller } ARCHD;
18557119Smuller 
18657119Smuller /*
18757119Smuller  * Format Specific Options List
18857119Smuller  *
18957119Smuller  * Used to pass format options to the format options handler
19057119Smuller  */
19157119Smuller typedef struct oplist {
19257119Smuller 	char		*name;		/* option variable name e.g. name= */
19357119Smuller 	char		*value;		/* value for option variable */
19457119Smuller 	struct oplist	*fow;		/* next option */
19557119Smuller } OPLIST;
19657119Smuller 
19757119Smuller /*
19857119Smuller  * General Macros
19957119Smuller  */
20057119Smuller #ifndef MIN
20157119Smuller #define        MIN(a,b) (((a)<(b))?(a):(b))
20257119Smuller #endif
20357119Smuller #define MAJOR(x)        (((unsigned)(x) >> 8) & 0xff)
20457119Smuller #define MINOR(x)        ((x) & 0xff)
20557119Smuller #define TODEV(x, y)	(((unsigned)(x) << 8) | ((unsigned)(y)))
20657119Smuller 
20757119Smuller /*
20857119Smuller  * General Defines
20957119Smuller  */
21057119Smuller #define HEX	16
21157119Smuller #define OCT	8
21257545Smuller #define _PAX_	1
213