1*df930be7Sderaadt /* $NetBSD: pax.h,v 1.3 1995/03/21 09:07:41 cgd Exp $ */ 2*df930be7Sderaadt 3*df930be7Sderaadt /*- 4*df930be7Sderaadt * Copyright (c) 1992 Keith Muller. 5*df930be7Sderaadt * Copyright (c) 1992, 1993 6*df930be7Sderaadt * The Regents of the University of California. All rights reserved. 7*df930be7Sderaadt * 8*df930be7Sderaadt * This code is derived from software contributed to Berkeley by 9*df930be7Sderaadt * Keith Muller of the University of California, San Diego. 10*df930be7Sderaadt * 11*df930be7Sderaadt * Redistribution and use in source and binary forms, with or without 12*df930be7Sderaadt * modification, are permitted provided that the following conditions 13*df930be7Sderaadt * are met: 14*df930be7Sderaadt * 1. Redistributions of source code must retain the above copyright 15*df930be7Sderaadt * notice, this list of conditions and the following disclaimer. 16*df930be7Sderaadt * 2. Redistributions in binary form must reproduce the above copyright 17*df930be7Sderaadt * notice, this list of conditions and the following disclaimer in the 18*df930be7Sderaadt * documentation and/or other materials provided with the distribution. 19*df930be7Sderaadt * 3. All advertising materials mentioning features or use of this software 20*df930be7Sderaadt * must display the following acknowledgement: 21*df930be7Sderaadt * This product includes software developed by the University of 22*df930be7Sderaadt * California, Berkeley and its contributors. 23*df930be7Sderaadt * 4. Neither the name of the University nor the names of its contributors 24*df930be7Sderaadt * may be used to endorse or promote products derived from this software 25*df930be7Sderaadt * without specific prior written permission. 26*df930be7Sderaadt * 27*df930be7Sderaadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28*df930be7Sderaadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29*df930be7Sderaadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30*df930be7Sderaadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31*df930be7Sderaadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32*df930be7Sderaadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33*df930be7Sderaadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34*df930be7Sderaadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35*df930be7Sderaadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36*df930be7Sderaadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37*df930be7Sderaadt * SUCH DAMAGE. 38*df930be7Sderaadt * 39*df930be7Sderaadt * @(#)pax.h 8.2 (Berkeley) 4/18/94 40*df930be7Sderaadt */ 41*df930be7Sderaadt 42*df930be7Sderaadt /* 43*df930be7Sderaadt * BSD PAX global data structures and constants. 44*df930be7Sderaadt */ 45*df930be7Sderaadt 46*df930be7Sderaadt #define MAXBLK 32256 /* MAX blocksize supported (posix SPEC) */ 47*df930be7Sderaadt /* WARNING: increasing MAXBLK past 32256 */ 48*df930be7Sderaadt /* will violate posix spec. */ 49*df930be7Sderaadt #define BLKMULT 512 /* blocksize must be even mult of 512 bytes */ 50*df930be7Sderaadt /* Don't even think of changing this */ 51*df930be7Sderaadt #define DEVBLK 8192 /* default read blksize for devices */ 52*df930be7Sderaadt #define FILEBLK 10240 /* default read blksize for files */ 53*df930be7Sderaadt #define PAXPATHLEN 3072 /* maximium path length for pax. MUST be */ 54*df930be7Sderaadt /* longer than the system MAXPATHLEN */ 55*df930be7Sderaadt 56*df930be7Sderaadt /* 57*df930be7Sderaadt * Pax modes of operation 58*df930be7Sderaadt */ 59*df930be7Sderaadt #define LIST 0 /* List the file in an archive */ 60*df930be7Sderaadt #define EXTRACT 1 /* extract the files in an archive */ 61*df930be7Sderaadt #define ARCHIVE 2 /* write a new archive */ 62*df930be7Sderaadt #define APPND 3 /* append to the end of an archive */ 63*df930be7Sderaadt #define COPY 4 /* copy files to destination dir */ 64*df930be7Sderaadt #define DEFOP LIST /* if no flags default is to LIST */ 65*df930be7Sderaadt 66*df930be7Sderaadt /* 67*df930be7Sderaadt * Device type of the current archive volume 68*df930be7Sderaadt */ 69*df930be7Sderaadt #define ISREG 0 /* regular file */ 70*df930be7Sderaadt #define ISCHR 1 /* character device */ 71*df930be7Sderaadt #define ISBLK 2 /* block device */ 72*df930be7Sderaadt #define ISTAPE 3 /* tape drive */ 73*df930be7Sderaadt #define ISPIPE 4 /* pipe/socket */ 74*df930be7Sderaadt 75*df930be7Sderaadt /* 76*df930be7Sderaadt * Format Specific Routine Table 77*df930be7Sderaadt * 78*df930be7Sderaadt * The format specific routine table allows new archive formats to be quickly 79*df930be7Sderaadt * added. Overall pax operation is independent of the actual format used to 80*df930be7Sderaadt * form the archive. Only those routines which deal directly with the archive 81*df930be7Sderaadt * are tailored to the oddities of the specifc format. All other routines are 82*df930be7Sderaadt * independent of the archive format. Data flow in and out of the format 83*df930be7Sderaadt * dependent routines pass pointers to ARCHD structure (described below). 84*df930be7Sderaadt */ 85*df930be7Sderaadt typedef struct { 86*df930be7Sderaadt char *name; /* name of format, this is the name the user */ 87*df930be7Sderaadt /* gives to -x option to select it. */ 88*df930be7Sderaadt int bsz; /* default block size. used when the user */ 89*df930be7Sderaadt /* does not specify a blocksize for writing */ 90*df930be7Sderaadt /* Appends continue to with the blocksize */ 91*df930be7Sderaadt /* the archive is currently using.*/ 92*df930be7Sderaadt int hsz; /* Header size in bytes. this is the size of */ 93*df930be7Sderaadt /* the smallest header this format supports. */ 94*df930be7Sderaadt /* Headers are assumed to fit in a BLKMULT. */ 95*df930be7Sderaadt /* If they are bigger, get_head() and */ 96*df930be7Sderaadt /* get_arc() must be adjusted */ 97*df930be7Sderaadt int udev; /* does append require unique dev/ino? some */ 98*df930be7Sderaadt /* formats use the device and inode fields */ 99*df930be7Sderaadt /* to specify hard links. when members in */ 100*df930be7Sderaadt /* the archive have the same inode/dev they */ 101*df930be7Sderaadt /* are assumed to be hard links. During */ 102*df930be7Sderaadt /* append we may have to generate unique ids */ 103*df930be7Sderaadt /* to avoid creating incorrect hard links */ 104*df930be7Sderaadt int hlk; /* does archive store hard links info? if */ 105*df930be7Sderaadt /* not, we do not bother to look for them */ 106*df930be7Sderaadt /* during archive write operations */ 107*df930be7Sderaadt int blkalgn; /* writes must be aligned to blkalgn boundry */ 108*df930be7Sderaadt int inhead; /* is the trailer encoded in a valid header? */ 109*df930be7Sderaadt /* if not, trailers are assumed to be found */ 110*df930be7Sderaadt /* in invalid headers (i.e like tar) */ 111*df930be7Sderaadt int (*id)(); /* checks if a buffer is a valid header */ 112*df930be7Sderaadt /* returns 1 if it is, o.w. returns a 0 */ 113*df930be7Sderaadt int (*st_rd)(); /* initialize routine for read. so format */ 114*df930be7Sderaadt /* can set up tables etc before it starts */ 115*df930be7Sderaadt /* reading an archive */ 116*df930be7Sderaadt int (*rd)(); /* read header routine. passed a pointer to */ 117*df930be7Sderaadt /* ARCHD. It must extract the info from the */ 118*df930be7Sderaadt /* format and store it in the ARCHD struct. */ 119*df930be7Sderaadt /* This routine is expected to fill all the */ 120*df930be7Sderaadt /* fields in the ARCHD (including stat buf) */ 121*df930be7Sderaadt /* 0 is returned when a valid header is */ 122*df930be7Sderaadt /* found. -1 when not valid. This routine */ 123*df930be7Sderaadt /* set the skip and pad fields so the format */ 124*df930be7Sderaadt /* independent routines know the amount of */ 125*df930be7Sderaadt /* padding and the number of bytes of data */ 126*df930be7Sderaadt /* which follow the header. This info is */ 127*df930be7Sderaadt /* used skip to the next file header */ 128*df930be7Sderaadt off_t (*end_rd)(); /* read cleanup. Allows format to clean up */ 129*df930be7Sderaadt /* and MUST RETURN THE LENGTH OF THE TRAILER */ 130*df930be7Sderaadt /* RECORD (so append knows how many bytes */ 131*df930be7Sderaadt /* to move back to rewrite the trailer) */ 132*df930be7Sderaadt int (*st_wr)(); /* initialize routine for write operations */ 133*df930be7Sderaadt int (*wr)(); /* write archive header. Passed an ARCHD */ 134*df930be7Sderaadt /* filled with the specs on the next file to */ 135*df930be7Sderaadt /* archived. Returns a 1 if no file data is */ 136*df930be7Sderaadt /* is to be stored; 0 if file data is to be */ 137*df930be7Sderaadt /* added. A -1 is returned if a write */ 138*df930be7Sderaadt /* operation to the archive failed. this */ 139*df930be7Sderaadt /* function sets the skip and pad fields so */ 140*df930be7Sderaadt /* the proper padding can be added after */ 141*df930be7Sderaadt /* file data. This routine must NEVER write */ 142*df930be7Sderaadt /* a flawed archive header. */ 143*df930be7Sderaadt int (*end_wr)(); /* end write. write the trailer and do any */ 144*df930be7Sderaadt /* other format specific functions needed */ 145*df930be7Sderaadt /* at the ecnd of a archive write */ 146*df930be7Sderaadt int (*trail)(); /* returns 0 if a valid trailer, -1 if not */ 147*df930be7Sderaadt /* For formats which encode the trailer */ 148*df930be7Sderaadt /* outside of a valid header, a return value */ 149*df930be7Sderaadt /* of 1 indicates that the block passed to */ 150*df930be7Sderaadt /* it can never contain a valid header (skip */ 151*df930be7Sderaadt /* this block, no point in looking at it) */ 152*df930be7Sderaadt /* CAUTION: parameters to this function are */ 153*df930be7Sderaadt /* different for trailers inside or outside */ 154*df930be7Sderaadt /* of headers. See get_head() for details */ 155*df930be7Sderaadt int (*rd_data)(); /* read/process file data from the archive */ 156*df930be7Sderaadt int (*wr_data)(); /* write/process file data to the archive */ 157*df930be7Sderaadt int (*options)(); /* process format specific options (-o) */ 158*df930be7Sderaadt } FSUB; 159*df930be7Sderaadt 160*df930be7Sderaadt /* 161*df930be7Sderaadt * Pattern matching structure 162*df930be7Sderaadt * 163*df930be7Sderaadt * Used to store command line patterns 164*df930be7Sderaadt */ 165*df930be7Sderaadt typedef struct pattern { 166*df930be7Sderaadt char *pstr; /* pattern to match, user supplied */ 167*df930be7Sderaadt char *pend; /* end of a prefix match */ 168*df930be7Sderaadt int plen; /* length of pstr */ 169*df930be7Sderaadt int flgs; /* processing/state flags */ 170*df930be7Sderaadt #define MTCH 0x1 /* pattern has been matched */ 171*df930be7Sderaadt #define DIR_MTCH 0x2 /* pattern matched a directory */ 172*df930be7Sderaadt struct pattern *fow; /* next pattern */ 173*df930be7Sderaadt } PATTERN; 174*df930be7Sderaadt 175*df930be7Sderaadt /* 176*df930be7Sderaadt * General Archive Structure (used internal to pax) 177*df930be7Sderaadt * 178*df930be7Sderaadt * This structure is used to pass information about archive members between 179*df930be7Sderaadt * the format independent routines and the format specific routines. When 180*df930be7Sderaadt * new archive formats are added, they must accept requests and supply info 181*df930be7Sderaadt * encoded in a structure of this type. The name fields are declared statically 182*df930be7Sderaadt * here, as there is only ONE of these floating around, size is not a major 183*df930be7Sderaadt * consideration. Eventually converting the name fields to a dynamic length 184*df930be7Sderaadt * may be required if and when the supporting operating system removes all 185*df930be7Sderaadt * restrictions on the length of pathnames it will resolve. 186*df930be7Sderaadt */ 187*df930be7Sderaadt typedef struct { 188*df930be7Sderaadt int nlen; /* file name length */ 189*df930be7Sderaadt char name[PAXPATHLEN+1]; /* file name */ 190*df930be7Sderaadt int ln_nlen; /* link name length */ 191*df930be7Sderaadt char ln_name[PAXPATHLEN+1]; /* name to link to (if any) */ 192*df930be7Sderaadt char *org_name; /* orig name in file system */ 193*df930be7Sderaadt PATTERN *pat; /* ptr to pattern match (if any) */ 194*df930be7Sderaadt struct stat sb; /* stat buffer see stat(2) */ 195*df930be7Sderaadt off_t pad; /* bytes of padding after file xfer */ 196*df930be7Sderaadt off_t skip; /* bytes of real data after header */ 197*df930be7Sderaadt /* IMPORTANT. The st_size field does */ 198*df930be7Sderaadt /* not always indicate the amount of */ 199*df930be7Sderaadt /* data following the header. */ 200*df930be7Sderaadt u_long crc; /* file crc */ 201*df930be7Sderaadt int type; /* type of file node */ 202*df930be7Sderaadt #define PAX_DIR 1 /* directory */ 203*df930be7Sderaadt #define PAX_CHR 2 /* character device */ 204*df930be7Sderaadt #define PAX_BLK 3 /* block device */ 205*df930be7Sderaadt #define PAX_REG 4 /* regular file */ 206*df930be7Sderaadt #define PAX_SLK 5 /* symbolic link */ 207*df930be7Sderaadt #define PAX_SCK 6 /* socket */ 208*df930be7Sderaadt #define PAX_FIF 7 /* fifo */ 209*df930be7Sderaadt #define PAX_HLK 8 /* hard link */ 210*df930be7Sderaadt #define PAX_HRG 9 /* hard link to a regular file */ 211*df930be7Sderaadt #define PAX_CTG 10 /* high performance file */ 212*df930be7Sderaadt } ARCHD; 213*df930be7Sderaadt 214*df930be7Sderaadt /* 215*df930be7Sderaadt * Format Specific Options List 216*df930be7Sderaadt * 217*df930be7Sderaadt * Used to pass format options to the format options handler 218*df930be7Sderaadt */ 219*df930be7Sderaadt typedef struct oplist { 220*df930be7Sderaadt char *name; /* option variable name e.g. name= */ 221*df930be7Sderaadt char *value; /* value for option variable */ 222*df930be7Sderaadt struct oplist *fow; /* next option */ 223*df930be7Sderaadt } OPLIST; 224*df930be7Sderaadt 225*df930be7Sderaadt /* 226*df930be7Sderaadt * General Macros 227*df930be7Sderaadt */ 228*df930be7Sderaadt #ifndef MIN 229*df930be7Sderaadt #define MIN(a,b) (((a)<(b))?(a):(b)) 230*df930be7Sderaadt #endif 231*df930be7Sderaadt #define MAJOR(x) (((unsigned)(x) >> 8) & 0xff) 232*df930be7Sderaadt #define MINOR(x) ((x) & 0xff) 233*df930be7Sderaadt #define TODEV(x, y) (((unsigned)(x) << 8) | ((unsigned)(y))) 234*df930be7Sderaadt 235*df930be7Sderaadt /* 236*df930be7Sderaadt * General Defines 237*df930be7Sderaadt */ 238*df930be7Sderaadt #define HEX 16 239*df930be7Sderaadt #define OCT 8 240*df930be7Sderaadt #define _PAX_ 1 241