/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1992 Keith Muller.4* Copyright (c) 1992, 19935* The Regents of the University of California. All rights reserved.6*7* This code is derived from software contributed to Berkeley by8* Keith Muller of the University of California, San Diego.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18* 3. Neither the name of the University nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435/*36* BSD PAX global data structures and constants.37*/3839#define MAXBLK 64512 /* MAX blocksize supported (posix SPEC) */40/* WARNING: increasing MAXBLK past 32256 */41/* will violate posix spec. */42#define MAXBLK_POSIX 32256 /* MAX blocksize supported as per POSIX */43#define BLKMULT 512 /* blocksize must be even mult of 512 bytes */44/* Don't even think of changing this */45#define DEVBLK 8192 /* default read blksize for devices */46#define FILEBLK 10240 /* default read blksize for files */47#define PAXPATHLEN 3072 /* maximum path length for pax. MUST be */48/* longer than the system PATH_MAX */4950/*51* Pax modes of operation52*/53#define LIST 0 /* List the file in an archive */54#define EXTRACT 1 /* extract the files in an archive */55#define ARCHIVE 2 /* write a new archive */56#define APPND 3 /* append to the end of an archive */57#define COPY 4 /* copy files to destination dir */58#define DEFOP LIST /* if no flags default is to LIST */5960/*61* Device type of the current archive volume62*/63#define ISREG 0 /* regular file */64#define ISCHR 1 /* character device */65#define ISBLK 2 /* block device */66#define ISTAPE 3 /* tape drive */67#define ISPIPE 4 /* pipe/socket */6869typedef struct archd ARCHD;70typedef struct fsub FSUB;71typedef struct oplist OPLIST;72typedef struct pattern PATTERN;7374/*75* Format Specific Routine Table76*77* The format specific routine table allows new archive formats to be quickly78* added. Overall pax operation is independent of the actual format used to79* form the archive. Only those routines which deal directly with the archive80* are tailored to the oddities of the specific format. All other routines are81* independent of the archive format. Data flow in and out of the format82* dependent routines pass pointers to ARCHD structure (described below).83*/84struct fsub {85const char *name; /* name of format, this is the name the user */86/* gives to -x option to select it. */87int bsz; /* default block size. used when the user */88/* does not specify a blocksize for writing */89/* Appends continue to with the blocksize */90/* the archive is currently using. */91int hsz; /* Header size in bytes. this is the size of */92/* the smallest header this format supports. */93/* Headers are assumed to fit in a BLKMULT. */94/* If they are bigger, get_head() and */95/* get_arc() must be adjusted */96int udev; /* does append require unique dev/ino? some */97/* formats use the device and inode fields */98/* to specify hard links. when members in */99/* the archive have the same inode/dev they */100/* are assumed to be hard links. During */101/* append we may have to generate unique ids */102/* to avoid creating incorrect hard links */103int hlk; /* does archive store hard links info? if */104/* not, we do not bother to look for them */105/* during archive write operations */106int blkalgn; /* writes must be aligned to blkalgn boundary */107int inhead; /* is the trailer encoded in a valid header? */108/* if not, trailers are assumed to be found */109/* in invalid headers (i.e like tar) */110int (*id)(char *, int); /* checks if a buffer is a valid header */111/* returns 1 if it is, o.w. returns a 0 */112int (*st_rd)(void); /* initialize routine for read. so format */113/* can set up tables etc before it starts */114/* reading an archive */115int (*rd)(ARCHD *, char *);116/* read header routine. passed a pointer to */117/* ARCHD. It must extract the info from the */118/* format and store it in the ARCHD struct. */119/* This routine is expected to fill all the */120/* fields in the ARCHD (including stat buf) */121/* 0 is returned when a valid header is */122/* found. -1 when not valid. This routine */123/* set the skip and pad fields so the format */124/* independent routines know the amount of */125/* padding and the number of bytes of data */126/* which follow the header. This info is */127/* used skip to the next file header */128off_t (*end_rd)(void); /* read cleanup. Allows format to clean up */129/* and MUST RETURN THE LENGTH OF THE TRAILER */130/* RECORD (so append knows how many bytes */131/* to move back to rewrite the trailer) */132int (*st_wr)(void); /* initialize routine for write operations */133int (*wr)(ARCHD *); /* write archive header. Passed an ARCHD */134/* filled with the specs on the next file to */135/* archived. Returns a 1 if no file data is */136/* is to be stored; 0 if file data is to be */137/* added. A -1 is returned if a write */138/* operation to the archive failed. this */139/* function sets the skip and pad fields so */140/* the proper padding can be added after */141/* file data. This routine must NEVER write */142/* a flawed archive header. */143int (*end_wr)(void); /* end write. write the trailer and do any */144/* other format specific functions needed */145/* at the end of an archive write */146int (*trail_cpio)(ARCHD *);147int (*trail_tar)(char *, int, int *);148/* returns 0 if a valid trailer, -1 if not */149/* For formats which encode the trailer */150/* outside of a valid header, a return value */151/* of 1 indicates that the block passed to */152/* it can never contain a valid header (skip */153/* this block, no point in looking at it) */154int (*rd_data)(ARCHD *, int, off_t *);155/* read/process file data from the archive */156int (*wr_data)(ARCHD *, int, off_t *);157/* write/process file data to the archive */158int (*options)(void); /* process format specific options (-o) */159};160161/*162* Pattern matching structure163*164* Used to store command line patterns165*/166struct pattern {167char *pstr; /* pattern to match, user supplied */168char *pend; /* end of a prefix match */169char *chdname; /* the dir to change to if not NULL. */170int plen; /* length of pstr */171int flgs; /* processing/state flags */172#define MTCH 0x1 /* pattern has been matched */173#define DIR_MTCH 0x2 /* pattern matched a directory */174struct pattern *fow; /* next pattern */175};176177/*178* General Archive Structure (used internal to pax)179*180* This structure is used to pass information about archive members between181* the format independent routines and the format specific routines. When182* new archive formats are added, they must accept requests and supply info183* encoded in a structure of this type. The name fields are declared statically184* here, as there is only ONE of these floating around, size is not a major185* consideration. Eventually converting the name fields to a dynamic length186* may be required if and when the supporting operating system removes all187* restrictions on the length of pathnames it will resolve.188*/189struct archd {190int nlen; /* file name length */191char name[PAXPATHLEN+1]; /* file name */192int ln_nlen; /* link name length */193char ln_name[PAXPATHLEN+1]; /* name to link to (if any) */194char *org_name; /* orig name in file system */195PATTERN *pat; /* ptr to pattern match (if any) */196struct stat sb; /* stat buffer see stat(2) */197off_t pad; /* bytes of padding after file xfer */198off_t skip; /* bytes of real data after header */199/* IMPORTANT. The st_size field does */200/* not always indicate the amount of */201/* data following the header. */202u_long crc; /* file crc */203int type; /* type of file node */204#define PAX_DIR 1 /* directory */205#define PAX_CHR 2 /* character device */206#define PAX_BLK 3 /* block device */207#define PAX_REG 4 /* regular file */208#define PAX_SLK 5 /* symbolic link */209#define PAX_SCK 6 /* socket */210#define PAX_FIF 7 /* fifo */211#define PAX_HLK 8 /* hard link */212#define PAX_HRG 9 /* hard link to a regular file */213#define PAX_CTG 10 /* high performance file */214};215216/*217* Format Specific Options List218*219* Used to pass format options to the format options handler220*/221struct oplist {222char *name; /* option variable name e.g. name= */223char *value; /* value for option variable */224struct oplist *fow; /* next option */225};226227/*228* General Macros229*/230#ifndef MIN231#define MIN(a,b) (((a)<(b))?(a):(b))232#endif233#define MAJOR(x) major(x)234#define MINOR(x) minor(x)235#define TODEV(x, y) makedev((x), (y))236237/*238* General Defines239*/240#define HEX 16241#define OCT 8242#define _PAX_ 1243#define _TFILE_BASE "paxXXXXXXXXXX"244245246