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