1*57119Smuller /*- 2*57119Smuller * Copyright (c) 1992 Keith Muller. 3*57119Smuller * Copyright (c) 1992 The Regents of the University of California. 4*57119Smuller * All rights reserved. 5*57119Smuller * 6*57119Smuller * This code is derived from software contributed to Berkeley by 7*57119Smuller * Keith Muller of the University of California, San Diego. 8*57119Smuller * 9*57119Smuller * %sccs.include.redist.c% 10*57119Smuller * 11*57119Smuller * @(#)pax.h 1.1 (Berkeley) 12/13/92 12*57119Smuller */ 13*57119Smuller 14*57119Smuller /* 15*57119Smuller * BSD PAX global data structures and constants. 16*57119Smuller */ 17*57119Smuller 18*57119Smuller #define MAXBLK 32256 /* MAX blocksize supported (posix SPEC) */ 19*57119Smuller /* WARNING: increasing MAXBLK past 32256 */ 20*57119Smuller /* will violate posix spec. */ 21*57119Smuller #define BLKMULT 512 /* blocksize must be even mult of 512 bytes */ 22*57119Smuller /* Don't even think of changing this */ 23*57119Smuller #define DEVBLK 8192 /* default read blksize for devices */ 24*57119Smuller #define FILEBLK 10240 /* default read blksize for files */ 25*57119Smuller #define PAXPATHLEN 3072 /* maximium path length for pax. MUST be */ 26*57119Smuller /* longer than the system max */ 27*57119Smuller 28*57119Smuller /* 29*57119Smuller * Pax modes of operation 30*57119Smuller */ 31*57119Smuller #define LIST 0 /* List the file in an archive */ 32*57119Smuller #define EXTRACT 1 /* extract the files in an archive */ 33*57119Smuller #define ARCHIVE 2 /* write a new archive */ 34*57119Smuller #define APPND 3 /* append to the end of an archive */ 35*57119Smuller #define COPY 4 /* copy files to destination dir */ 36*57119Smuller #define DEFOP LIST /* if no flags default is to LIST */ 37*57119Smuller 38*57119Smuller /* 39*57119Smuller * Device type of the current archive volume 40*57119Smuller */ 41*57119Smuller #define ISREG 0 /* regular file */ 42*57119Smuller #define ISCHR 1 /* character device */ 43*57119Smuller #define ISBLK 2 /* block device */ 44*57119Smuller #define ISTAPE 3 /* tape drive */ 45*57119Smuller #define ISPIPE 4 /* pipe/socket */ 46*57119Smuller 47*57119Smuller /* 48*57119Smuller * Format Specific Routine Table 49*57119Smuller * 50*57119Smuller * The format specific routine table allows new archive formats to be quickly 51*57119Smuller * added. Overall pax operation is independent of the actual format used to 52*57119Smuller * form the archive. Only those routines which deal directly with the archive 53*57119Smuller * are tailored to the oddities of the specifc format. All other routines are 54*57119Smuller * independent of the archive format. Data flow in and out of the format 55*57119Smuller * dependnent routines pass pointers to ARCHD structure (described below). 56*57119Smuller */ 57*57119Smuller typedef struct { 58*57119Smuller char *name; /* name of format, this is the name the user */ 59*57119Smuller /* gives to -x to select it. */ 60*57119Smuller int bsz; /* default block size. used when the user */ 61*57119Smuller /* does not specify a blocksize for writing */ 62*57119Smuller /* Appends continue to with the blocksize */ 63*57119Smuller /* the archive is currently using.*/ 64*57119Smuller int hsz; /* Header size in bytes. this is the size of */ 65*57119Smuller /* the smallest header this format supports. */ 66*57119Smuller /* Headers are assumed to fit in a BLKMULT. */ 67*57119Smuller /* If they are bigger, get_head() and */ 68*57119Smuller /* get_arc() must be adjusted */ 69*57119Smuller int udev; /* does append require unique dev/ino. some */ 70*57119Smuller /* formats use the device and inode fields */ 71*57119Smuller /* to specify hard links. when members in */ 72*57119Smuller /* the archive have the same inode/dev they */ 73*57119Smuller /* are assumed to be hard links. During */ 74*57119Smuller /* append we may have to generate unique ids */ 75*57119Smuller /* to avoid creating incorrect links */ 76*57119Smuller int hlk; /* does archive store hard links info? if */ 77*57119Smuller /* not we do not bother to look for them */ 78*57119Smuller /* during write operations */ 79*57119Smuller int blkalgn; /* writes must be aligned to blkalgn boundry */ 80*57119Smuller int inhead; /* is the trailer encoded in a valid header? */ 81*57119Smuller /* if not, trailers are assumed to be */ 82*57119Smuller /* invalid headers */ 83*57119Smuller int (*id)(); /* checks if a buffer is a valid header */ 84*57119Smuller /* returns 1 if it is, o.w. returns a 0 */ 85*57119Smuller int (*st_rd)(); /* initialize routine for read. so format */ 86*57119Smuller /* can set up tables etc before it starts */ 87*57119Smuller /* reading */ 88*57119Smuller int (*rd)(); /* read header routine. passed a pointer to */ 89*57119Smuller /* ARCHD. It must extract the info from the */ 90*57119Smuller /* format and store it in the ARCHD struct. */ 91*57119Smuller /* 0 is returned when a valid header is */ 92*57119Smuller /* found. -1 when not valid. This routine */ 93*57119Smuller /* set the skip and pad fields so the format */ 94*57119Smuller /* independent routines know the amount of */ 95*57119Smuller /* padding and the number of bytes to get to */ 96*57119Smuller /* the next file header */ 97*57119Smuller off_t (*end_rd)(); /* read is over. Allows format to clean up */ 98*57119Smuller /* and MUST return the length of the trailer */ 99*57119Smuller /* record (so append knows how many bytes */ 100*57119Smuller /* to move back to rewrite the trailer */ 101*57119Smuller int (*st_wr)(); /* initialize routine for write operations */ 102*57119Smuller int (*wr)(); /* write archive header. Passed an ARCHD */ 103*57119Smuller /* filled with the specs on the next file to */ 104*57119Smuller /* archived. Returns a 1 if no file data is */ 105*57119Smuller /* is to be stored; 0 if file data is to be */ 106*57119Smuller /* added. A -1 is returned if a write */ 107*57119Smuller /* operation to the archive failed. this */ 108*57119Smuller /* function sets the skip and pad fields so */ 109*57119Smuller /* the proper padding can be added after */ 110*57119Smuller /* file data. This routine must NEVER write */ 111*57119Smuller /* a flawed archive header. */ 112*57119Smuller int (*end_wr)(); /* end write. write the trailer and do any */ 113*57119Smuller /* other format specific functions needed */ 114*57119Smuller /* at the ecnd of a archive write */ 115*57119Smuller int (*trail)(); /* returns 0 if a valid trailer, -1 if not */ 116*57119Smuller /* For formats which encode the trailer */ 117*57119Smuller /* outside of a valid header, a return value */ 118*57119Smuller /* of 1 indicates that the block passed to */ 119*57119Smuller /* it can never contain a valid header (skip */ 120*57119Smuller /* this block, no point in looking at it) */ 121*57119Smuller /* CAUTION: parameters to this function are */ 122*57119Smuller /* different for trailers inside or outside */ 123*57119Smuller /* of headers. Se get_head() for details */ 124*57119Smuller int (*rd_data)(); /* read/process file data on the archive */ 125*57119Smuller int (*wr_data)(); /* read/process file data on the archive */ 126*57119Smuller int (*options)(); /* process format options (-x) flags */ 127*57119Smuller } FSUB; 128*57119Smuller 129*57119Smuller /* 130*57119Smuller * Pattern matching structure 131*57119Smuller * 132*57119Smuller * Used to store command line patterns 133*57119Smuller */ 134*57119Smuller typedef struct pattern { 135*57119Smuller char *pstr; /* pattern to match, user supplied */ 136*57119Smuller int plen; /* length of pstr */ 137*57119Smuller int flgs; /* processing/state flags */ 138*57119Smuller #define MTCH 0x1 /* this pattern has been matched */ 139*57119Smuller #define DIR_MTCH 0x2 /* this pattern matched a directory */ 140*57119Smuller struct pattern *fow; /* next pattern */ 141*57119Smuller } PATTERN; 142*57119Smuller 143*57119Smuller /* 144*57119Smuller * General Archive Structure (used internal to pax) 145*57119Smuller * 146*57119Smuller * This structure is used to pass information about archive members between 147*57119Smuller * the format independent routines and the format specific routines. When 148*57119Smuller * new archive formats are added, they must accept requests and supply info 149*57119Smuller * encoded in a structure of this type. The name fields are declared statically 150*57119Smuller * here. The cost of malloc() and free on every archive member was found to be 151*57119Smuller * excessive. Since there is only ONE of these flowting around, size is not a 152*57119Smuller * big consideration. 153*57119Smuller */ 154*57119Smuller typedef struct { 155*57119Smuller int nlen; /* file name length */ 156*57119Smuller char name[PAXPATHLEN+1]; /* file name */ 157*57119Smuller int ln_nlen; /* link name length */ 158*57119Smuller char ln_name[PAXPATHLEN+1]; /* name to link to (if any) */ 159*57119Smuller char *org_name; /* orig name in file system */ 160*57119Smuller PATTERN *pat; /* ptr to pattern match (if any) */ 161*57119Smuller struct stat sb; /* stat buffer see stat(2) */ 162*57119Smuller off_t pad; /* bytes of padding after file xfer */ 163*57119Smuller off_t skip; /* bytes of real data after header */ 164*57119Smuller /* the st_size field may not apply */ 165*57119Smuller u_long crc; /* file crc */ 166*57119Smuller int type; /* type of file node */ 167*57119Smuller #define PAX_DIR 1 /* directory */ 168*57119Smuller #define PAX_CHR 2 /* character device */ 169*57119Smuller #define PAX_BLK 3 /* block device */ 170*57119Smuller #define PAX_REG 4 /* regular file */ 171*57119Smuller #define PAX_SLK 5 /* symbolic link */ 172*57119Smuller #define PAX_SCK 6 /* socket */ 173*57119Smuller #define PAX_FIF 7 /* fifo */ 174*57119Smuller #define PAX_HLK 8 /* hard link */ 175*57119Smuller #define PAX_HRG 9 /* hard link (to a file if known) */ 176*57119Smuller #define PAX_CTG 10 /* high performance file */ 177*57119Smuller } ARCHD; 178*57119Smuller 179*57119Smuller /* 180*57119Smuller * Format Specific Options List 181*57119Smuller * 182*57119Smuller * Used to pass format options to the format options handler 183*57119Smuller */ 184*57119Smuller typedef struct oplist { 185*57119Smuller char *name; /* option variable name e.g. name= */ 186*57119Smuller char *value; /* value for option variable */ 187*57119Smuller struct oplist *fow; /* next option */ 188*57119Smuller } OPLIST; 189*57119Smuller 190*57119Smuller /* 191*57119Smuller * General Macros 192*57119Smuller */ 193*57119Smuller #ifndef MIN 194*57119Smuller #define MIN(a,b) (((a)<(b))?(a):(b)) 195*57119Smuller #endif 196*57119Smuller #define MAJOR(x) (((unsigned)(x) >> 8) & 0xff) 197*57119Smuller #define MINOR(x) ((x) & 0xff) 198*57119Smuller #define TODEV(x, y) (((unsigned)(x) << 8) | ((unsigned)(y))) 199*57119Smuller 200*57119Smuller /* 201*57119Smuller * General Defines 202*57119Smuller */ 203*57119Smuller #define HEX 16 204*57119Smuller #define OCT 8 205