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