pax.h revision 76016
11558Srgrimes/*- 293492Sphk * Copyright (c) 1992 Keith Muller. 393492Sphk * Copyright (c) 1992, 1993 493492Sphk * The Regents of the University of California. All rights reserved. 51558Srgrimes * 693492Sphk * This code is derived from software contributed to Berkeley by 793492Sphk * Keith Muller of the University of California, San Diego. 893492Sphk * 993492Sphk * Redistribution and use in source and binary forms, with or without 1093492Sphk * modification, are permitted provided that the following conditions 111558Srgrimes * are met: 121558Srgrimes * 1. Redistributions of source code must retain the above copyright 131558Srgrimes * notice, this list of conditions and the following disclaimer. 141558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 151558Srgrimes * notice, this list of conditions and the following disclaimer in the 161558Srgrimes * documentation and/or other materials provided with the distribution. 171558Srgrimes * 3. All advertising materials mentioning features or use of this software 181558Srgrimes * must display the following acknowledgement: 1993492Sphk * This product includes software developed by the University of 2093492Sphk * California, Berkeley and its contributors. 2193492Sphk * 4. Neither the name of the University nor the names of its contributors 221558Srgrimes * may be used to endorse or promote products derived from this software 2393492Sphk * without specific prior written permission. 241558Srgrimes * 251558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2693492Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 271558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 281558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 291558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 301558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 311558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 321558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 331558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3493492Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3593492Sphk * SUCH DAMAGE. 361558Srgrimes * 371558Srgrimes * @(#)pax.h 8.2 (Berkeley) 4/18/94 3894580Smarcel * $FreeBSD: head/bin/pax/pax.h 76016 2001-04-26 07:32:27Z kris $ 3994580Smarcel */ 4094580Smarcel 4194580Smarcel/* 4293492Sphk * BSD PAX global data structures and constants. 4394580Smarcel */ 4493492Sphk 4593492Sphk#define MAXBLK 32256 /* MAX blocksize supported (posix SPEC) */ 4694580Smarcel /* WARNING: increasing MAXBLK past 32256 */ 4794580Smarcel /* will violate posix spec. */ 4894580Smarcel#define BLKMULT 512 /* blocksize must be even mult of 512 bytes */ 4994580Smarcel /* Don't even think of changing this */ 5093492Sphk#define DEVBLK 8192 /* default read blksize for devices */ 5193492Sphk#define FILEBLK 10240 /* default read blksize for files */ 521558Srgrimes#define PAXPATHLEN 3072 /* maximum path length for pax. MUST be */ 5394580Smarcel /* longer than the system MAXPATHLEN */ 5494580Smarcel 5594580Smarcel/* 5693492Sphk * Pax modes of operation 5794580Smarcel */ 5893717Smarcel#define LIST 0 /* List the file in an archive */ 591558Srgrimes#define EXTRACT 1 /* extract the files in an archive */ 6093717Smarcel#define ARCHIVE 2 /* write a new archive */ 6193492Sphk#define APPND 3 /* append to the end of an archive */ 621558Srgrimes#define COPY 4 /* copy files to destination dir */ 6394580Smarcel#define DEFOP LIST /* if no flags default is to LIST */ 6493492Sphk 6593717Smarcel/* 6693717Smarcel * Device type of the current archive volume 6793717Smarcel */ 6893717Smarcel#define ISREG 0 /* regular file */ 6993717Smarcel#define ISCHR 1 /* character device */ 7093717Smarcel#define ISBLK 2 /* block device */ 7193717Smarcel#define ISTAPE 3 /* tape drive */ 7293492Sphk#define ISPIPE 4 /* pipe/socket */ 7393492Sphk 7493492Sphk/* 7593492Sphk * Format Specific Routine Table 7693492Sphk * 771558Srgrimes * The format specific routine table allows new archive formats to be quickly 781558Srgrimes * added. Overall pax operation is independent of the actual format used to 7993717Smarcel * form the archive. Only those routines which deal directly with the archive 8093492Sphk * are tailored to the oddities of the specific format. All other routines are 8194580Smarcel * independent of the archive format. Data flow in and out of the format 821558Srgrimes * dependent routines pass pointers to ARCHD structure (described below). 8394580Smarcel */ 8494580Smarceltypedef struct { 8594580Smarcel char *name; /* name of format, this is the name the user */ 8693492Sphk /* gives to -x option to select it. */ 8793492Sphk int bsz; /* default block size. used when the user */ 8893492Sphk /* does not specify a blocksize for writing */ 8994580Smarcel /* Appends continue to with the blocksize */ 9094580Smarcel /* the archive is currently using.*/ 918871Srgrimes int hsz; /* Header size in bytes. this is the size of */ 9294580Smarcel /* the smallest header this format supports. */ 9394580Smarcel /* Headers are assumed to fit in a BLKMULT. */ 9494580Smarcel /* If they are bigger, get_head() and */ 9593492Sphk /* get_arc() must be adjusted */ 9694580Smarcel int udev; /* does append require unique dev/ino? some */ 9793492Sphk /* formats use the device and inode fields */ 9894580Smarcel /* to specify hard links. when members in */ 9993492Sphk /* the archive have the same inode/dev they */ 10047095Sluoqi /* are assumed to be hard links. During */ 10193492Sphk /* append we may have to generate unique ids */ 10293492Sphk /* to avoid creating incorrect hard links */ 10393492Sphk int hlk; /* does archive store hard links info? if */ 10493492Sphk /* not, we do not bother to look for them */ 10594580Smarcel /* during archive write operations */ 10694580Smarcel int blkalgn; /* writes must be aligned to blkalgn boundary */ 1071558Srgrimes int inhead; /* is the trailer encoded in a valid header? */ 10894580Smarcel /* if not, trailers are assumed to be found */ 10994580Smarcel /* in invalid headers (i.e like tar) */ 11094580Smarcel int (*id)(); /* checks if a buffer is a valid header */ 11194580Smarcel /* returns 1 if it is, o.w. returns a 0 */ 11294580Smarcel int (*st_rd)(); /* initialize routine for read. so format */ 11394580Smarcel /* can set up tables etc before it starts */ 11493492Sphk /* reading an archive */ 11593492Sphk int (*rd)(); /* read header routine. passed a pointer to */ 11693492Sphk /* ARCHD. It must extract the info from the */ 11793492Sphk /* format and store it in the ARCHD struct. */ 11894580Smarcel /* This routine is expected to fill all the */ 11994580Smarcel /* fields in the ARCHD (including stat buf) */ 12094580Smarcel /* 0 is returned when a valid header is */ 1211558Srgrimes /* found. -1 when not valid. This routine */ 12293492Sphk /* set the skip and pad fields so the format */ 12394580Smarcel /* independent routines know the amount of */ 12494580Smarcel /* padding and the number of bytes of data */ 12594580Smarcel /* which follow the header. This info is */ 12694580Smarcel /* used skip to the next file header */ 1271558Srgrimes off_t (*end_rd)(); /* read cleanup. Allows format to clean up */ 12893717Smarcel /* and MUST RETURN THE LENGTH OF THE TRAILER */ 12994580Smarcel /* RECORD (so append knows how many bytes */ 13094580Smarcel /* to move back to rewrite the trailer) */ 13194580Smarcel int (*st_wr)(); /* initialize routine for write operations */ 13266429Sdes int (*wr)(); /* write archive header. Passed an ARCHD */ 13394580Smarcel /* filled with the specs on the next file to */ 13494580Smarcel /* archived. Returns a 1 if no file data is */ 13594580Smarcel /* is to be stored; 0 if file data is to be */ 13694580Smarcel /* added. A -1 is returned if a write */ 13794580Smarcel /* operation to the archive failed. this */ 13894580Smarcel /* function sets the skip and pad fields so */ 13994580Smarcel /* the proper padding can be added after */ 14094580Smarcel /* file data. This routine must NEVER write */ 14194580Smarcel /* a flawed archive header. */ 14293717Smarcel int (*end_wr)(); /* end write. write the trailer and do any */ 14393717Smarcel /* other format specific functions needed */ 14493492Sphk /* at the end of a archive write */ 14593492Sphk int (*trail)(); /* returns 0 if a valid trailer, -1 if not */ 14693492Sphk /* For formats which encode the trailer */ 14794580Smarcel /* outside of a valid header, a return value */ 14894580Smarcel /* of 1 indicates that the block passed to */ 14994580Smarcel /* it can never contain a valid header (skip */ 1501558Srgrimes /* this block, no point in looking at it) */ 15193492Sphk /* CAUTION: parameters to this function are */ 15294580Smarcel /* different for trailers inside or outside */ 15394580Smarcel /* of headers. See get_head() for details */ 15466429Sdes int (*rd_data)(); /* read/process file data from the archive */ 15593492Sphk int (*wr_data)(); /* write/process file data to the archive */ 15693492Sphk int (*options)(); /* process format specific options (-o) */ 15794580Smarcel} FSUB; 15894580Smarcel 15994580Smarcel/* 16094580Smarcel * Pattern matching structure 16194580Smarcel * 16294580Smarcel * Used to store command line patterns 16394580Smarcel */ 16494580Smarceltypedef struct pattern { 16594580Smarcel char *pstr; /* pattern to match, user supplied */ 16694580Smarcel char *pend; /* end of a prefix match */ 16794580Smarcel int plen; /* length of pstr */ 16894580Smarcel int flgs; /* processing/state flags */ 16994580Smarcel#define MTCH 0x1 /* pattern has been matched */ 17094580Smarcel#define DIR_MTCH 0x2 /* pattern matched a directory */ 17194580Smarcel struct pattern *fow; /* next pattern */ 1721558Srgrimes} PATTERN; 17394580Smarcel 17494580Smarcel/* 17594580Smarcel * General Archive Structure (used internal to pax) 17694580Smarcel * 17794580Smarcel * This structure is used to pass information about archive members between 17893492Sphk * the format independent routines and the format specific routines. When 17993492Sphk * new archive formats are added, they must accept requests and supply info 18094580Smarcel * encoded in a structure of this type. The name fields are declared statically 1811558Srgrimes * here, as there is only ONE of these floating around, size is not a major 18293492Sphk * consideration. Eventually converting the name fields to a dynamic length 18394580Smarcel * may be required if and when the supporting operating system removes all 18493492Sphk * restrictions on the length of pathnames it will resolve. 18593492Sphk */ 18694580Smarceltypedef struct { 18794580Smarcel int nlen; /* file name length */ 18893492Sphk char name[PAXPATHLEN+1]; /* file name */ 18993492Sphk int ln_nlen; /* link name length */ 19094580Smarcel char ln_name[PAXPATHLEN+1]; /* name to link to (if any) */ 19194580Smarcel char *org_name; /* orig name in file system */ 19294580Smarcel PATTERN *pat; /* ptr to pattern match (if any) */ 19394580Smarcel struct stat sb; /* stat buffer see stat(2) */ 19494580Smarcel off_t pad; /* bytes of padding after file xfer */ 19594580Smarcel off_t skip; /* bytes of real data after header */ 19694580Smarcel /* IMPORTANT. The st_size field does */ 19794580Smarcel /* not always indicate the amount of */ 19894580Smarcel /* data following the header. */ 19993492Sphk u_long crc; /* file crc */ 20093492Sphk int type; /* type of file node */ 20193492Sphk#define PAX_DIR 1 /* directory */ 20293492Sphk#define PAX_CHR 2 /* character device */ 20393492Sphk#define PAX_BLK 3 /* block device */ 20493492Sphk#define PAX_REG 4 /* regular file */ 20594580Smarcel#define PAX_SLK 5 /* symbolic link */ 20694580Smarcel#define PAX_SCK 6 /* socket */ 20767264Sdes#define PAX_FIF 7 /* fifo */ 20893492Sphk#define PAX_HLK 8 /* hard link */ 20993492Sphk#define PAX_HRG 9 /* hard link to a regular file */ 21094580Smarcel#define PAX_CTG 10 /* high performance file */ 21194580Smarcel} ARCHD; 21293492Sphk 21393492Sphk/* 21467264Sdes * Format Specific Options List 21594580Smarcel * 21694580Smarcel * Used to pass format options to the format options handler 21794580Smarcel */ 21894580Smarceltypedef struct oplist { 21994580Smarcel char *name; /* option variable name e.g. name= */ 22094580Smarcel char *value; /* value for option variable */ 22194580Smarcel struct oplist *fow; /* next option */ 22294580Smarcel} OPLIST; 22394580Smarcel 22494580Smarcel/* 22594580Smarcel * General Macros 22694580Smarcel */ 22794580Smarcel#ifndef MIN 22894580Smarcel#define MIN(a,b) (((a)<(b))?(a):(b)) 22994580Smarcel#endif 23094580Smarcel#define MAJOR(x) major(x) 23194580Smarcel#define MINOR(x) minor(x) 23294580Smarcel#define TODEV(x, y) makedev((x), (y)) 23394580Smarcel 23494580Smarcel/* 23594580Smarcel * General Defines 23694580Smarcel */ 23794580Smarcel#define HEX 16 23894580Smarcel#define OCT 8 23994580Smarcel#define _PAX_ 1 2401558Srgrimes#define _TFILE_BASE "paxXXXXXXXXXX" 2411558Srgrimes