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