xref: /illumos-gate/usr/src/cmd/cpio/cpio.h (revision 02bc52be7430b2f7fafe1a2c981bff49ef11d6fa)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 #ifndef	_CPIO_H
30 #define	_CPIO_H
31 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /* Option Character keys (OC#), where '#' is the option character specified. */
39 
40 #define	OCa	0x1
41 #define	OCb	0x2
42 #define	OCc	0x4
43 #define	OCd	0x8
44 #define	OCf	0x10
45 #define	OCi	0x20
46 #define	OCk	0x40
47 #define	OCl	0x80
48 #define	OCm	0x100
49 #define	OCo	0x200
50 #define	OCp	0x400
51 #define	OCr	0x800
52 #define	OCs	0x1000
53 #define	OCt	0x2000
54 #define	OCu	0x4000
55 #define	OCv	0x8000
56 #define	OCA	0x10000
57 #define	OCB	0x20000
58 #define	OCC	0x40000
59 #define	OCE	0x80000
60 #define	OCH	0x100000
61 #define	OCI	0x200000
62 #define	OCL	0x400000
63 #define	OCM	0x800000
64 #define	OCO	0x1000000
65 #define	OCR	0x2000000
66 #define	OCS	0x4000000
67 #define	OCV	0x8000000
68 #define	OC6	0x10000000
69 #define	BSM	0x20000000
70 #define	OCP	0x40000000
71 
72 /* Invalid option masks for each action option (-i, -o or -p). */
73 
74 #define	INV_MSK4i	(OCo | OCp | OCA | OCL | OCO)
75 
76 #define	INV_MSK4o	(OCi | OCp | OCE | OCI | OCR)
77 
78 #define	INV_MSK4p	(OCf | OCi | OCo | OCr | OCt | OCA \
79 			| OCE | OCH | OCI | OCO)
80 
81 /* Header types */
82 
83 #define	NONE	0	/* No header value verified */
84 #define	BIN	1	/* Binary */
85 #define	CHR	2	/* ASCII character (-c) */
86 #define	ASC	3	/* ASCII with expanded maj/min numbers */
87 #define	CRC	4	/* CRC with expanded maj/min numbers */
88 #define	TARTYP	5	/* Tar or USTAR */
89 #define	SECURE	6	/* Secure system */
90 
91 /* Differentiate between TAR and USTAR */
92 
93 #define	TAR	7	/* Regular tar */
94 #define	USTAR	8	/* IEEE data interchange standard */
95 
96 /* constants for bar, used for extracting bar archives */
97 #define	BAR	9
98 #define	BAR_VOLUME_MAGIC	'V'
99 #define	BARTYP	7
100 #define	BARSZ	512
101 #define	BAR_TAPE_SIZE	(126*BARSZ)
102 #define	BAR_FLOPPY_SIZE	(18*BARSZ)
103 
104 /* the pathname lengths for the USTAR header */
105 
106 #define	MAXNAM	256	/* The maximum pathname length */
107 #define	NAMSIZ	100	/* The maximum length of the name field */
108 #define	PRESIZ	155	/* The maximum length of the prefix */
109 
110 /* HDRSZ: header size minus filename field length */
111 
112 #define	HDRSZ (Hdr.h_name - (char *)&Hdr)
113 
114 /*
115  * IDENT: Determine if two stat() structures represent identical files.
116  * Assumes that if the device and inode are the same the files are
117  * identical (prevents the archive file from appearing in the archive).
118  */
119 
120 #define	IDENT(a, b) ((a.st_ino == b.st_ino && a.st_dev == b.st_dev) ? 1 : 0)
121 
122 /*
123  * FLUSH: Determine if enough space remains in the buffer to hold
124  * cnt bytes, if not, call bflush() to flush the buffer to the archive.
125  */
126 
127 #define	FLUSH(cnt) if ((Buffr.b_end_p - Buffr.b_in_p) < cnt) bflush()
128 
129 /*
130  * FILL: Determine if enough bytes remain in the buffer to meet current needs,
131  * if not, call rstbuf() to reset and refill the buffer from the archive.
132  */
133 
134 #define	FILL(cnt) while (Buffr.b_cnt < cnt) rstbuf()
135 
136 /*
137  * VERBOSE: If x is non-zero, call verbose().
138  */
139 
140 #define	VERBOSE(x, name) if (x) verbose(name)
141 
142 /*
143  * FORMAT: Date time formats
144  * b - abbreviated month name
145  * e - day of month (1 - 31)
146  * H - hour (00 - 23)
147  * M - minute (00 - 59)
148  * Y - year as ccyy
149  */
150 
151 #define	FORMAT	"%b %e %H:%M %Y"
152 
153 /* Extended system attributes */
154 #ifndef	VIEW_READONLY
155 #define	VIEW_READONLY	"SUNWattr_ro"
156 #endif
157 
158 #ifndef	VIEW_READWRITE
159 #define	VIEW_READWRITE	"SUNWattr_rw"
160 #endif
161 
162 /* Values used in typeflag field */
163 #define	REGTYPE		'0'		/* Regular File */
164 #define	LNKTYPE		'1'		/* Link */
165 #define	SYMTYPE		'2'		/* Reserved */
166 #define	CHRTYPE		'3'		/* Character Special File */
167 #define	BLKTYPE		'4'		/* Block Special File */
168 #define	DIRTYPE		'5'		/* Directory */
169 #define	FIFOTYPE	'6'		/* FIFO */
170 #define	CONTTYPE	'7'		/* Reserved */
171 #define	XHDRTYPE	'X'		/* Extended header */
172 
173 #define	INPUT	0	/* -i mode (used for chgreel() */
174 #define	OUTPUT	1	/* -o mode (used for chgreel() */
175 #define	APATH	1024	/* maximum ASC or CRC header path length */
176 #define	CPATH	256	/* maximum -c and binary path length */
177 #define	BUFSZ	512	/* default buffer size for archive I/O */
178 #define	CPIOBSZ	8192	/* buffer size for file system I/O */
179 #define	LNK_INC	500	/* link allocation increment */
180 #define	MX_BUFS	10	/* max. number of buffers to allocate */
181 
182 #define	F_SKIP	0	/* an object did not match the patterns */
183 #define	F_LINK	1	/* linked file */
184 #define	F_EXTR	2	/* extract non-linked object that matched patterns */
185 
186 #define	MX_SEEKS	10	/* max. number of lseek attempts after error */
187 #define	SEEK_ABS	0	/* lseek absolute */
188 #define	SEEK_REL	1	/* lseek relative */
189 
190 /*
191  * xxx_CNT represents the number of sscanf items that will be matched
192  * if the sscanf to read a header is successful.  If sscanf returns a number
193  * that is not equal to this, an error occured (which indicates that this
194  * is not a valid header of the type assumed.
195  */
196 
197 #define	ASC_CNT	14	/* ASC and CRC headers */
198 #define	CHR_CNT	11	/* CHR header */
199 
200 /* These defines determine the severity of the message sent to the user. */
201 
202 #define	ERR	1	/* Error message (warning) - not fatal */
203 #define	EXT	2	/* Error message - fatal, causes exit */
204 #define	ERRN	3	/* Error message with errno (warning) - not fatal */
205 #define	EXTN	4	/* Error message with errno - fatal, causes exit */
206 #define	POST	5	/* Information message, not an error */
207 #define	EPOST	6	/* Information message to stderr */
208 
209 #define	SIXTH	060000	/* UNIX 6th edition files */
210 
211 #define	P_SKIP	0	/* File should be skipped */
212 #define	P_PROC	1	/* File should be processed */
213 
214 #define	U_KEEP	0	/* Keep the existing version of a file (-u) */
215 #define	U_OVER	1	/* Overwrite the existing version of a file (-u) */
216 
217 /*
218  * _20K: Allocate the maximum of (20K or (MX_BUFS * Bufsize)) bytes
219  * for the main I/O buffer.  Therefore if a user specifies a small buffer
220  * size, they still get decent performance due to the buffering strategy.
221  */
222 
223 #define	_20K	20480
224 
225 #define	HALFWD	1	/* Pad headers/data to halfword boundaries */
226 #define	FULLWD	3	/* Pad headers/data to word boundaries */
227 #define	FULLBK	511	/* Pad headers/data to 512 byte boundaries */
228 
229 /* bar structure */
230 union b_block {
231 	char dummy[TBLOCK];
232 	struct bar_header {
233 		char mode[8];
234 		char uid[8];
235 		char gid[8];
236 		char size[12];
237 		char mtime[12];
238 		char chksum[8];
239 		char rdev[8];
240 		char linkflag;
241 
242 		/*
243 		 * The following fields are specific to the volume
244 		 * header.  They are set to zero in all file headers
245 		 * in the archive.
246 		 */
247 		char bar_magic[2];	/* magic number */
248 		char volume_num[4];	/* volume number */
249 		char compressed;	/* files compressed = 1 */
250 		char date[12];		/* date of archive mmddhhmm */
251 		char start_of_name;	/* start of the filename */
252 	} dbuf;
253 };
254 
255 /* svr32 stat structure -- for -Hodc headers */
256 
257 typedef struct cpioinfo {
258 	o_dev_t st_dev;
259 	o_ino_t st_ino;
260 	o_mode_t	st_mode;
261 	o_nlink_t	st_nlink;
262 	uid_t st_uid;		/* actual uid */
263 	gid_t st_gid;		/* actual gid */
264 	o_dev_t st_rdev;
265 	off_t	st_size;
266 	time_t	st_modtime;
267 } cpioinfo_t;
268 
269 void stat_to_svr32_stat(cpioinfo_t *TmpSt, struct stat *FromStat);
270 
271 /*
272  * If compiling on a system that doesn't
273  * support extended attributes, then
274  * define a couple of things so we can compile.
275  */
276 #if !defined(O_XATTR)
277 #define	AT_SYMLINK_NOFOLLOW	0x1000
278 #define	AT_REMOVEDIR		0x0001
279 #define	_XATTR_CPIO_MODE	0xB000
280 #define	_XATTR_HDRTYPE		'E'
281 #endif /* O_XATTR */
282 
283 #ifdef	__cplusplus
284 }
285 #endif
286 
287 #endif /* _CPIO_H */
288