pax.h revision 1556
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 381556Srgrimes */ 391556Srgrimes 401556Srgrimes/* 411556Srgrimes * BSD PAX global data structures and constants. 421556Srgrimes */ 431556Srgrimes 441556Srgrimes#define MAXBLK 32256 /* MAX blocksize supported (posix SPEC) */ 451556Srgrimes /* WARNING: increasing MAXBLK past 32256 */ 461556Srgrimes /* will violate posix spec. */ 471556Srgrimes#define BLKMULT 512 /* blocksize must be even mult of 512 bytes */ 481556Srgrimes /* Don't even think of changing this */ 491556Srgrimes#define DEVBLK 8192 /* default read blksize for devices */ 501556Srgrimes#define FILEBLK 10240 /* default read blksize for files */ 511556Srgrimes#define PAXPATHLEN 3072 /* maximium path length for pax. MUST be */ 521556Srgrimes /* longer than the system MAXPATHLEN */ 531556Srgrimes 541556Srgrimes/* 551556Srgrimes * Pax modes of operation 561556Srgrimes */ 571556Srgrimes#define LIST 0 /* List the file in an archive */ 581556Srgrimes#define EXTRACT 1 /* extract the files in an archive */ 591556Srgrimes#define ARCHIVE 2 /* write a new archive */ 601556Srgrimes#define APPND 3 /* append to the end of an archive */ 611556Srgrimes#define COPY 4 /* copy files to destination dir */ 621556Srgrimes#define DEFOP LIST /* if no flags default is to LIST */ 631556Srgrimes 641556Srgrimes/* 651556Srgrimes * Device type of the current archive volume 661556Srgrimes */ 671556Srgrimes#define ISREG 0 /* regular file */ 681556Srgrimes#define ISCHR 1 /* character device */ 691556Srgrimes#define ISBLK 2 /* block device */ 701556Srgrimes#define ISTAPE 3 /* tape drive */ 711556Srgrimes#define ISPIPE 4 /* pipe/socket */ 721556Srgrimes 731556Srgrimes/* 741556Srgrimes * Format Specific Routine Table 751556Srgrimes * 761556Srgrimes * The format specific routine table allows new archive formats to be quickly 771556Srgrimes * added. Overall pax operation is independent of the actual format used to 781556Srgrimes * form the archive. Only those routines which deal directly with the archive 791556Srgrimes * are tailored to the oddities of the specifc format. All other routines are 801556Srgrimes * independent of the archive format. Data flow in and out of the format 811556Srgrimes * dependent routines pass pointers to ARCHD structure (described below). 821556Srgrimes */ 831556Srgrimestypedef struct { 841556Srgrimes char *name; /* name of format, this is the name the user */ 851556Srgrimes /* gives to -x option to select it. */ 861556Srgrimes int bsz; /* default block size. used when the user */ 871556Srgrimes /* does not specify a blocksize for writing */ 881556Srgrimes /* Appends continue to with the blocksize */ 891556Srgrimes /* the archive is currently using.*/ 901556Srgrimes int hsz; /* Header size in bytes. this is the size of */ 911556Srgrimes /* the smallest header this format supports. */ 921556Srgrimes /* Headers are assumed to fit in a BLKMULT. */ 931556Srgrimes /* If they are bigger, get_head() and */ 941556Srgrimes /* get_arc() must be adjusted */ 951556Srgrimes int udev; /* does append require unique dev/ino? some */ 961556Srgrimes /* formats use the device and inode fields */ 971556Srgrimes /* to specify hard links. when members in */ 981556Srgrimes /* the archive have the same inode/dev they */ 991556Srgrimes /* are assumed to be hard links. During */ 1001556Srgrimes /* append we may have to generate unique ids */ 1011556Srgrimes /* to avoid creating incorrect hard links */ 1021556Srgrimes int hlk; /* does archive store hard links info? if */ 1031556Srgrimes /* not, we do not bother to look for them */ 1041556Srgrimes /* during archive write operations */ 1051556Srgrimes int blkalgn; /* writes must be aligned to blkalgn boundry */ 1061556Srgrimes int inhead; /* is the trailer encoded in a valid header? */ 1071556Srgrimes /* if not, trailers are assumed to be found */ 1081556Srgrimes /* in invalid headers (i.e like tar) */ 1091556Srgrimes int (*id)(); /* checks if a buffer is a valid header */ 1101556Srgrimes /* returns 1 if it is, o.w. returns a 0 */ 1111556Srgrimes int (*st_rd)(); /* initialize routine for read. so format */ 1121556Srgrimes /* can set up tables etc before it starts */ 1131556Srgrimes /* reading an archive */ 1141556Srgrimes int (*rd)(); /* read header routine. passed a pointer to */ 1151556Srgrimes /* ARCHD. It must extract the info from the */ 1161556Srgrimes /* format and store it in the ARCHD struct. */ 1171556Srgrimes /* This routine is expected to fill all the */ 1181556Srgrimes /* fields in the ARCHD (including stat buf) */ 1191556Srgrimes /* 0 is returned when a valid header is */ 1201556Srgrimes /* found. -1 when not valid. This routine */ 1211556Srgrimes /* set the skip and pad fields so the format */ 1221556Srgrimes /* independent routines know the amount of */ 1231556Srgrimes /* padding and the number of bytes of data */ 1241556Srgrimes /* which follow the header. This info is */ 1251556Srgrimes /* used skip to the next file header */ 1261556Srgrimes off_t (*end_rd)(); /* read cleanup. Allows format to clean up */ 1271556Srgrimes /* and MUST RETURN THE LENGTH OF THE TRAILER */ 1281556Srgrimes /* RECORD (so append knows how many bytes */ 1291556Srgrimes /* to move back to rewrite the trailer) */ 1301556Srgrimes int (*st_wr)(); /* initialize routine for write operations */ 1311556Srgrimes int (*wr)(); /* write archive header. Passed an ARCHD */ 1321556Srgrimes /* filled with the specs on the next file to */ 1331556Srgrimes /* archived. Returns a 1 if no file data is */ 1341556Srgrimes /* is to be stored; 0 if file data is to be */ 1351556Srgrimes /* added. A -1 is returned if a write */ 1361556Srgrimes /* operation to the archive failed. this */ 1371556Srgrimes /* function sets the skip and pad fields so */ 1381556Srgrimes /* the proper padding can be added after */ 1391556Srgrimes /* file data. This routine must NEVER write */ 1401556Srgrimes /* a flawed archive header. */ 1411556Srgrimes int (*end_wr)(); /* end write. write the trailer and do any */ 1421556Srgrimes /* other format specific functions needed */ 1431556Srgrimes /* at the ecnd of a archive write */ 1441556Srgrimes int (*trail)(); /* returns 0 if a valid trailer, -1 if not */ 1451556Srgrimes /* For formats which encode the trailer */ 1461556Srgrimes /* outside of a valid header, a return value */ 1471556Srgrimes /* of 1 indicates that the block passed to */ 1481556Srgrimes /* it can never contain a valid header (skip */ 1491556Srgrimes /* this block, no point in looking at it) */ 1501556Srgrimes /* CAUTION: parameters to this function are */ 1511556Srgrimes /* different for trailers inside or outside */ 1521556Srgrimes /* of headers. See get_head() for details */ 1531556Srgrimes int (*rd_data)(); /* read/process file data from the archive */ 1541556Srgrimes int (*wr_data)(); /* write/process file data to the archive */ 1551556Srgrimes int (*options)(); /* process format specific options (-o) */ 1561556Srgrimes} FSUB; 1571556Srgrimes 1581556Srgrimes/* 1591556Srgrimes * Pattern matching structure 1601556Srgrimes * 1611556Srgrimes * Used to store command line patterns 1621556Srgrimes */ 1631556Srgrimestypedef struct pattern { 1641556Srgrimes char *pstr; /* pattern to match, user supplied */ 1651556Srgrimes char *pend; /* end of a prefix match */ 1661556Srgrimes int plen; /* length of pstr */ 1671556Srgrimes int flgs; /* processing/state flags */ 1681556Srgrimes#define MTCH 0x1 /* pattern has been matched */ 1691556Srgrimes#define DIR_MTCH 0x2 /* pattern matched a directory */ 1701556Srgrimes struct pattern *fow; /* next pattern */ 1711556Srgrimes} PATTERN; 1721556Srgrimes 1731556Srgrimes/* 1741556Srgrimes * General Archive Structure (used internal to pax) 1751556Srgrimes * 1761556Srgrimes * This structure is used to pass information about archive members between 1771556Srgrimes * the format independent routines and the format specific routines. When 1781556Srgrimes * new archive formats are added, they must accept requests and supply info 1791556Srgrimes * encoded in a structure of this type. The name fields are declared statically 1801556Srgrimes * here, as there is only ONE of these floating around, size is not a major 1811556Srgrimes * consideration. Eventually converting the name fields to a dynamic length 1821556Srgrimes * may be required if and when the supporting operating system removes all 1831556Srgrimes * restrictions on the length of pathnames it will resolve. 1841556Srgrimes */ 1851556Srgrimestypedef struct { 1861556Srgrimes int nlen; /* file name length */ 1871556Srgrimes char name[PAXPATHLEN+1]; /* file name */ 1881556Srgrimes int ln_nlen; /* link name length */ 1891556Srgrimes char ln_name[PAXPATHLEN+1]; /* name to link to (if any) */ 1901556Srgrimes char *org_name; /* orig name in file system */ 1911556Srgrimes PATTERN *pat; /* ptr to pattern match (if any) */ 1921556Srgrimes struct stat sb; /* stat buffer see stat(2) */ 1931556Srgrimes off_t pad; /* bytes of padding after file xfer */ 1941556Srgrimes off_t skip; /* bytes of real data after header */ 1951556Srgrimes /* IMPORTANT. The st_size field does */ 1961556Srgrimes /* not always indicate the amount of */ 1971556Srgrimes /* data following the header. */ 1981556Srgrimes u_long crc; /* file crc */ 1991556Srgrimes int type; /* type of file node */ 2001556Srgrimes#define PAX_DIR 1 /* directory */ 2011556Srgrimes#define PAX_CHR 2 /* character device */ 2021556Srgrimes#define PAX_BLK 3 /* block device */ 2031556Srgrimes#define PAX_REG 4 /* regular file */ 2041556Srgrimes#define PAX_SLK 5 /* symbolic link */ 2051556Srgrimes#define PAX_SCK 6 /* socket */ 2061556Srgrimes#define PAX_FIF 7 /* fifo */ 2071556Srgrimes#define PAX_HLK 8 /* hard link */ 2081556Srgrimes#define PAX_HRG 9 /* hard link to a regular file */ 2091556Srgrimes#define PAX_CTG 10 /* high performance file */ 2101556Srgrimes} ARCHD; 2111556Srgrimes 2121556Srgrimes/* 2131556Srgrimes * Format Specific Options List 2141556Srgrimes * 2151556Srgrimes * Used to pass format options to the format options handler 2161556Srgrimes */ 2171556Srgrimestypedef struct oplist { 2181556Srgrimes char *name; /* option variable name e.g. name= */ 2191556Srgrimes char *value; /* value for option variable */ 2201556Srgrimes struct oplist *fow; /* next option */ 2211556Srgrimes} OPLIST; 2221556Srgrimes 2231556Srgrimes/* 2241556Srgrimes * General Macros 2251556Srgrimes */ 2261556Srgrimes#ifndef MIN 2271556Srgrimes#define MIN(a,b) (((a)<(b))?(a):(b)) 2281556Srgrimes#endif 2291556Srgrimes#define MAJOR(x) (((unsigned)(x) >> 8) & 0xff) 2301556Srgrimes#define MINOR(x) ((x) & 0xff) 2311556Srgrimes#define TODEV(x, y) (((unsigned)(x) << 8) | ((unsigned)(y))) 2321556Srgrimes 2331556Srgrimes/* 2341556Srgrimes * General Defines 2351556Srgrimes */ 2361556Srgrimes#define HEX 16 2371556Srgrimes#define OCT 8 2381556Srgrimes#define _PAX_ 1 239