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