xref: /illumos-gate/usr/src/head/archives.h (revision b4203d75)
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 /*
23  * Copyright (c) 1988,1997-1998,2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 
31 #ifndef	_ARCHIVES_H
32 #define	_ARCHIVES_H
33 
34 #include <tar.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /* Magic numbers */
41 
42 #define	CMN_ASC	0x070701	/* Cpio Magic Number for ASCii header */
43 #define	CMN_BIN	070707		/* Cpio Magic Number for Binary header */
44 #define	CMN_BBS	0143561		/* Cpio Magic Number for Byte-Swap header */
45 #define	CMN_CRC	0x070702	/* Cpio Magic Number for CRC header */
46 #define	CMS_ASC	"070701"	/* Cpio Magic String for ASCii header */
47 #define	CMS_CHR	"070707"	/* Cpio Magic String for CHR (-c) header */
48 #define	CMS_CRC	"070702"	/* Cpio Magic String for CRC header */
49 #define	CMS_LEN	6		/* Cpio Magic String LENgth */
50 
51 /* Various header and field lengths */
52 
53 #define	CHRSZ	76		/* -c hdr size minus filename field */
54 #define	ASCSZ	110		/* ASC and CRC hdr size minus filename field */
55 #define	TARSZ	512		/* TAR hdr size */
56 
57 #define	HNAMLEN	256	/* maximum filename length for binary and -c headers */
58 #define	EXPNLEN	1024	/* maximum filename length for ASC and CRC headers */
59 #define	HTIMLEN	2	/* length of modification time field */
60 #define	HSIZLEN	2	/* length of file size field */
61 
62 /* cpio binary header definition */
63 
64 struct hdr_cpio {
65 	short	h_magic,		/* magic number field */
66 		h_dev;			/* file system of file */
67 	ushort_t h_ino,			/* inode of file */
68 		h_mode,			/* modes of file */
69 		h_uid,			/* uid of file */
70 		h_gid;			/* gid of file */
71 	short	h_nlink,		/* number of links to file */
72 		h_rdev,			/* maj/min numbers for special files */
73 		h_mtime[HTIMLEN],	/* modification time of file */
74 		h_namesize,		/* length of filename */
75 		h_filesize[HSIZLEN];	/* size of file */
76 	char	h_name[HNAMLEN];	/* filename */
77 };
78 
79 /* cpio ODC header format */
80 
81 struct c_hdr {
82 	char	c_magic[CMS_LEN],
83 		c_dev[6],
84 		c_ino[6],
85 		c_mode[6],
86 		c_uid[6],
87 		c_gid[6],
88 		c_nlink[6],
89 		c_rdev[6],
90 		c_mtime[11],
91 		c_namesz[6],
92 		c_filesz[11],
93 		c_name[HNAMLEN];
94 };
95 
96 /* -c and CRC header format */
97 
98 struct Exp_cpio_hdr {
99 	char	E_magic[CMS_LEN],
100 		E_ino[8],
101 		E_mode[8],
102 		E_uid[8],
103 		E_gid[8],
104 		E_nlink[8],
105 		E_mtime[8],
106 		E_filesize[8],
107 		E_maj[8],
108 		E_min[8],
109 		E_rmaj[8],
110 		E_rmin[8],
111 		E_namesize[8],
112 		E_chksum[8],
113 		E_name[EXPNLEN];
114 };
115 
116 /* Tar header structure and format */
117 
118 #define	TBLOCK	512	/* length of tar header and data blocks */
119 #define	TNAMLEN	100	/* maximum length for tar file names */
120 #define	TMODLEN	8	/* length of mode field */
121 #define	TUIDLEN	8	/* length of uid field */
122 #define	TGIDLEN	8	/* length of gid field */
123 #define	TSIZLEN	12	/* length of size field */
124 #define	TTIMLEN	12	/* length of modification time field */
125 #define	TCRCLEN	8	/* length of header checksum field */
126 
127 /* tar header definition */
128 
129 union tblock {
130 	char dummy[TBLOCK];
131 	struct tar_hdr {
132 		char	t_name[TNAMLEN],	/* name of file */
133 			t_mode[TMODLEN],	/* mode of file */
134 			t_uid[TUIDLEN],		/* uid of file */
135 			t_gid[TGIDLEN],		/* gid of file */
136 			t_size[TSIZLEN],	/* size of file in bytes */
137 			t_mtime[TTIMLEN],	/* modification time of file */
138 			t_cksum[TCRCLEN],	/* checksum of header */
139 			t_typeflag,
140 			t_linkname[TNAMLEN],	/* file this file linked with */
141 			t_magic[TMAGLEN],
142 			t_version[TVERSLEN],
143 			t_uname[32],
144 			t_gname[32],
145 			t_devmajor[8],
146 			t_devminor[8],
147 			t_prefix[155];
148 	} tbuf;
149 };
150 
151 /* volcopy tape label format and structure */
152 
153 #define	VMAGLEN 8
154 #define	VVOLLEN 6
155 #define	VFILLEN 464
156 
157 struct volcopy_label {
158 	char	v_magic[VMAGLEN],
159 		v_volume[VVOLLEN],
160 		v_reels,
161 		v_reel;
162 	int	v_time,
163 		v_length,
164 		v_dens,
165 		v_reelblks,	/* u370 added field */
166 		v_blksize,	/* u370 added field */
167 		v_nblocks;	/* u370 added field */
168 	char	v_fill[VFILLEN];
169 	int	v_offset;	/* used with -e and -reel options */
170 	int	v_type;		/* does tape have nblocks field? */
171 };
172 
173 /*
174  * Define archive formats for extended attributes.
175  *
176  * Extended attributes are stored in two pieces.
177  * 1. An attribute header which has information about
178  *    what file the attribute is for and what the attribute
179  *    is named.
180  * 2. The attribute record itself.  Stored as a normal file type
181  *    of entry.
182  * Both the header and attribute record have special modes/typeflags
183  * associated with them.
184  *
185  * The names of the header in the archive look like:
186  * /dev/null/attr.hdr
187  *
188  * The name of the attribute looks like:
189  * /dev/null/attr.
190  *
191  * This is done so that an archiver that doesn't understand these formats
192  * can just dispose of the attribute records unless the user chooses to
193  * rename them via cpio -r or pax -i
194  *
195  * The format is composed of a fixed size header followed
196  * by a variable sized xattr_buf. If the attribute is a hard link
197  * to another attribute, then another xattr_buf section is included
198  * for the link.
199  *
200  * The xattr_buf is used to define the necessary "pathing" steps
201  * to get to the extended attribute.  This is necessary to support
202  * a fully recursive attribute model where an attribute may itself
203  * have an attribute.
204  *
205  * The basic layout looks like this.
206  *
207  *     --------------------------------
208  *     |                              |
209  *     |         xattr_hdr            |
210  *     |                              |
211  *     --------------------------------
212  *     --------------------------------
213  *     |                              |
214  *     |        xattr_buf             |
215  *     |                              |
216  *     --------------------------------
217  *     --------------------------------
218  *     |                              |
219  *     |      (optional link info)    |
220  *     |                              |
221  *     --------------------------------
222  *     --------------------------------
223  *     |                              |
224  *     |      attribute itself        |
225  *     |      stored as normal tar    |
226  *     |      or cpio data with       |
227  *     |      special mode or         |
228  *     |      typeflag                |
229  *     |                              |
230  *     --------------------------------
231  *
232  */
233 #define	XATTR_ARCH_VERS	"1.0"
234 
235 /*
236  * extended attribute fixed header
237  *
238  * h_version		format version.
239  * h_size               size of header + variable sized data sections.
240  * h_component_len      Length of entire pathing section.
241  * h_link_component_len Length of link component section.  Again same definition
242  *                      as h_component_len.
243  */
244 struct xattr_hdr {
245 	char	h_version[7];
246 	char	h_size[10];
247 	char	h_component_len[10];	   /* total length of path component */
248 	char	h_link_component_len[10];
249 };
250 
251 /*
252  * The name is encoded like this:
253  * filepathNULattrpathNUL[attrpathNULL]...
254  */
255 struct xattr_buf {
256 	char	h_namesz[7];   /* length of h_names */
257 	char	h_typeflag;    /* actual typeflag of file being archived */
258 	char	h_names[1];	/* filepathNULattrpathNUL... */
259 };
260 
261 /*
262  * Special values for tar archives
263  */
264 
265 /*
266  * typeflag for tar archives.
267  */
268 
269 /*
270  * Attribute hdr and attribute files have the following typeflag
271  */
272 #define	_XATTR_HDRTYPE		'E'
273 
274 /*
275  * For cpio archives the header and attribute have
276  * _XATTR_CPIO_MODE ORED into the mode field in both
277  * character and binary versions of the archive format
278  */
279 #define	_XATTR_CPIO_MODE	0xB000
280 
281 #ifdef	__cplusplus
282 }
283 #endif
284 
285 #endif	/* _ARCHIVES_H */
286