pax.h

Go to the documentation of this file.
00001 /*-
00002  * Copyright (c) 1992 Keith Muller.
00003  * Copyright (c) 1992, 1993
00004  *      The Regents of the University of California.  All rights reserved.
00005  *
00006  * This code is derived from software contributed to Berkeley by
00007  * Keith Muller of the University of California, San Diego.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer.
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the
00016  *    documentation and/or other materials provided with the distribution.
00017  * 4. Neither the name of the University nor the names of its contributors
00018  *    may be used to endorse or promote products derived from this software
00019  *    without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  *      @(#)pax.h       8.2 (Berkeley) 4/18/94
00034  * $FreeBSD: src/bin/pax/pax.h,v 1.18 2004/04/06 20:06:48 markm Exp $
00035  */
00036 
00037 
00038 #include <minix/config.h>
00039 #include <minix/const.h>
00040 
00041 /*
00042  * BSD PAX global data structures and constants.
00043  */
00044 
00045 #define MAXBLK          64512   /* MAX blocksize supported (posix SPEC) */
00046                                 /* WARNING: increasing MAXBLK past 32256 */
00047                                 /* will violate posix spec. */
00048 #define MAXBLK_POSIX    32256   /* MAX blocksize supported as per POSIX */
00049 #define BLKMULT         512     /* blocksize must be even mult of 512 bytes */
00050                                 /* Don't even think of changing this */
00051 #define DEVBLK          8192    /* default read blksize for devices */
00052 #define FILEBLK         10240   /* default read blksize for files */
00053 #define PAXPATHLEN      3072    /* maximum path length for pax. MUST be */
00054                                 /* longer than the system PATH_MAX */
00055 
00056 /*
00057  * Pax modes of operation
00058  */
00059 #define LIST            0       /* List the file in an archive */
00060 #define EXTRACT         1       /* extract the files in an archive */
00061 #define ARCHIVE         2       /* write a new archive */
00062 #define APPND           3       /* append to the end of an archive */
00063 #define COPY            4       /* copy files to destination dir */
00064 #define DEFOP           LIST    /* if no flags default is to LIST */
00065 
00066 /*
00067  * Device type of the current archive volume
00068  */
00069 #define ISREG           0       /* regular file */
00070 #define ISCHR           1       /* character device */
00071 #define ISBLK           2       /* block device */
00072 #define ISTAPE          3       /* tape drive */
00073 #define ISPIPE          4       /* pipe/socket */
00074 
00075 typedef struct archd ARCHD;
00076 typedef struct fsub FSUB;
00077 typedef struct oplist OPLIST;
00078 typedef struct pattern PATTERN;
00079 
00080 /*
00081  * Format Specific Routine Table
00082  *
00083  * The format specific routine table allows new archive formats to be quickly
00084  * added. Overall pax operation is independent of the actual format used to
00085  * form the archive. Only those routines which deal directly with the archive
00086  * are tailored to the oddities of the specific format. All other routines are
00087  * independent of the archive format. Data flow in and out of the format
00088  * dependent routines pass pointers to ARCHD structure (described below).
00089  */
00090 struct fsub {
00091         const char *name;       /* name of format, this is the name the user */
00092                                 /* gives to -x option to select it. */
00093         int bsz;                /* default block size. used when the user */
00094                                 /* does not specify a blocksize for writing */
00095                                 /* Appends continue to with the blocksize */
00096                                 /* the archive is currently using. */
00097         int hsz;                /* Header size in bytes. this is the size of */
00098                                 /* the smallest header this format supports. */
00099                                 /* Headers are assumed to fit in a BLKMULT. */
00100                                 /* If they are bigger, get_head() and */
00101                                 /* get_arc() must be adjusted */
00102         int udev;               /* does append require unique dev/ino? some */
00103                                 /* formats use the device and inode fields */
00104                                 /* to specify hard links. when members in */
00105                                 /* the archive have the same inode/dev they */
00106                                 /* are assumed to be hard links. During */
00107                                 /* append we may have to generate unique ids */
00108                                 /* to avoid creating incorrect hard links */
00109         int hlk;                /* does archive store hard links info? if */
00110                                 /* not, we do not bother to look for them */
00111                                 /* during archive write operations */
00112         int blkalgn;            /* writes must be aligned to blkalgn boundary */
00113         int inhead;             /* is the trailer encoded in a valid header? */
00114                                 /* if not, trailers are assumed to be found */
00115                                 /* in invalid headers (i.e like tar) */
00116         int (*id)(char *, int); /* checks if a buffer is a valid header */
00117                                 /* returns 1 if it is, o.w. returns a 0 */
00118         int (*st_rd)(void);     /* initialize routine for read. so format */
00119                                 /* can set up tables etc before it starts */
00120                                 /* reading an archive */
00121         int (*rd)(ARCHD *, char *);
00122                                 /* read header routine. passed a pointer to */
00123                                 /* ARCHD. It must extract the info from the */
00124                                 /* format and store it in the ARCHD struct. */
00125                                 /* This routine is expected to fill all the */
00126                                 /* fields in the ARCHD (including stat buf) */
00127                                 /* 0 is returned when a valid header is */
00128                                 /* found. -1 when not valid. This routine */
00129                                 /* set the skip and pad fields so the format */
00130                                 /* independent routines know the amount of */
00131                                 /* padding and the number of bytes of data */
00132                                 /* which follow the header. This info is */
00133                                 /* used skip to the next file header */
00134         off_t (*end_rd)(void);  /* read cleanup. Allows format to clean up */
00135                                 /* and MUST RETURN THE LENGTH OF THE TRAILER */
00136                                 /* RECORD (so append knows how many bytes */
00137                                 /* to move back to rewrite the trailer) */
00138         int (*st_wr)(void);     /* initialize routine for write operations */
00139         int (*wr)(ARCHD *);     /* write archive header. Passed an ARCHD */
00140                                 /* filled with the specs on the next file to */
00141                                 /* archived. Returns a 1 if no file data is */
00142                                 /* is to be stored; 0 if file data is to be */
00143                                 /* added. A -1 is returned if a write */
00144                                 /* operation to the archive failed. this */
00145                                 /* function sets the skip and pad fields so */
00146                                 /* the proper padding can be added after */
00147                                 /* file data. This routine must NEVER write */
00148                                 /* a flawed archive header. */
00149         int (*end_wr)(void);    /* end write. write the trailer and do any */
00150                                 /* other format specific functions needed */
00151                                 /* at the end of an archive write */
00152         int (*trail_cpio)(ARCHD *);
00153         int (*trail_tar)(char *, int, int *);
00154                                 /* returns 0 if a valid trailer, -1 if not */
00155                                 /* For formats which encode the trailer */
00156                                 /* outside of a valid header, a return value */
00157                                 /* of 1 indicates that the block passed to */
00158                                 /* it can never contain a valid header (skip */
00159                                 /* this block, no point in looking at it)  */
00160         int (*rd_data)(ARCHD *, int, off_t *);
00161                                 /* read/process file data from the archive */
00162         int (*wr_data)(ARCHD *, int, off_t *);
00163                                 /* write/process file data to the archive */
00164         int (*options)(void);   /* process format specific options (-o) */
00165 };
00166 
00167 /*
00168  * Pattern matching structure
00169  *
00170  * Used to store command line patterns
00171  */
00172 struct pattern {
00173         char            *pstr;          /* pattern to match, user supplied */
00174         char            *pend;          /* end of a prefix match */
00175         char            *chdname;       /* the dir to change to if not NULL.  */
00176         int             plen;           /* length of pstr */
00177         int             flgs;           /* processing/state flags */
00178 #define MTCH            0x1             /* pattern has been matched */
00179 #define DIR_MTCH        0x2             /* pattern matched a directory */
00180         struct pattern  *fow;           /* next pattern */
00181 };
00182 
00183 /*
00184  * General Archive Structure (used internal to pax)
00185  *
00186  * This structure is used to pass information about archive members between
00187  * the format independent routines and the format specific routines. When
00188  * new archive formats are added, they must accept requests and supply info
00189  * encoded in a structure of this type. The name fields are declared statically
00190  * here, as there is only ONE of these floating around, size is not a major
00191  * consideration. Eventually converting the name fields to a dynamic length
00192  * may be required if and when the supporting operating system removes all
00193  * restrictions on the length of pathnames it will resolve.
00194  */
00195 struct archd {
00196         int nlen;                       /* file name length */
00197         char name[PAXPATHLEN+1];        /* file name */
00198         int ln_nlen;                    /* link name length */
00199         char ln_name[PAXPATHLEN+1];     /* name to link to (if any) */
00200         char *org_name;                 /* orig name in file system */
00201         PATTERN *pat;                   /* ptr to pattern match (if any) */
00202         struct stat sb;                 /* stat buffer see stat(2) */
00203         off_t pad;                      /* bytes of padding after file xfer */
00204         off_t skip;                     /* bytes of real data after header */
00205                                         /* IMPORTANT. The st_size field does */
00206                                         /* not always indicate the amount of */
00207                                         /* data following the header. */
00208         u_long crc;                     /* file crc */
00209         int type;                       /* type of file node */
00210 #define PAX_DIR         1               /* directory */
00211 #define PAX_CHR         2               /* character device */
00212 #define PAX_BLK         3               /* block device */
00213 #define PAX_REG         4               /* regular file */
00214 #define PAX_SLK         5               /* symbolic link */
00215 #define PAX_SCK         6               /* socket */
00216 #define PAX_FIF         7               /* fifo */
00217 #define PAX_HLK         8               /* hard link */
00218 #define PAX_HRG         9               /* hard link to a regular file */
00219 #define PAX_CTG         10              /* high performance file */
00220 };
00221 
00222 /*
00223  * Format Specific Options List
00224  *
00225  * Used to pass format options to the format options handler
00226  */
00227 struct oplist {
00228         char            *name;          /* option variable name e.g. name= */
00229         char            *value;         /* value for option variable */
00230         struct oplist   *fow;           /* next option */
00231 };
00232 
00233 /*
00234  * General Macros
00235  */
00236 #ifndef MIN
00237 #define        MIN(a,b) (((a)<(b))?(a):(b))
00238 #endif
00239 #define TODEV(x, y)     makedev((x), (y))
00240 
00241 /*
00242  * General Defines
00243  */
00244 #define HEX             16
00245 #define OCT             8
00246 #define _PAX_           1
00247 #define _TFILE_BASE     "paxXXXXXXXXXX"
00248 
00249 #define err(c, str) { perror(str); exit(c); }
00250 #define setpassent(a) setpwent()
00251 #define setgroupent(a) setgrent()

Generated on Fri Apr 14 22:57:01 2006 for minix by  doxygen 1.4.6