xref: /titanic_44/usr/src/cmd/cpio/cpio.h (revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*da6c28aaSamw  * Common Development and Distribution License (the "License").
6*da6c28aaSamw  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*da6c28aaSamw  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
26*da6c28aaSamw /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27*da6c28aaSamw /*	  All Rights Reserved  	*/
28*da6c28aaSamw 
297c478bd9Sstevel@tonic-gate #ifndef	_CPIO_H
307c478bd9Sstevel@tonic-gate #define	_CPIO_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
357c478bd9Sstevel@tonic-gate extern "C" {
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /* Option Character keys (OC#), where '#' is the option character specified. */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #define	OCa	0x1
417c478bd9Sstevel@tonic-gate #define	OCb	0x2
427c478bd9Sstevel@tonic-gate #define	OCc	0x4
437c478bd9Sstevel@tonic-gate #define	OCd	0x8
447c478bd9Sstevel@tonic-gate #define	OCf	0x10
457c478bd9Sstevel@tonic-gate #define	OCi	0x20
467c478bd9Sstevel@tonic-gate #define	OCk	0x40
477c478bd9Sstevel@tonic-gate #define	OCl	0x80
487c478bd9Sstevel@tonic-gate #define	OCm	0x100
497c478bd9Sstevel@tonic-gate #define	OCo	0x200
507c478bd9Sstevel@tonic-gate #define	OCp	0x400
517c478bd9Sstevel@tonic-gate #define	OCr	0x800
527c478bd9Sstevel@tonic-gate #define	OCs	0x1000
537c478bd9Sstevel@tonic-gate #define	OCt	0x2000
547c478bd9Sstevel@tonic-gate #define	OCu	0x4000
557c478bd9Sstevel@tonic-gate #define	OCv	0x8000
567c478bd9Sstevel@tonic-gate #define	OCA	0x10000
577c478bd9Sstevel@tonic-gate #define	OCB	0x20000
587c478bd9Sstevel@tonic-gate #define	OCC	0x40000
597c478bd9Sstevel@tonic-gate #define	OCE	0x80000
607c478bd9Sstevel@tonic-gate #define	OCH	0x100000
617c478bd9Sstevel@tonic-gate #define	OCI	0x200000
627c478bd9Sstevel@tonic-gate #define	OCL	0x400000
637c478bd9Sstevel@tonic-gate #define	OCM	0x800000
647c478bd9Sstevel@tonic-gate #define	OCO	0x1000000
657c478bd9Sstevel@tonic-gate #define	OCR	0x2000000
667c478bd9Sstevel@tonic-gate #define	OCS	0x4000000
677c478bd9Sstevel@tonic-gate #define	OCV	0x8000000
687c478bd9Sstevel@tonic-gate #define	OC6	0x10000000
697c478bd9Sstevel@tonic-gate #define	BSM	0x20000000
707c478bd9Sstevel@tonic-gate #define	OCP	0x40000000
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /* Invalid option masks for each action option (-i, -o or -p). */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #define	INV_MSK4i	(OCo | OCp | OCA | OCL | OCO)
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #define	INV_MSK4o	(OCi | OCp | OCE | OCI | OCR)
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #define	INV_MSK4p	(OCf | OCi | OCo | OCr | OCt | OCA \
797c478bd9Sstevel@tonic-gate 			| OCE | OCH | OCI | OCO)
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /* Header types */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #define	NONE	0	/* No header value verified */
847c478bd9Sstevel@tonic-gate #define	BIN	1	/* Binary */
857c478bd9Sstevel@tonic-gate #define	CHR	2	/* ASCII character (-c) */
867c478bd9Sstevel@tonic-gate #define	ASC	3	/* ASCII with expanded maj/min numbers */
877c478bd9Sstevel@tonic-gate #define	CRC	4	/* CRC with expanded maj/min numbers */
887c478bd9Sstevel@tonic-gate #define	TARTYP	5	/* Tar or USTAR */
897c478bd9Sstevel@tonic-gate #define	SECURE	6	/* Secure system */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /* Differentiate between TAR and USTAR */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #define	TAR	7	/* Regular tar */
947c478bd9Sstevel@tonic-gate #define	USTAR	8	/* IEEE data interchange standard */
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /* constants for bar, used for extracting bar archives */
977c478bd9Sstevel@tonic-gate #define	BAR	9
987c478bd9Sstevel@tonic-gate #define	BAR_VOLUME_MAGIC	'V'
997c478bd9Sstevel@tonic-gate #define	BARTYP	7
1007c478bd9Sstevel@tonic-gate #define	BARSZ	512
1017c478bd9Sstevel@tonic-gate #define	BAR_TAPE_SIZE	(126*BARSZ)
1027c478bd9Sstevel@tonic-gate #define	BAR_FLOPPY_SIZE	(18*BARSZ)
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /* the pathname lengths for the USTAR header */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate #define	MAXNAM	256	/* The maximum pathname length */
1077c478bd9Sstevel@tonic-gate #define	NAMSIZ	100	/* The maximum length of the name field */
1087c478bd9Sstevel@tonic-gate #define	PRESIZ	155	/* The maximum length of the prefix */
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /* HDRSZ: header size minus filename field length */
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate #define	HDRSZ (Hdr.h_name - (char *)&Hdr)
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate  * IDENT: Determine if two stat() structures represent identical files.
1167c478bd9Sstevel@tonic-gate  * Assumes that if the device and inode are the same the files are
1177c478bd9Sstevel@tonic-gate  * identical (prevents the archive file from appearing in the archive).
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #define	IDENT(a, b) ((a.st_ino == b.st_ino && a.st_dev == b.st_dev) ? 1 : 0)
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /*
1237c478bd9Sstevel@tonic-gate  * FLUSH: Determine if enough space remains in the buffer to hold
1247c478bd9Sstevel@tonic-gate  * cnt bytes, if not, call bflush() to flush the buffer to the archive.
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #define	FLUSH(cnt) if ((Buffr.b_end_p - Buffr.b_in_p) < cnt) bflush()
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  * FILL: Determine if enough bytes remain in the buffer to meet current needs,
1317c478bd9Sstevel@tonic-gate  * if not, call rstbuf() to reset and refill the buffer from the archive.
1327c478bd9Sstevel@tonic-gate  */
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate #define	FILL(cnt) while (Buffr.b_cnt < cnt) rstbuf()
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * VERBOSE: If x is non-zero, call verbose().
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate #define	VERBOSE(x, name) if (x) verbose(name)
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * FORMAT: Date time formats
1447c478bd9Sstevel@tonic-gate  * b - abbreviated month name
1457c478bd9Sstevel@tonic-gate  * e - day of month (1 - 31)
1467c478bd9Sstevel@tonic-gate  * H - hour (00 - 23)
1477c478bd9Sstevel@tonic-gate  * M - minute (00 - 59)
1487c478bd9Sstevel@tonic-gate  * Y - year as ccyy
1497c478bd9Sstevel@tonic-gate  */
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate #define	FORMAT	"%b %e %H:%M %Y"
1527c478bd9Sstevel@tonic-gate 
153*da6c28aaSamw /* Extended system attributes */
154*da6c28aaSamw #ifndef	VIEW_READONLY
155*da6c28aaSamw #define	VIEW_READONLY	"SUNWattr_ro"
156*da6c28aaSamw #endif
157*da6c28aaSamw 
158*da6c28aaSamw #ifndef	VIEW_READWRITE
159*da6c28aaSamw #define	VIEW_READWRITE	"SUNWattr_rw"
160*da6c28aaSamw #endif
161*da6c28aaSamw 
1627c478bd9Sstevel@tonic-gate /* Values used in typeflag field */
1637c478bd9Sstevel@tonic-gate #define	REGTYPE		'0'		/* Regular File */
1647c478bd9Sstevel@tonic-gate #define	LNKTYPE		'1'		/* Link */
1657c478bd9Sstevel@tonic-gate #define	SYMTYPE		'2'		/* Reserved */
1667c478bd9Sstevel@tonic-gate #define	CHRTYPE		'3'		/* Character Special File */
1677c478bd9Sstevel@tonic-gate #define	BLKTYPE		'4'		/* Block Special File */
1687c478bd9Sstevel@tonic-gate #define	DIRTYPE		'5'		/* Directory */
1697c478bd9Sstevel@tonic-gate #define	FIFOTYPE	'6'		/* FIFO */
1707c478bd9Sstevel@tonic-gate #define	CONTTYPE	'7'		/* Reserved */
1717c478bd9Sstevel@tonic-gate #define	XHDRTYPE	'X'		/* Extended header */
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate #define	INPUT	0	/* -i mode (used for chgreel() */
1747c478bd9Sstevel@tonic-gate #define	OUTPUT	1	/* -o mode (used for chgreel() */
1757c478bd9Sstevel@tonic-gate #define	APATH	1024	/* maximum ASC or CRC header path length */
1767c478bd9Sstevel@tonic-gate #define	CPATH	256	/* maximum -c and binary path length */
1777c478bd9Sstevel@tonic-gate #define	BUFSZ	512	/* default buffer size for archive I/O */
1787c478bd9Sstevel@tonic-gate #define	CPIOBSZ	8192	/* buffer size for file system I/O */
1797c478bd9Sstevel@tonic-gate #define	LNK_INC	500	/* link allocation increment */
1807c478bd9Sstevel@tonic-gate #define	MX_BUFS	10	/* max. number of buffers to allocate */
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate #define	F_SKIP	0	/* an object did not match the patterns */
1837c478bd9Sstevel@tonic-gate #define	F_LINK	1	/* linked file */
1847c478bd9Sstevel@tonic-gate #define	F_EXTR	2	/* extract non-linked object that matched patterns */
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate #define	MX_SEEKS	10	/* max. number of lseek attempts after error */
1877c478bd9Sstevel@tonic-gate #define	SEEK_ABS	0	/* lseek absolute */
1887c478bd9Sstevel@tonic-gate #define	SEEK_REL	1	/* lseek relative */
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate /*
1917c478bd9Sstevel@tonic-gate  * xxx_CNT represents the number of sscanf items that will be matched
1927c478bd9Sstevel@tonic-gate  * if the sscanf to read a header is successful.  If sscanf returns a number
1937c478bd9Sstevel@tonic-gate  * that is not equal to this, an error occured (which indicates that this
1947c478bd9Sstevel@tonic-gate  * is not a valid header of the type assumed.
1957c478bd9Sstevel@tonic-gate  */
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate #define	ASC_CNT	14	/* ASC and CRC headers */
1987c478bd9Sstevel@tonic-gate #define	CHR_CNT	11	/* CHR header */
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /* These defines determine the severity of the message sent to the user. */
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate #define	ERR	1	/* Error message (warning) - not fatal */
2037c478bd9Sstevel@tonic-gate #define	EXT	2	/* Error message - fatal, causes exit */
2047c478bd9Sstevel@tonic-gate #define	ERRN	3	/* Error message with errno (warning) - not fatal */
2057c478bd9Sstevel@tonic-gate #define	EXTN	4	/* Error message with errno - fatal, causes exit */
2067c478bd9Sstevel@tonic-gate #define	POST	5	/* Information message, not an error */
2077c478bd9Sstevel@tonic-gate #define	EPOST	6	/* Information message to stderr */
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate #define	SIXTH	060000	/* UNIX 6th edition files */
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate #define	P_SKIP	0	/* File should be skipped */
2127c478bd9Sstevel@tonic-gate #define	P_PROC	1	/* File should be processed */
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate #define	U_KEEP	0	/* Keep the existing version of a file (-u) */
2157c478bd9Sstevel@tonic-gate #define	U_OVER	1	/* Overwrite the existing version of a file (-u) */
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate /*
2187c478bd9Sstevel@tonic-gate  * _20K: Allocate the maximum of (20K or (MX_BUFS * Bufsize)) bytes
2197c478bd9Sstevel@tonic-gate  * for the main I/O buffer.  Therefore if a user specifies a small buffer
2207c478bd9Sstevel@tonic-gate  * size, they still get decent performance due to the buffering strategy.
2217c478bd9Sstevel@tonic-gate  */
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate #define	_20K	20480
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #define	HALFWD	1	/* Pad headers/data to halfword boundaries */
2267c478bd9Sstevel@tonic-gate #define	FULLWD	3	/* Pad headers/data to word boundaries */
2277c478bd9Sstevel@tonic-gate #define	FULLBK	511	/* Pad headers/data to 512 byte boundaries */
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate /* bar structure */
2307c478bd9Sstevel@tonic-gate union b_block {
2317c478bd9Sstevel@tonic-gate 	char dummy[TBLOCK];
2327c478bd9Sstevel@tonic-gate 	struct bar_header {
2337c478bd9Sstevel@tonic-gate 		char mode[8];
2347c478bd9Sstevel@tonic-gate 		char uid[8];
2357c478bd9Sstevel@tonic-gate 		char gid[8];
2367c478bd9Sstevel@tonic-gate 		char size[12];
2377c478bd9Sstevel@tonic-gate 		char mtime[12];
2387c478bd9Sstevel@tonic-gate 		char chksum[8];
2397c478bd9Sstevel@tonic-gate 		char rdev[8];
2407c478bd9Sstevel@tonic-gate 		char linkflag;
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 		/*
2437c478bd9Sstevel@tonic-gate 		 * The following fields are specific to the volume
2447c478bd9Sstevel@tonic-gate 		 * header.  They are set to zero in all file headers
2457c478bd9Sstevel@tonic-gate 		 * in the archive.
2467c478bd9Sstevel@tonic-gate 		 */
2477c478bd9Sstevel@tonic-gate 		char bar_magic[2];	/* magic number */
2487c478bd9Sstevel@tonic-gate 		char volume_num[4];	/* volume number */
2497c478bd9Sstevel@tonic-gate 		char compressed;	/* files compressed = 1 */
2507c478bd9Sstevel@tonic-gate 		char date[12];		/* date of archive mmddhhmm */
2517c478bd9Sstevel@tonic-gate 		char start_of_name;	/* start of the filename */
2527c478bd9Sstevel@tonic-gate 	} dbuf;
2537c478bd9Sstevel@tonic-gate };
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate /* svr32 stat structure -- for -Hodc headers */
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate typedef struct cpioinfo {
2587c478bd9Sstevel@tonic-gate 	o_dev_t st_dev;
2597c478bd9Sstevel@tonic-gate 	o_ino_t st_ino;
2607c478bd9Sstevel@tonic-gate 	o_mode_t	st_mode;
2617c478bd9Sstevel@tonic-gate 	o_nlink_t	st_nlink;
2627c478bd9Sstevel@tonic-gate 	uid_t st_uid;		/* actual uid */
2637c478bd9Sstevel@tonic-gate 	gid_t st_gid;		/* actual gid */
2647c478bd9Sstevel@tonic-gate 	o_dev_t st_rdev;
2657c478bd9Sstevel@tonic-gate 	off_t	st_size;
2667c478bd9Sstevel@tonic-gate 	time_t	st_modtime;
2677c478bd9Sstevel@tonic-gate } cpioinfo_t;
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate void stat_to_svr32_stat(cpioinfo_t *TmpSt, struct stat *FromStat);
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate /*
2727c478bd9Sstevel@tonic-gate  * If compiling on a system that doesn't
2737c478bd9Sstevel@tonic-gate  * support extended attributes, then
2747c478bd9Sstevel@tonic-gate  * define a couple of things so we can compile.
2757c478bd9Sstevel@tonic-gate  */
2767c478bd9Sstevel@tonic-gate #if !defined(O_XATTR)
2777c478bd9Sstevel@tonic-gate #define	AT_SYMLINK_NOFOLLOW	0x1000
2787c478bd9Sstevel@tonic-gate #define	AT_REMOVEDIR		0x0001
2797c478bd9Sstevel@tonic-gate #define	_XATTR_CPIO_MODE	0xB000
2807c478bd9Sstevel@tonic-gate #define	_XATTR_HDRTYPE		'E'
2817c478bd9Sstevel@tonic-gate #endif /* O_XATTR */
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2847c478bd9Sstevel@tonic-gate }
2857c478bd9Sstevel@tonic-gate #endif
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate #endif /* _CPIO_H */
288