pax.h revision 8855
197318Sphk/*- 297318Sphk * Copyright (c) 1992 Keith Muller. 397318Sphk * Copyright (c) 1992, 1993 497318Sphk * The Regents of the University of California. All rights reserved. 597318Sphk * 697318Sphk * This code is derived from software contributed to Berkeley by 797318Sphk * Keith Muller of the University of California, San Diego. 897318Sphk * 997318Sphk * Redistribution and use in source and binary forms, with or without 1097318Sphk * modification, are permitted provided that the following conditions 1197318Sphk * are met: 1297318Sphk * 1. Redistributions of source code must retain the above copyright 1397318Sphk * notice, this list of conditions and the following disclaimer. 1497318Sphk * 2. Redistributions in binary form must reproduce the above copyright 1597318Sphk * notice, this list of conditions and the following disclaimer in the 1697318Sphk * documentation and/or other materials provided with the distribution. 1797318Sphk * 3. All advertising materials mentioning features or use of this software 1897318Sphk * must display the following acknowledgement: 1997318Sphk * This product includes software developed by the University of 2097318Sphk * California, Berkeley and its contributors. 2197318Sphk * 4. Neither the name of the University nor the names of its contributors 2297318Sphk * may be used to endorse or promote products derived from this software 2397318Sphk * without specific prior written permission. 2497318Sphk * 2597318Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2697318Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2797318Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2897318Sphk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2997318Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3097318Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3197318Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3297318Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3397318Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34139778Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35139778Simp * SUCH DAMAGE. 36139778Simp * 3797318Sphk * @(#)pax.h 8.2 (Berkeley) 4/18/94 3897318Sphk * $Id: pax.h,v 1.2 1994/09/24 02:56:28 davidg Exp $ 3997318Sphk */ 4097318Sphk 4197318Sphk/* 4297318Sphk * BSD PAX global data structures and constants. 43116196Sobrien */ 44116196Sobrien 45116196Sobrien#define MAXBLK 32256 /* MAX blocksize supported (posix SPEC) */ 4697318Sphk /* WARNING: increasing MAXBLK past 32256 */ 4797318Sphk /* will violate posix spec. */ 4897318Sphk#define BLKMULT 512 /* blocksize must be even mult of 512 bytes */ 4997318Sphk /* Don't even think of changing this */ 5097318Sphk#define DEVBLK 8192 /* default read blksize for devices */ 5197318Sphk#define FILEBLK 10240 /* default read blksize for files */ 5297318Sphk#define PAXPATHLEN 3072 /* maximium path length for pax. MUST be */ 5397318Sphk /* longer than the system MAXPATHLEN */ 5498987Sphk 55104087Sphk/* 5698987Sphk * Pax modes of operation 5797318Sphk */ 5897318Sphk#define LIST 0 /* List the file in an archive */ 5997318Sphk#define EXTRACT 1 /* extract the files in an archive */ 60143418Sume#define ARCHIVE 2 /* write a new archive */ 6197318Sphk#define APPND 3 /* append to the end of an archive */ 6297318Sphk#define COPY 4 /* copy files to destination dir */ 6397318Sphk#define DEFOP LIST /* if no flags default is to LIST */ 6498987Sphk 6598987Sphk/* 66107953Sphk * Device type of the current archive volume 67107953Sphk */ 68107953Sphk#define ISREG 0 /* regular file */ 6997318Sphk#define ISCHR 1 /* character device */ 7097318Sphk#define ISBLK 2 /* block device */ 7197318Sphk#define ISTAPE 3 /* tape drive */ 7298987Sphk#define ISPIPE 4 /* pipe/socket */ 7398987Sphk 7498987Sphk/* 7598987Sphk * Format Specific Routine Table 7698987Sphk * 7797318Sphk * The format specific routine table allows new archive formats to be quickly 7897318Sphk * added. Overall pax operation is independent of the actual format used to 7997318Sphk * form the archive. Only those routines which deal directly with the archive 8098987Sphk * are tailored to the oddities of the specifc format. All other routines are 8197318Sphk * independent of the archive format. Data flow in and out of the format 8297318Sphk * dependent routines pass pointers to ARCHD structure (described below). 8398987Sphk */ 8498987Sphktypedef struct { 8598987Sphk char *name; /* name of format, this is the name the user */ 8698987Sphk /* gives to -x option to select it. */ 8798987Sphk int bsz; /* default block size. used when the user */ 8898987Sphk /* does not specify a blocksize for writing */ 8998987Sphk /* Appends continue to with the blocksize */ 9098987Sphk /* the archive is currently using.*/ 9198987Sphk int hsz; /* Header size in bytes. this is the size of */ 9298987Sphk /* the smallest header this format supports. */ 9398987Sphk /* Headers are assumed to fit in a BLKMULT. */ 9498987Sphk /* If they are bigger, get_head() and */ 9598987Sphk /* get_arc() must be adjusted */ 9698987Sphk int udev; /* does append require unique dev/ino? some */ 9797318Sphk /* formats use the device and inode fields */ 9898987Sphk /* to specify hard links. when members in */ 9998987Sphk /* the archive have the same inode/dev they */ 10098987Sphk /* are assumed to be hard links. During */ 10198987Sphk /* append we may have to generate unique ids */ 10298987Sphk /* to avoid creating incorrect hard links */ 10398987Sphk int hlk; /* does archive store hard links info? if */ 10498987Sphk /* not, we do not bother to look for them */ 10598987Sphk /* during archive write operations */ 10698987Sphk int blkalgn; /* writes must be aligned to blkalgn boundry */ 10798987Sphk int inhead; /* is the trailer encoded in a valid header? */ 10898987Sphk /* if not, trailers are assumed to be found */ 10998987Sphk /* in invalid headers (i.e like tar) */ 11098987Sphk int (*id)(); /* checks if a buffer is a valid header */ 11198987Sphk /* returns 1 if it is, o.w. returns a 0 */ 11298987Sphk int (*st_rd)(); /* initialize routine for read. so format */ 11398987Sphk /* can set up tables etc before it starts */ 11498987Sphk /* reading an archive */ 11598987Sphk int (*rd)(); /* read header routine. passed a pointer to */ 11698987Sphk /* ARCHD. It must extract the info from the */ 11798987Sphk /* format and store it in the ARCHD struct. */ 11898987Sphk /* This routine is expected to fill all the */ 11998987Sphk /* fields in the ARCHD (including stat buf) */ 12098987Sphk /* 0 is returned when a valid header is */ 12198987Sphk /* found. -1 when not valid. This routine */ 12298987Sphk /* set the skip and pad fields so the format */ 12398987Sphk /* independent routines know the amount of */ 12498987Sphk /* padding and the number of bytes of data */ 12598987Sphk /* which follow the header. This info is */ 12698987Sphk /* used skip to the next file header */ 12798987Sphk off_t (*end_rd)(); /* read cleanup. Allows format to clean up */ 12898987Sphk /* and MUST RETURN THE LENGTH OF THE TRAILER */ 12998987Sphk /* RECORD (so append knows how many bytes */ 13098987Sphk /* to move back to rewrite the trailer) */ 13198987Sphk int (*st_wr)(); /* initialize routine for write operations */ 13298987Sphk int (*wr)(); /* write archive header. Passed an ARCHD */ 13398987Sphk /* filled with the specs on the next file to */ 13497318Sphk /* archived. Returns a 1 if no file data is */ 13597318Sphk /* is to be stored; 0 if file data is to be */ 13697318Sphk /* added. A -1 is returned if a write */ 13797318Sphk /* operation to the archive failed. this */ 13897318Sphk /* function sets the skip and pad fields so */ 13998987Sphk /* the proper padding can be added after */ 14098987Sphk /* file data. This routine must NEVER write */ 14197318Sphk /* a flawed archive header. */ 14297318Sphk int (*end_wr)(); /* end write. write the trailer and do any */ 14397318Sphk /* other format specific functions needed */ 144111119Simp /* at the ecnd of a archive write */ 14597318Sphk int (*trail)(); /* returns 0 if a valid trailer, -1 if not */ 14697318Sphk /* For formats which encode the trailer */ 14797318Sphk /* outside of a valid header, a return value */ 14898987Sphk /* of 1 indicates that the block passed to */ 14997318Sphk /* it can never contain a valid header (skip */ 15098987Sphk /* this block, no point in looking at it) */ 15198987Sphk /* CAUTION: parameters to this function are */ 15297318Sphk /* different for trailers inside or outside */ 15398987Sphk /* of headers. See get_head() for details */ 15497318Sphk int (*rd_data)(); /* read/process file data from the archive */ 15598987Sphk int (*wr_data)(); /* write/process file data to the archive */ 15698987Sphk int (*options)(); /* process format specific options (-o) */ 15798987Sphk} FSUB; 15897318Sphk 15997318Sphk/* 16097318Sphk * Pattern matching structure 16197318Sphk * 16297318Sphk * Used to store command line patterns 16397318Sphk */ 16497318Sphktypedef struct pattern { 16598987Sphk char *pstr; /* pattern to match, user supplied */ 16697318Sphk char *pend; /* end of a prefix match */ 16797318Sphk int plen; /* length of pstr */ 16897318Sphk int flgs; /* processing/state flags */ 16997318Sphk#define MTCH 0x1 /* pattern has been matched */ 17097318Sphk#define DIR_MTCH 0x2 /* pattern matched a directory */ 17197318Sphk struct pattern *fow; /* next pattern */ 17297318Sphk} PATTERN; 17397318Sphk 17497318Sphk/* 17597318Sphk * General Archive Structure (used internal to pax) 17697318Sphk * 17797318Sphk * This structure is used to pass information about archive members between 17898987Sphk * the format independent routines and the format specific routines. When 17998987Sphk * new archive formats are added, they must accept requests and supply info 18097318Sphk * encoded in a structure of this type. The name fields are declared statically 18197318Sphk * here, as there is only ONE of these floating around, size is not a major 18297318Sphk * consideration. Eventually converting the name fields to a dynamic length 18397318Sphk * may be required if and when the supporting operating system removes all 18497318Sphk * restrictions on the length of pathnames it will resolve. 18597318Sphk */ 18697318Sphktypedef struct { 187104057Sphk int nlen; /* file name length */ 188104195Sphk char name[PAXPATHLEN+1]; /* file name */ 189104057Sphk int ln_nlen; /* link name length */ 190104057Sphk char ln_name[PAXPATHLEN+1]; /* name to link to (if any) */ 19197318Sphk char *org_name; /* orig name in file system */ 19297318Sphk PATTERN *pat; /* ptr to pattern match (if any) */ 19397318Sphk struct stat sb; /* stat buffer see stat(2) */ 19497318Sphk off_t pad; /* bytes of padding after file xfer */ 19597318Sphk off_t skip; /* bytes of real data after header */ 19697318Sphk /* IMPORTANT. The st_size field does */ 197104057Sphk /* not always indicate the amount of */ 198104195Sphk /* data following the header. */ 199104057Sphk u_long crc; /* file crc */ 200104057Sphk int type; /* type of file node */ 20197318Sphk#define PAX_DIR 1 /* directory */ 20297318Sphk#define PAX_CHR 2 /* character device */ 203111119Simp#define PAX_BLK 3 /* block device */ 20497318Sphk#define PAX_REG 4 /* regular file */ 20597318Sphk#define PAX_SLK 5 /* symbolic link */ 20697318Sphk#define PAX_SCK 6 /* socket */ 20797318Sphk#define PAX_FIF 7 /* fifo */ 20898987Sphk#define PAX_HLK 8 /* hard link */ 20997318Sphk#define PAX_HRG 9 /* hard link to a regular file */ 21098987Sphk#define PAX_CTG 10 /* high performance file */ 21198987Sphk} ARCHD; 21297318Sphk 21397318Sphk/* 21498987Sphk * Format Specific Options List 21597318Sphk * 21698987Sphk * Used to pass format options to the format options handler 21797318Sphk */ 21897318Sphktypedef struct oplist { 21997318Sphk char *name; /* option variable name e.g. name= */ 22097318Sphk char *value; /* value for option variable */ 221104057Sphk struct oplist *fow; /* next option */ 222104195Sphk} OPLIST; 223104057Sphk 224104057Sphk/* 22597318Sphk * General Macros 22697318Sphk */ 22797318Sphk#ifndef MIN 22897318Sphk#define MIN(a,b) (((a)<(b))?(a):(b)) 22997318Sphk#endif 230104195Sphk#define MAJOR(x) (((unsigned)(x) >> 8) & 0xff) 23197318Sphk#define MINOR(x) ((x) & 0xff) 23297318Sphk#define TODEV(x, y) (((unsigned)(x) << 8) | ((unsigned)(y))) 23397318Sphk 23497318Sphk/* 23597318Sphk * General Defines 23697318Sphk */ 23797318Sphk#define HEX 16 23897318Sphk#define OCT 8 23997318Sphk#define _PAX_ 1 24098987Sphk