Debian Codegraph @

pax.h

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