xref: /titanic_44/usr/src/cmd/cpio/cpio.h (revision a38ddfee9c8c6b6c5a2947ff52fd2338362a4444)
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 #define	min(a, b)	((a) < (b) ? (a) : (b))
163 
164 /* Values used in typeflag field */
165 #define	REGTYPE		'0'		/* Regular File */
166 #define	LNKTYPE		'1'		/* Link */
167 #define	SYMTYPE		'2'		/* Reserved */
168 #define	CHRTYPE		'3'		/* Character Special File */
169 #define	BLKTYPE		'4'		/* Block Special File */
170 #define	DIRTYPE		'5'		/* Directory */
171 #define	FIFOTYPE	'6'		/* FIFO */
172 #define	CONTTYPE	'7'		/* Reserved */
173 #define	XHDRTYPE	'X'		/* Extended header */
174 
175 #define	INPUT	0	/* -i mode (used for chgreel() */
176 #define	OUTPUT	1	/* -o mode (used for chgreel() */
177 #define	APATH	1024	/* maximum ASC or CRC header path length */
178 #define	CPATH	256	/* maximum -c and binary path length */
179 #define	BUFSZ	512	/* default buffer size for archive I/O */
180 #define	CPIOBSZ	8192	/* buffer size for file system I/O */
181 #define	LNK_INC	500	/* link allocation increment */
182 #define	MX_BUFS	10	/* max. number of buffers to allocate */
183 
184 #define	F_SKIP	0	/* an object did not match the patterns */
185 #define	F_LINK	1	/* linked file */
186 #define	F_EXTR	2	/* extract non-linked object that matched patterns */
187 
188 #define	MX_SEEKS	10	/* max. number of lseek attempts after error */
189 #define	SEEK_ABS	0	/* lseek absolute */
190 #define	SEEK_REL	1	/* lseek relative */
191 
192 /*
193  * xxx_CNT represents the number of sscanf items that will be matched
194  * if the sscanf to read a header is successful.  If sscanf returns a number
195  * that is not equal to this, an error occured (which indicates that this
196  * is not a valid header of the type assumed.
197  */
198 
199 #define	ASC_CNT	14	/* ASC and CRC headers */
200 #define	CHR_CNT	11	/* CHR header */
201 
202 /* These defines determine the severity of the message sent to the user. */
203 
204 #define	ERR	1	/* Error message (warning) - not fatal */
205 #define	EXT	2	/* Error message - fatal, causes exit */
206 #define	ERRN	3	/* Error message with errno (warning) - not fatal */
207 #define	EXTN	4	/* Error message with errno - fatal, causes exit */
208 #define	POST	5	/* Information message, not an error */
209 #define	EPOST	6	/* Information message to stderr */
210 
211 #define	SIXTH	060000	/* UNIX 6th edition files */
212 
213 #define	P_SKIP	0	/* File should be skipped */
214 #define	P_PROC	1	/* File should be processed */
215 
216 #define	U_KEEP	0	/* Keep the existing version of a file (-u) */
217 #define	U_OVER	1	/* Overwrite the existing version of a file (-u) */
218 
219 /*
220  * _20K: Allocate the maximum of (20K or (MX_BUFS * Bufsize)) bytes
221  * for the main I/O buffer.  Therefore if a user specifies a small buffer
222  * size, they still get decent performance due to the buffering strategy.
223  */
224 
225 #define	_20K	20480
226 
227 #define	HALFWD	1	/* Pad headers/data to halfword boundaries */
228 #define	FULLWD	3	/* Pad headers/data to word boundaries */
229 #define	FULLBK	511	/* Pad headers/data to 512 byte boundaries */
230 
231 /* bar structure */
232 union b_block {
233 	char dummy[TBLOCK];
234 	struct bar_header {
235 		char mode[8];
236 		char uid[8];
237 		char gid[8];
238 		char size[12];
239 		char mtime[12];
240 		char chksum[8];
241 		char rdev[8];
242 		char linkflag;
243 
244 		/*
245 		 * The following fields are specific to the volume
246 		 * header.  They are set to zero in all file headers
247 		 * in the archive.
248 		 */
249 		char bar_magic[2];	/* magic number */
250 		char volume_num[4];	/* volume number */
251 		char compressed;	/* files compressed = 1 */
252 		char date[12];		/* date of archive mmddhhmm */
253 		char start_of_name;	/* start of the filename */
254 	} dbuf;
255 };
256 
257 /* svr32 stat structure -- for -Hodc headers */
258 
259 typedef struct cpioinfo {
260 	o_dev_t st_dev;
261 	o_ino_t st_ino;
262 	o_mode_t	st_mode;
263 	o_nlink_t	st_nlink;
264 	uid_t st_uid;		/* actual uid */
265 	gid_t st_gid;		/* actual gid */
266 	o_dev_t st_rdev;
267 	off_t	st_size;
268 	time_t	st_modtime;
269 } cpioinfo_t;
270 
271 void stat_to_svr32_stat(cpioinfo_t *TmpSt, struct stat *FromStat);
272 
273 /*
274  * If compiling on a system that doesn't
275  * support extended attributes, then
276  * define a couple of things so we can compile.
277  */
278 #if !defined(O_XATTR)
279 #define	AT_SYMLINK_NOFOLLOW	0x1000
280 #define	AT_REMOVEDIR		0x0001
281 #define	_XATTR_CPIO_MODE	0xB000
282 #define	_XATTR_HDRTYPE		'E'
283 #endif /* O_XATTR */
284 
285 #ifdef	__cplusplus
286 }
287 #endif
288 
289 #endif /* _CPIO_H */
290