pax.h revision 114583
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 114583 2003-05-03 16:39:34Z markm $ 391556Srgrimes */ 401556Srgrimes 411556Srgrimes/* 421556Srgrimes * BSD PAX global data structures and constants. 431556Srgrimes */ 441556Srgrimes 4576351Skris#define MAXBLK 64512 /* MAX blocksize supported (posix SPEC) */ 461556Srgrimes /* WARNING: increasing MAXBLK past 32256 */ 471556Srgrimes /* will violate posix spec. */ 4876351Skris#define MAXBLK_POSIX 32256 /* MAX blocksize supported as per POSIX */ 491556Srgrimes#define BLKMULT 512 /* blocksize must be even mult of 512 bytes */ 501556Srgrimes /* Don't even think of changing this */ 511556Srgrimes#define DEVBLK 8192 /* default read blksize for devices */ 521556Srgrimes#define FILEBLK 10240 /* default read blksize for files */ 5346684Skris#define PAXPATHLEN 3072 /* maximum path length for pax. MUST be */ 5477458Simp /* longer than the system PATH_MAX */ 551556Srgrimes 561556Srgrimes/* 571556Srgrimes * Pax modes of operation 581556Srgrimes */ 591556Srgrimes#define LIST 0 /* List the file in an archive */ 601556Srgrimes#define EXTRACT 1 /* extract the files in an archive */ 611556Srgrimes#define ARCHIVE 2 /* write a new archive */ 621556Srgrimes#define APPND 3 /* append to the end of an archive */ 631556Srgrimes#define COPY 4 /* copy files to destination dir */ 641556Srgrimes#define DEFOP LIST /* if no flags default is to LIST */ 651556Srgrimes 661556Srgrimes/* 678855Srgrimes * Device type of the current archive volume 681556Srgrimes */ 691556Srgrimes#define ISREG 0 /* regular file */ 701556Srgrimes#define ISCHR 1 /* character device */ 711556Srgrimes#define ISBLK 2 /* block device */ 721556Srgrimes#define ISTAPE 3 /* tape drive */ 731556Srgrimes#define ISPIPE 4 /* pipe/socket */ 741556Srgrimes 75114583Smarkmtypedef struct archd ARCHD; 76114583Smarkmtypedef struct fsub FSUB; 77114583Smarkmtypedef struct oplist OPLIST; 78114583Smarkmtypedef struct pattern PATTERN; 79114583Smarkm 801556Srgrimes/* 811556Srgrimes * Format Specific Routine Table 821556Srgrimes * 831556Srgrimes * The format specific routine table allows new archive formats to be quickly 841556Srgrimes * added. Overall pax operation is independent of the actual format used to 858855Srgrimes * form the archive. Only those routines which deal directly with the archive 8646684Skris * are tailored to the oddities of the specific format. All other routines are 871556Srgrimes * independent of the archive format. Data flow in and out of the format 881556Srgrimes * dependent routines pass pointers to ARCHD structure (described below). 891556Srgrimes */ 90114583Smarkmstruct fsub { 91114583Smarkm const char *name; /* name of format, this is the name the user */ 921556Srgrimes /* gives to -x option to select it. */ 931556Srgrimes int bsz; /* default block size. used when the user */ 941556Srgrimes /* does not specify a blocksize for writing */ 951556Srgrimes /* Appends continue to with the blocksize */ 9676017Skris /* the archive is currently using. */ 971556Srgrimes int hsz; /* Header size in bytes. this is the size of */ 981556Srgrimes /* the smallest header this format supports. */ 991556Srgrimes /* Headers are assumed to fit in a BLKMULT. */ 1001556Srgrimes /* If they are bigger, get_head() and */ 1011556Srgrimes /* get_arc() must be adjusted */ 1021556Srgrimes int udev; /* does append require unique dev/ino? some */ 1031556Srgrimes /* formats use the device and inode fields */ 1041556Srgrimes /* to specify hard links. when members in */ 1051556Srgrimes /* the archive have the same inode/dev they */ 1061556Srgrimes /* are assumed to be hard links. During */ 1071556Srgrimes /* append we may have to generate unique ids */ 1081556Srgrimes /* to avoid creating incorrect hard links */ 1091556Srgrimes int hlk; /* does archive store hard links info? if */ 1101556Srgrimes /* not, we do not bother to look for them */ 1111556Srgrimes /* during archive write operations */ 11246684Skris int blkalgn; /* writes must be aligned to blkalgn boundary */ 1131556Srgrimes int inhead; /* is the trailer encoded in a valid header? */ 1141556Srgrimes /* if not, trailers are assumed to be found */ 1151556Srgrimes /* in invalid headers (i.e like tar) */ 116114583Smarkm int (*id)(char *, int); /* checks if a buffer is a valid header */ 1171556Srgrimes /* returns 1 if it is, o.w. returns a 0 */ 118114583Smarkm int (*st_rd)(void); /* initialize routine for read. so format */ 1191556Srgrimes /* can set up tables etc before it starts */ 1201556Srgrimes /* reading an archive */ 121114583Smarkm int (*rd)(ARCHD *, char *); 122114583Smarkm /* read header routine. passed a pointer to */ 1231556Srgrimes /* ARCHD. It must extract the info from the */ 1241556Srgrimes /* format and store it in the ARCHD struct. */ 1251556Srgrimes /* This routine is expected to fill all the */ 1261556Srgrimes /* fields in the ARCHD (including stat buf) */ 1271556Srgrimes /* 0 is returned when a valid header is */ 1281556Srgrimes /* found. -1 when not valid. This routine */ 1291556Srgrimes /* set the skip and pad fields so the format */ 1301556Srgrimes /* independent routines know the amount of */ 1311556Srgrimes /* padding and the number of bytes of data */ 1321556Srgrimes /* which follow the header. This info is */ 1331556Srgrimes /* used skip to the next file header */ 134114583Smarkm off_t (*end_rd)(void); /* read cleanup. Allows format to clean up */ 1351556Srgrimes /* and MUST RETURN THE LENGTH OF THE TRAILER */ 1361556Srgrimes /* RECORD (so append knows how many bytes */ 1371556Srgrimes /* to move back to rewrite the trailer) */ 138114583Smarkm int (*st_wr)(void); /* initialize routine for write operations */ 139114583Smarkm int (*wr)(ARCHD *); /* write archive header. Passed an ARCHD */ 1401556Srgrimes /* filled with the specs on the next file to */ 1411556Srgrimes /* archived. Returns a 1 if no file data is */ 1421556Srgrimes /* is to be stored; 0 if file data is to be */ 1431556Srgrimes /* added. A -1 is returned if a write */ 1441556Srgrimes /* operation to the archive failed. this */ 1451556Srgrimes /* function sets the skip and pad fields so */ 1461556Srgrimes /* the proper padding can be added after */ 1471556Srgrimes /* file data. This routine must NEVER write */ 1481556Srgrimes /* a flawed archive header. */ 149114583Smarkm int (*end_wr)(void); /* end write. write the trailer and do any */ 1501556Srgrimes /* other format specific functions needed */ 151108533Sschweikh /* at the end of an archive write */ 152114583Smarkm int (*trail_cpio)(ARCHD *); 153114583Smarkm int (*trail_tar)(char *, int, int *); 154114583Smarkm /* returns 0 if a valid trailer, -1 if not */ 1551556Srgrimes /* For formats which encode the trailer */ 1561556Srgrimes /* outside of a valid header, a return value */ 1571556Srgrimes /* of 1 indicates that the block passed to */ 1581556Srgrimes /* it can never contain a valid header (skip */ 1591556Srgrimes /* this block, no point in looking at it) */ 160114583Smarkm int (*rd_data)(ARCHD *, int, off_t *); 161114583Smarkm /* read/process file data from the archive */ 162114583Smarkm int (*wr_data)(ARCHD *, int, off_t *); 163114583Smarkm /* write/process file data to the archive */ 164114583Smarkm int (*options)(void); /* process format specific options (-o) */ 165114583Smarkm}; 1661556Srgrimes 1671556Srgrimes/* 1681556Srgrimes * Pattern matching structure 1691556Srgrimes * 1701556Srgrimes * Used to store command line patterns 1711556Srgrimes */ 172114583Smarkmstruct pattern { 1731556Srgrimes char *pstr; /* pattern to match, user supplied */ 1741556Srgrimes char *pend; /* end of a prefix match */ 17576351Skris char *chdname; /* the dir to change to if not NULL. */ 1761556Srgrimes int plen; /* length of pstr */ 1771556Srgrimes int flgs; /* processing/state flags */ 1781556Srgrimes#define MTCH 0x1 /* pattern has been matched */ 1791556Srgrimes#define DIR_MTCH 0x2 /* pattern matched a directory */ 1801556Srgrimes struct pattern *fow; /* next pattern */ 181114583Smarkm}; 1821556Srgrimes 1831556Srgrimes/* 1841556Srgrimes * General Archive Structure (used internal to pax) 1851556Srgrimes * 1861556Srgrimes * This structure is used to pass information about archive members between 1871556Srgrimes * the format independent routines and the format specific routines. When 1881556Srgrimes * new archive formats are added, they must accept requests and supply info 1891556Srgrimes * encoded in a structure of this type. The name fields are declared statically 1901556Srgrimes * here, as there is only ONE of these floating around, size is not a major 1911556Srgrimes * consideration. Eventually converting the name fields to a dynamic length 1921556Srgrimes * may be required if and when the supporting operating system removes all 1931556Srgrimes * restrictions on the length of pathnames it will resolve. 1941556Srgrimes */ 195114583Smarkmstruct archd { 1961556Srgrimes int nlen; /* file name length */ 1971556Srgrimes char name[PAXPATHLEN+1]; /* file name */ 1981556Srgrimes int ln_nlen; /* link name length */ 1991556Srgrimes char ln_name[PAXPATHLEN+1]; /* name to link to (if any) */ 200102230Strhodes char *org_name; /* orig name in file system */ 2011556Srgrimes PATTERN *pat; /* ptr to pattern match (if any) */ 2021556Srgrimes struct stat sb; /* stat buffer see stat(2) */ 2031556Srgrimes off_t pad; /* bytes of padding after file xfer */ 2041556Srgrimes off_t skip; /* bytes of real data after header */ 2051556Srgrimes /* IMPORTANT. The st_size field does */ 2061556Srgrimes /* not always indicate the amount of */ 2071556Srgrimes /* data following the header. */ 2081556Srgrimes u_long crc; /* file crc */ 2091556Srgrimes int type; /* type of file node */ 2101556Srgrimes#define PAX_DIR 1 /* directory */ 2111556Srgrimes#define PAX_CHR 2 /* character device */ 2121556Srgrimes#define PAX_BLK 3 /* block device */ 2131556Srgrimes#define PAX_REG 4 /* regular file */ 2141556Srgrimes#define PAX_SLK 5 /* symbolic link */ 2151556Srgrimes#define PAX_SCK 6 /* socket */ 2161556Srgrimes#define PAX_FIF 7 /* fifo */ 2171556Srgrimes#define PAX_HLK 8 /* hard link */ 2181556Srgrimes#define PAX_HRG 9 /* hard link to a regular file */ 2198855Srgrimes#define PAX_CTG 10 /* high performance file */ 220114583Smarkm}; 2211556Srgrimes 2221556Srgrimes/* 2231556Srgrimes * Format Specific Options List 2241556Srgrimes * 2251556Srgrimes * Used to pass format options to the format options handler 2261556Srgrimes */ 227114583Smarkmstruct oplist { 2281556Srgrimes char *name; /* option variable name e.g. name= */ 2291556Srgrimes char *value; /* value for option variable */ 2301556Srgrimes struct oplist *fow; /* next option */ 231114583Smarkm}; 2321556Srgrimes 2331556Srgrimes/* 2341556Srgrimes * General Macros 2351556Srgrimes */ 2361556Srgrimes#ifndef MIN 23776019Skris#define MIN(a,b) (((a)<(b))?(a):(b)) 2381556Srgrimes#endif 2399322Sbde#define MAJOR(x) major(x) 2409322Sbde#define MINOR(x) minor(x) 2419322Sbde#define TODEV(x, y) makedev((x), (y)) 2421556Srgrimes 2431556Srgrimes/* 2441556Srgrimes * General Defines 2451556Srgrimes */ 24676019Skris#define HEX 16 24776019Skris#define OCT 8 24876019Skris#define _PAX_ 1 24976016Skris#define _TFILE_BASE "paxXXXXXXXXXX" 250