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