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