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