pax.h revision 76019
11556Srgrimes/*-
21556Srgrimes * Copyright (c) 1992 Keith Muller.
31556Srgrimes * Copyright (c) 1992, 1993
41556Srgrimes *	The Regents of the University of California.  All rights reserved.
51556Srgrimes *
61556Srgrimes * This code is derived from software contributed to Berkeley by
71556Srgrimes * Keith Muller of the University of California, San Diego.
81556Srgrimes *
91556Srgrimes * Redistribution and use in source and binary forms, with or without
101556Srgrimes * modification, are permitted provided that the following conditions
111556Srgrimes * are met:
121556Srgrimes * 1. Redistributions of source code must retain the above copyright
131556Srgrimes *    notice, this list of conditions and the following disclaimer.
141556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
151556Srgrimes *    notice, this list of conditions and the following disclaimer in the
161556Srgrimes *    documentation and/or other materials provided with the distribution.
171556Srgrimes * 3. All advertising materials mentioning features or use of this software
181556Srgrimes *    must display the following acknowledgement:
191556Srgrimes *	This product includes software developed by the University of
201556Srgrimes *	California, Berkeley and its contributors.
211556Srgrimes * 4. Neither the name of the University nor the names of its contributors
221556Srgrimes *    may be used to endorse or promote products derived from this software
231556Srgrimes *    without specific prior written permission.
241556Srgrimes *
251556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
261556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
271556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
281556Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
291556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
301556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
311556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
321556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
331556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
341556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
351556Srgrimes * SUCH DAMAGE.
361556Srgrimes *
371556Srgrimes *	@(#)pax.h	8.2 (Berkeley) 4/18/94
3850471Speter * $FreeBSD: head/bin/pax/pax.h 76019 2001-04-26 09:22:28Z kris $
391556Srgrimes */
401556Srgrimes
411556Srgrimes/*
421556Srgrimes * BSD PAX global data structures and constants.
431556Srgrimes */
441556Srgrimes
451556Srgrimes#define	MAXBLK		32256	/* MAX blocksize supported (posix SPEC) */
461556Srgrimes				/* WARNING: increasing MAXBLK past 32256 */
471556Srgrimes				/* will violate posix spec. */
481556Srgrimes#define BLKMULT		512	/* blocksize must be even mult of 512 bytes */
491556Srgrimes				/* Don't even think of changing this */
501556Srgrimes#define DEVBLK		8192	/* default read blksize for devices */
511556Srgrimes#define FILEBLK		10240	/* default read blksize for files */
5246684Skris#define PAXPATHLEN	3072	/* maximum path length for pax. MUST be */
531556Srgrimes				/* longer than the system MAXPATHLEN */
541556Srgrimes
551556Srgrimes/*
561556Srgrimes * Pax modes of operation
571556Srgrimes */
581556Srgrimes#define	LIST		0	/* List the file in an archive */
591556Srgrimes#define	EXTRACT		1	/* extract the files in an archive */
601556Srgrimes#define ARCHIVE		2	/* write a new archive */
611556Srgrimes#define APPND		3	/* append to the end of an archive */
621556Srgrimes#define	COPY		4	/* copy files to destination dir */
631556Srgrimes#define DEFOP		LIST	/* if no flags default is to LIST */
641556Srgrimes
651556Srgrimes/*
668855Srgrimes * Device type of the current archive volume
671556Srgrimes */
681556Srgrimes#define ISREG		0	/* regular file */
691556Srgrimes#define ISCHR		1	/* character device */
701556Srgrimes#define ISBLK		2	/* block device */
711556Srgrimes#define ISTAPE		3	/* tape drive */
721556Srgrimes#define ISPIPE		4	/* pipe/socket */
731556Srgrimes
741556Srgrimes/*
751556Srgrimes * Format Specific Routine Table
761556Srgrimes *
771556Srgrimes * The format specific routine table allows new archive formats to be quickly
781556Srgrimes * added. Overall pax operation is independent of the actual format used to
798855Srgrimes * form the archive. Only those routines which deal directly with the archive
8046684Skris * are tailored to the oddities of the specific format. All other routines are
811556Srgrimes * independent of the archive format. Data flow in and out of the format
821556Srgrimes * dependent routines pass pointers to ARCHD structure (described below).
831556Srgrimes */
841556Srgrimestypedef struct {
851556Srgrimes	char *name;		/* name of format, this is the name the user */
861556Srgrimes				/* gives to -x option to select it. */
871556Srgrimes	int bsz;		/* default block size. used when the user */
881556Srgrimes				/* does not specify a blocksize for writing */
891556Srgrimes				/* Appends continue to with the blocksize */
9076017Skris				/* the archive is currently using. */
911556Srgrimes	int hsz;		/* Header size in bytes. this is the size of */
921556Srgrimes				/* the smallest header this format supports. */
931556Srgrimes				/* Headers are assumed to fit in a BLKMULT. */
941556Srgrimes				/* If they are bigger, get_head() and */
951556Srgrimes				/* get_arc() must be adjusted */
961556Srgrimes	int udev;		/* does append require unique dev/ino? some */
971556Srgrimes				/* formats use the device and inode fields */
981556Srgrimes				/* to specify hard links. when members in */
991556Srgrimes				/* the archive have the same inode/dev they */
1001556Srgrimes				/* are assumed to be hard links. During */
1011556Srgrimes				/* append we may have to generate unique ids */
1021556Srgrimes				/* to avoid creating incorrect hard links */
1031556Srgrimes	int hlk;		/* does archive store hard links info? if */
1041556Srgrimes				/* not, we do not bother to look for them */
1051556Srgrimes				/* during archive write operations */
10646684Skris	int blkalgn;		/* writes must be aligned to blkalgn boundary */
1071556Srgrimes	int inhead;		/* is the trailer encoded in a valid header? */
1081556Srgrimes				/* if not, trailers are assumed to be found */
1091556Srgrimes				/* in invalid headers (i.e like tar) */
1101556Srgrimes	int (*id)();		/* checks if a buffer is a valid header */
1111556Srgrimes				/* returns 1 if it is, o.w. returns a 0 */
1121556Srgrimes	int (*st_rd)();		/* initialize routine for read. so format */
1131556Srgrimes				/* can set up tables etc before it starts */
1141556Srgrimes				/* reading an archive */
1151556Srgrimes	int (*rd)();		/* read header routine. passed a pointer to */
1161556Srgrimes				/* ARCHD. It must extract the info from the */
1171556Srgrimes				/* format and store it in the ARCHD struct. */
1181556Srgrimes				/* This routine is expected to fill all the */
1191556Srgrimes				/* fields in the ARCHD (including stat buf) */
1201556Srgrimes				/* 0 is returned when a valid header is */
1211556Srgrimes				/* found. -1 when not valid. This routine */
1221556Srgrimes				/* set the skip and pad fields so the format */
1231556Srgrimes				/* independent routines know the amount of */
1241556Srgrimes				/* padding and the number of bytes of data */
1251556Srgrimes				/* which follow the header. This info is */
1261556Srgrimes				/* used skip to the next file header */
1271556Srgrimes	off_t (*end_rd)();	/* read cleanup. Allows format to clean up */
1281556Srgrimes				/* and MUST RETURN THE LENGTH OF THE TRAILER */
1291556Srgrimes				/* RECORD (so append knows how many bytes */
1301556Srgrimes				/* to move back to rewrite the trailer) */
1311556Srgrimes	int (*st_wr)();		/* initialize routine for write operations */
1321556Srgrimes	int (*wr)();		/* write archive header. Passed an ARCHD */
1331556Srgrimes				/* filled with the specs on the next file to */
1341556Srgrimes				/* archived. Returns a 1 if no file data is */
1351556Srgrimes				/* is to be stored; 0 if file data is to be */
1361556Srgrimes				/* added. A -1 is returned if a write */
1371556Srgrimes				/* operation to the archive failed. this */
1381556Srgrimes				/* function sets the skip and pad fields so */
1391556Srgrimes				/* the proper padding can be added after */
1401556Srgrimes				/* file data. This routine must NEVER write */
1411556Srgrimes				/* a flawed archive header. */
1421556Srgrimes	int (*end_wr)();	/* end write. write the trailer and do any */
1431556Srgrimes				/* other format specific functions needed */
14446684Skris				/* at the end of a archive write */
1451556Srgrimes	int (*trail)();		/* returns 0 if a valid trailer, -1 if not */
1461556Srgrimes				/* For formats which encode the trailer */
1471556Srgrimes				/* outside of a valid header, a return value */
1481556Srgrimes				/* of 1 indicates that the block passed to */
1491556Srgrimes				/* it can never contain a valid header (skip */
1501556Srgrimes				/* this block, no point in looking at it)  */
1511556Srgrimes				/* CAUTION: parameters to this function are */
1521556Srgrimes				/* different for trailers inside or outside */
1531556Srgrimes				/* of headers. See get_head() for details */
1541556Srgrimes	int (*rd_data)();	/* read/process file data from the archive */
1551556Srgrimes	int (*wr_data)();	/* write/process file data to the archive */
1561556Srgrimes	int (*options)();	/* process format specific options (-o) */
1571556Srgrimes} FSUB;
1581556Srgrimes
1591556Srgrimes/*
1601556Srgrimes * Pattern matching structure
1611556Srgrimes *
1621556Srgrimes * Used to store command line patterns
1631556Srgrimes */
1641556Srgrimestypedef struct pattern {
1651556Srgrimes	char		*pstr;		/* pattern to match, user supplied */
1661556Srgrimes	char		*pend;		/* end of a prefix match */
1671556Srgrimes	int		plen;		/* length of pstr */
1681556Srgrimes	int		flgs;		/* processing/state flags */
1691556Srgrimes#define MTCH		0x1		/* pattern has been matched */
1701556Srgrimes#define DIR_MTCH	0x2		/* pattern matched a directory */
1711556Srgrimes	struct pattern	*fow;		/* next pattern */
1721556Srgrimes} PATTERN;
1731556Srgrimes
1741556Srgrimes/*
1751556Srgrimes * General Archive Structure (used internal to pax)
1761556Srgrimes *
1771556Srgrimes * This structure is used to pass information about archive members between
1781556Srgrimes * the format independent routines and the format specific routines. When
1791556Srgrimes * new archive formats are added, they must accept requests and supply info
1801556Srgrimes * encoded in a structure of this type. The name fields are declared statically
1811556Srgrimes * here, as there is only ONE of these floating around, size is not a major
1821556Srgrimes * consideration. Eventually converting the name fields to a dynamic length
1831556Srgrimes * may be required if and when the supporting operating system removes all
1841556Srgrimes * restrictions on the length of pathnames it will resolve.
1851556Srgrimes */
1861556Srgrimestypedef struct {
1871556Srgrimes	int nlen;			/* file name length */
1881556Srgrimes	char name[PAXPATHLEN+1];	/* file name */
1891556Srgrimes	int ln_nlen;			/* link name length */
1901556Srgrimes	char ln_name[PAXPATHLEN+1];	/* name to link to (if any) */
1911556Srgrimes	char *org_name;			/* orig name in file system */
1921556Srgrimes	PATTERN *pat;			/* ptr to pattern match (if any) */
1931556Srgrimes	struct stat sb;			/* stat buffer see stat(2) */
1941556Srgrimes	off_t pad;			/* bytes of padding after file xfer */
1951556Srgrimes	off_t skip;			/* bytes of real data after header */
1961556Srgrimes					/* IMPORTANT. The st_size field does */
1971556Srgrimes					/* not always indicate the amount of */
1981556Srgrimes					/* data following the header. */
1991556Srgrimes	u_long crc;			/* file crc */
2001556Srgrimes	int type;			/* type of file node */
2011556Srgrimes#define PAX_DIR		1		/* directory */
2021556Srgrimes#define PAX_CHR		2		/* character device */
2031556Srgrimes#define PAX_BLK		3		/* block device */
2041556Srgrimes#define PAX_REG		4		/* regular file */
2051556Srgrimes#define PAX_SLK		5		/* symbolic link */
2061556Srgrimes#define PAX_SCK		6		/* socket */
2071556Srgrimes#define PAX_FIF		7		/* fifo */
2081556Srgrimes#define PAX_HLK		8		/* hard link */
2091556Srgrimes#define PAX_HRG		9		/* hard link to a regular file */
2108855Srgrimes#define PAX_CTG		10		/* high performance file */
2111556Srgrimes} ARCHD;
2121556Srgrimes
2131556Srgrimes/*
2141556Srgrimes * Format Specific Options List
2151556Srgrimes *
2161556Srgrimes * Used to pass format options to the format options handler
2171556Srgrimes */
2181556Srgrimestypedef struct oplist {
2191556Srgrimes	char		*name;		/* option variable name e.g. name= */
2201556Srgrimes	char		*value;		/* value for option variable */
2211556Srgrimes	struct oplist	*fow;		/* next option */
2221556Srgrimes} OPLIST;
2231556Srgrimes
2241556Srgrimes/*
2251556Srgrimes * General Macros
2261556Srgrimes */
2271556Srgrimes#ifndef MIN
22876019Skris#define	       MIN(a,b) (((a)<(b))?(a):(b))
2291556Srgrimes#endif
2309322Sbde#define MAJOR(x)	major(x)
2319322Sbde#define MINOR(x)	minor(x)
2329322Sbde#define TODEV(x, y)	makedev((x), (y))
2331556Srgrimes
2341556Srgrimes/*
2351556Srgrimes * General Defines
2361556Srgrimes */
23776019Skris#define HEX		16
23876019Skris#define OCT		8
23976019Skris#define _PAX_		1
24076016Skris#define _TFILE_BASE	"paxXXXXXXXXXX"
241