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