xref: /illumos-gate/usr/src/head/archives.h (revision b4203d75)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright (c) 1988,1997-1998,2001 by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate  * All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*b4203d75SMarcel Telka /*	  All Rights Reserved	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifndef	_ARCHIVES_H
327c478bd9Sstevel@tonic-gate #define	_ARCHIVES_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <tar.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /* Magic numbers */
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #define	CMN_ASC	0x070701	/* Cpio Magic Number for ASCii header */
437c478bd9Sstevel@tonic-gate #define	CMN_BIN	070707		/* Cpio Magic Number for Binary header */
447c478bd9Sstevel@tonic-gate #define	CMN_BBS	0143561		/* Cpio Magic Number for Byte-Swap header */
457c478bd9Sstevel@tonic-gate #define	CMN_CRC	0x070702	/* Cpio Magic Number for CRC header */
467c478bd9Sstevel@tonic-gate #define	CMS_ASC	"070701"	/* Cpio Magic String for ASCii header */
477c478bd9Sstevel@tonic-gate #define	CMS_CHR	"070707"	/* Cpio Magic String for CHR (-c) header */
487c478bd9Sstevel@tonic-gate #define	CMS_CRC	"070702"	/* Cpio Magic String for CRC header */
497c478bd9Sstevel@tonic-gate #define	CMS_LEN	6		/* Cpio Magic String LENgth */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /* Various header and field lengths */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #define	CHRSZ	76		/* -c hdr size minus filename field */
547c478bd9Sstevel@tonic-gate #define	ASCSZ	110		/* ASC and CRC hdr size minus filename field */
557c478bd9Sstevel@tonic-gate #define	TARSZ	512		/* TAR hdr size */
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #define	HNAMLEN	256	/* maximum filename length for binary and -c headers */
587c478bd9Sstevel@tonic-gate #define	EXPNLEN	1024	/* maximum filename length for ASC and CRC headers */
597c478bd9Sstevel@tonic-gate #define	HTIMLEN	2	/* length of modification time field */
607c478bd9Sstevel@tonic-gate #define	HSIZLEN	2	/* length of file size field */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /* cpio binary header definition */
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate struct hdr_cpio {
657c478bd9Sstevel@tonic-gate 	short	h_magic,		/* magic number field */
667c478bd9Sstevel@tonic-gate 		h_dev;			/* file system of file */
677c478bd9Sstevel@tonic-gate 	ushort_t h_ino,			/* inode of file */
687c478bd9Sstevel@tonic-gate 		h_mode,			/* modes of file */
697c478bd9Sstevel@tonic-gate 		h_uid,			/* uid of file */
707c478bd9Sstevel@tonic-gate 		h_gid;			/* gid of file */
717c478bd9Sstevel@tonic-gate 	short	h_nlink,		/* number of links to file */
727c478bd9Sstevel@tonic-gate 		h_rdev,			/* maj/min numbers for special files */
737c478bd9Sstevel@tonic-gate 		h_mtime[HTIMLEN],	/* modification time of file */
747c478bd9Sstevel@tonic-gate 		h_namesize,		/* length of filename */
757c478bd9Sstevel@tonic-gate 		h_filesize[HSIZLEN];	/* size of file */
767c478bd9Sstevel@tonic-gate 	char	h_name[HNAMLEN];	/* filename */
777c478bd9Sstevel@tonic-gate };
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /* cpio ODC header format */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate struct c_hdr {
827c478bd9Sstevel@tonic-gate 	char	c_magic[CMS_LEN],
837c478bd9Sstevel@tonic-gate 		c_dev[6],
847c478bd9Sstevel@tonic-gate 		c_ino[6],
857c478bd9Sstevel@tonic-gate 		c_mode[6],
867c478bd9Sstevel@tonic-gate 		c_uid[6],
877c478bd9Sstevel@tonic-gate 		c_gid[6],
887c478bd9Sstevel@tonic-gate 		c_nlink[6],
897c478bd9Sstevel@tonic-gate 		c_rdev[6],
907c478bd9Sstevel@tonic-gate 		c_mtime[11],
917c478bd9Sstevel@tonic-gate 		c_namesz[6],
927c478bd9Sstevel@tonic-gate 		c_filesz[11],
937c478bd9Sstevel@tonic-gate 		c_name[HNAMLEN];
947c478bd9Sstevel@tonic-gate };
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /* -c and CRC header format */
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate struct Exp_cpio_hdr {
997c478bd9Sstevel@tonic-gate 	char	E_magic[CMS_LEN],
1007c478bd9Sstevel@tonic-gate 		E_ino[8],
1017c478bd9Sstevel@tonic-gate 		E_mode[8],
1027c478bd9Sstevel@tonic-gate 		E_uid[8],
1037c478bd9Sstevel@tonic-gate 		E_gid[8],
1047c478bd9Sstevel@tonic-gate 		E_nlink[8],
1057c478bd9Sstevel@tonic-gate 		E_mtime[8],
1067c478bd9Sstevel@tonic-gate 		E_filesize[8],
1077c478bd9Sstevel@tonic-gate 		E_maj[8],
1087c478bd9Sstevel@tonic-gate 		E_min[8],
1097c478bd9Sstevel@tonic-gate 		E_rmaj[8],
1107c478bd9Sstevel@tonic-gate 		E_rmin[8],
1117c478bd9Sstevel@tonic-gate 		E_namesize[8],
1127c478bd9Sstevel@tonic-gate 		E_chksum[8],
1137c478bd9Sstevel@tonic-gate 		E_name[EXPNLEN];
1147c478bd9Sstevel@tonic-gate };
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /* Tar header structure and format */
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate #define	TBLOCK	512	/* length of tar header and data blocks */
1197c478bd9Sstevel@tonic-gate #define	TNAMLEN	100	/* maximum length for tar file names */
1207c478bd9Sstevel@tonic-gate #define	TMODLEN	8	/* length of mode field */
1217c478bd9Sstevel@tonic-gate #define	TUIDLEN	8	/* length of uid field */
1227c478bd9Sstevel@tonic-gate #define	TGIDLEN	8	/* length of gid field */
1237c478bd9Sstevel@tonic-gate #define	TSIZLEN	12	/* length of size field */
1247c478bd9Sstevel@tonic-gate #define	TTIMLEN	12	/* length of modification time field */
1257c478bd9Sstevel@tonic-gate #define	TCRCLEN	8	/* length of header checksum field */
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /* tar header definition */
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate union tblock {
1307c478bd9Sstevel@tonic-gate 	char dummy[TBLOCK];
1317c478bd9Sstevel@tonic-gate 	struct tar_hdr {
1327c478bd9Sstevel@tonic-gate 		char	t_name[TNAMLEN],	/* name of file */
1337c478bd9Sstevel@tonic-gate 			t_mode[TMODLEN],	/* mode of file */
1347c478bd9Sstevel@tonic-gate 			t_uid[TUIDLEN],		/* uid of file */
1357c478bd9Sstevel@tonic-gate 			t_gid[TGIDLEN],		/* gid of file */
1367c478bd9Sstevel@tonic-gate 			t_size[TSIZLEN],	/* size of file in bytes */
1377c478bd9Sstevel@tonic-gate 			t_mtime[TTIMLEN],	/* modification time of file */
1387c478bd9Sstevel@tonic-gate 			t_cksum[TCRCLEN],	/* checksum of header */
1397c478bd9Sstevel@tonic-gate 			t_typeflag,
1407c478bd9Sstevel@tonic-gate 			t_linkname[TNAMLEN],	/* file this file linked with */
1417c478bd9Sstevel@tonic-gate 			t_magic[TMAGLEN],
1427c478bd9Sstevel@tonic-gate 			t_version[TVERSLEN],
1437c478bd9Sstevel@tonic-gate 			t_uname[32],
1447c478bd9Sstevel@tonic-gate 			t_gname[32],
1457c478bd9Sstevel@tonic-gate 			t_devmajor[8],
1467c478bd9Sstevel@tonic-gate 			t_devminor[8],
1477c478bd9Sstevel@tonic-gate 			t_prefix[155];
1487c478bd9Sstevel@tonic-gate 	} tbuf;
1497c478bd9Sstevel@tonic-gate };
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /* volcopy tape label format and structure */
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate #define	VMAGLEN 8
1547c478bd9Sstevel@tonic-gate #define	VVOLLEN 6
1557c478bd9Sstevel@tonic-gate #define	VFILLEN 464
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate struct volcopy_label {
1587c478bd9Sstevel@tonic-gate 	char	v_magic[VMAGLEN],
1597c478bd9Sstevel@tonic-gate 		v_volume[VVOLLEN],
1607c478bd9Sstevel@tonic-gate 		v_reels,
1617c478bd9Sstevel@tonic-gate 		v_reel;
1627c478bd9Sstevel@tonic-gate 	int	v_time,
1637c478bd9Sstevel@tonic-gate 		v_length,
1647c478bd9Sstevel@tonic-gate 		v_dens,
1657c478bd9Sstevel@tonic-gate 		v_reelblks,	/* u370 added field */
1667c478bd9Sstevel@tonic-gate 		v_blksize,	/* u370 added field */
1677c478bd9Sstevel@tonic-gate 		v_nblocks;	/* u370 added field */
1687c478bd9Sstevel@tonic-gate 	char	v_fill[VFILLEN];
1697c478bd9Sstevel@tonic-gate 	int	v_offset;	/* used with -e and -reel options */
1707c478bd9Sstevel@tonic-gate 	int	v_type;		/* does tape have nblocks field? */
1717c478bd9Sstevel@tonic-gate };
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate /*
1747c478bd9Sstevel@tonic-gate  * Define archive formats for extended attributes.
1757c478bd9Sstevel@tonic-gate  *
1767c478bd9Sstevel@tonic-gate  * Extended attributes are stored in two pieces.
1777c478bd9Sstevel@tonic-gate  * 1. An attribute header which has information about
1787c478bd9Sstevel@tonic-gate  *    what file the attribute is for and what the attribute
1797c478bd9Sstevel@tonic-gate  *    is named.
1807c478bd9Sstevel@tonic-gate  * 2. The attribute record itself.  Stored as a normal file type
1817c478bd9Sstevel@tonic-gate  *    of entry.
1827c478bd9Sstevel@tonic-gate  * Both the header and attribute record have special modes/typeflags
1837c478bd9Sstevel@tonic-gate  * associated with them.
1847c478bd9Sstevel@tonic-gate  *
1857c478bd9Sstevel@tonic-gate  * The names of the header in the archive look like:
1867c478bd9Sstevel@tonic-gate  * /dev/null/attr.hdr
1877c478bd9Sstevel@tonic-gate  *
1887c478bd9Sstevel@tonic-gate  * The name of the attribute looks like:
1897c478bd9Sstevel@tonic-gate  * /dev/null/attr.
1907c478bd9Sstevel@tonic-gate  *
1917c478bd9Sstevel@tonic-gate  * This is done so that an archiver that doesn't understand these formats
1927c478bd9Sstevel@tonic-gate  * can just dispose of the attribute records unless the user chooses to
1937c478bd9Sstevel@tonic-gate  * rename them via cpio -r or pax -i
1947c478bd9Sstevel@tonic-gate  *
1957c478bd9Sstevel@tonic-gate  * The format is composed of a fixed size header followed
1967c478bd9Sstevel@tonic-gate  * by a variable sized xattr_buf. If the attribute is a hard link
1977c478bd9Sstevel@tonic-gate  * to another attribute, then another xattr_buf section is included
1987c478bd9Sstevel@tonic-gate  * for the link.
1997c478bd9Sstevel@tonic-gate  *
2007c478bd9Sstevel@tonic-gate  * The xattr_buf is used to define the necessary "pathing" steps
2017c478bd9Sstevel@tonic-gate  * to get to the extended attribute.  This is necessary to support
2027c478bd9Sstevel@tonic-gate  * a fully recursive attribute model where an attribute may itself
2037c478bd9Sstevel@tonic-gate  * have an attribute.
2047c478bd9Sstevel@tonic-gate  *
2057c478bd9Sstevel@tonic-gate  * The basic layout looks like this.
2067c478bd9Sstevel@tonic-gate  *
2077c478bd9Sstevel@tonic-gate  *     --------------------------------
2087c478bd9Sstevel@tonic-gate  *     |                              |
2097c478bd9Sstevel@tonic-gate  *     |         xattr_hdr            |
2107c478bd9Sstevel@tonic-gate  *     |                              |
2117c478bd9Sstevel@tonic-gate  *     --------------------------------
2127c478bd9Sstevel@tonic-gate  *     --------------------------------
2137c478bd9Sstevel@tonic-gate  *     |                              |
2147c478bd9Sstevel@tonic-gate  *     |        xattr_buf             |
2157c478bd9Sstevel@tonic-gate  *     |                              |
2167c478bd9Sstevel@tonic-gate  *     --------------------------------
2177c478bd9Sstevel@tonic-gate  *     --------------------------------
2187c478bd9Sstevel@tonic-gate  *     |                              |
2197c478bd9Sstevel@tonic-gate  *     |      (optional link info)    |
2207c478bd9Sstevel@tonic-gate  *     |                              |
2217c478bd9Sstevel@tonic-gate  *     --------------------------------
2227c478bd9Sstevel@tonic-gate  *     --------------------------------
2237c478bd9Sstevel@tonic-gate  *     |                              |
2247c478bd9Sstevel@tonic-gate  *     |      attribute itself        |
2257c478bd9Sstevel@tonic-gate  *     |      stored as normal tar    |
2267c478bd9Sstevel@tonic-gate  *     |      or cpio data with       |
2277c478bd9Sstevel@tonic-gate  *     |      special mode or         |
2287c478bd9Sstevel@tonic-gate  *     |      typeflag                |
2297c478bd9Sstevel@tonic-gate  *     |                              |
2307c478bd9Sstevel@tonic-gate  *     --------------------------------
2317c478bd9Sstevel@tonic-gate  *
2327c478bd9Sstevel@tonic-gate  */
2337c478bd9Sstevel@tonic-gate #define	XATTR_ARCH_VERS	"1.0"
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate  * extended attribute fixed header
2377c478bd9Sstevel@tonic-gate  *
2387c478bd9Sstevel@tonic-gate  * h_version		format version.
2397c478bd9Sstevel@tonic-gate  * h_size               size of header + variable sized data sections.
2407c478bd9Sstevel@tonic-gate  * h_component_len      Length of entire pathing section.
2417c478bd9Sstevel@tonic-gate  * h_link_component_len Length of link component section.  Again same definition
2427c478bd9Sstevel@tonic-gate  *                      as h_component_len.
2437c478bd9Sstevel@tonic-gate  */
2447c478bd9Sstevel@tonic-gate struct xattr_hdr {
2457c478bd9Sstevel@tonic-gate 	char	h_version[7];
2467c478bd9Sstevel@tonic-gate 	char	h_size[10];
2477c478bd9Sstevel@tonic-gate 	char	h_component_len[10];	   /* total length of path component */
2487c478bd9Sstevel@tonic-gate 	char	h_link_component_len[10];
2497c478bd9Sstevel@tonic-gate };
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate /*
2527c478bd9Sstevel@tonic-gate  * The name is encoded like this:
2537c478bd9Sstevel@tonic-gate  * filepathNULattrpathNUL[attrpathNULL]...
2547c478bd9Sstevel@tonic-gate  */
2557c478bd9Sstevel@tonic-gate struct xattr_buf {
2567c478bd9Sstevel@tonic-gate 	char	h_namesz[7];   /* length of h_names */
2577c478bd9Sstevel@tonic-gate 	char	h_typeflag;    /* actual typeflag of file being archived */
2587c478bd9Sstevel@tonic-gate 	char	h_names[1];	/* filepathNULattrpathNUL... */
2597c478bd9Sstevel@tonic-gate };
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate /*
2627c478bd9Sstevel@tonic-gate  * Special values for tar archives
2637c478bd9Sstevel@tonic-gate  */
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate /*
2667c478bd9Sstevel@tonic-gate  * typeflag for tar archives.
2677c478bd9Sstevel@tonic-gate  */
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate /*
2707c478bd9Sstevel@tonic-gate  * Attribute hdr and attribute files have the following typeflag
2717c478bd9Sstevel@tonic-gate  */
2727c478bd9Sstevel@tonic-gate #define	_XATTR_HDRTYPE		'E'
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate /*
2757c478bd9Sstevel@tonic-gate  * For cpio archives the header and attribute have
2767c478bd9Sstevel@tonic-gate  * _XATTR_CPIO_MODE ORED into the mode field in both
2777c478bd9Sstevel@tonic-gate  * character and binary versions of the archive format
2787c478bd9Sstevel@tonic-gate  */
2797c478bd9Sstevel@tonic-gate #define	_XATTR_CPIO_MODE	0xB000
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate #endif
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate #endif	/* _ARCHIVES_H */
286