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