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