Import libarchive-2.3.4:
[dragonfly.git] / contrib / libarchive-2 / libarchive / cpio.5
1 .\" Copyright (c) 2007 Tim Kientzle
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD$
26 .\"
27 .Dd October 5, 2007
28 .Dt CPIO 5
29 .Os
30 .Sh NAME
31 .Nm cpio
32 .Nd format of cpio archive files
33 .Sh DESCRIPTION
34 The
35 .Nm
36 archive format collects any number of files, directories, and other
37 file system objects (symbolic links, device nodes, etc.) into a single
38 stream of bytes.
39 .Ss General Format
40 Each file system object in a
41 .Nm
42 archive comprises a header record with basic numeric metadata
43 followed by the full pathname of the entry and the file data.
44 The header record stores a series of integer values that generally
45 follow the fields in
46 .Va struct stat .
47 (See
48 .Xr stat 2
49 for details.)
50 The variants differ primarily in how they store those integers
51 (binary, octal, or hexadecimal).
52 The header is followed by the pathname of the
53 entry (the length of the pathname is stored in the header)
54 and any file data.
55 The end of the archive is indicated by a special record with
56 the pathname
57 .Dq TRAILER!!! .
58 .Ss PWB format
59 XXX Any documentation of the original PWB/UNIX 1.0 format? XXX
60 .Ss Old Binary Format
61 The old binary
62 .Nm
63 format stores numbers as 2-byte and 4-byte binary values.
64 Each entry begins with a header in the following format:
65 .Bd -literal -offset indent
66 struct header_old_cpio {
67         unsigned short   c_magic;
68         unsigned short   c_dev;
69         unsigned short   c_ino;
70         unsigned short   c_mode;
71         unsigned short   c_uid;
72         unsigned short   c_gid;
73         unsigned short   c_nlink;
74         unsigned short   c_rdev;
75         unsigned int     c_mtime;
76         unsigned short   c_namesize;
77         unsigned int     c_filesize;
78 };
79 .Ed
80 .Pp
81 The
82 .Va unsigned short
83 fields here are 16-bit integer values; the
84 .Va unsigned int
85 fields are 32-bit integer values.
86 The fields are as follows
87 .Bl -tag -width indent
88 .It Va magic
89 The integer value octal 070707.
90 This value can be used to determine whether this archive is
91 written with little-endian or big-endian integers.
92 .It Va dev , Va ino
93 The device and inode numbers from the disk.
94 These are used by programs that read
95 .Nm
96 archives to determine when two entries refer to the same file.
97 Programs that synthesize
98 .Nm
99 archives should be careful to set these to distinct values for each entry.
100 .It Va mode
101 The mode specifies both the regular permissions and the file type.
102 It consists of several bit fields as follows:
103 .Bl -tag -width "MMMMMMM" -compact
104 .It 0170000
105 This masks the file type bits.
106 .It 0140000
107 File type value for sockets.
108 .It 0120000
109 File type value for symbolic links.
110 For symbolic links, the link body is stored as file data.
111 .It 0100000
112 File type value for regular files.
113 .It 0060000
114 File type value for block special devices.
115 .It 0040000
116 File type value for directories.
117 .It 0020000
118 File type value for character special devices.
119 .It 0010000
120 File type value for named pipes or FIFOs.
121 .It 0004000
122 SUID bit.
123 .It 0002000
124 SGID bit.
125 .It 0001000
126 Sticky bit.
127 On some systems, this modifies the behavior of executables and/or directories.
128 .It 0000777
129 The lower 9 bits specify read/write/execute permissions
130 for world, group, and user following standard POSIX conventions.
131 .El
132 .It Va uid , Va gid
133 The numeric user id and group id of the owner.
134 .It Va nlink
135 The number of links to this file.
136 Directories always have a value of at least two here.
137 Note that hardlinked files include file data with every copy in the archive.
138 .It Va rdev
139 For block special and character special entries,
140 this field contains the associated device number.
141 For all other entry types, it should be set to zero by writers
142 and ignored by readers.
143 .It Va mtime
144 Modification time of the file, indicated as the number
145 of seconds since the start of the epoch,
146 00:00:00 UTC January 1, 1970.
147 The four-byte integer is stored with the most-significant 16 bits first
148 followed by the least-significant 16 bits.
149 Each of the two 16 bit values are stored in machine-native byte order.
150 .It Va namesize
151 The number of bytes in the pathname that follows the header.
152 .It Va filesize
153 The size of the file.
154 Note that this archive format is limited to
155 four gigabyte file sizes.
156 See
157 .Va mtime
158 above for notes on the storage of four-byte integers.
159 .El
160 .Pp
161 The pathname immediately follows the fixed header.
162 If the pathname has an odd length, an additional NULL
163 byte is added after the pathname.
164 The file data is then appended, padded with NULL
165 bytes to an even length.
166 .Ss Portable ASCII Format
167 .St -susv2
168 standardized an ASCII variant that is portable across all
169 platforms.
170 It is commonly known as the
171 .Dq odc
172 format.
173 It stores the numeric fields as 6-character or 11-character
174 octal values.
175 .Bd -literal -offset indent
176 struct cpio_odc_header {
177         char    c_magic[6];
178         char    c_dev[6];
179         char    c_ino[6];
180         char    c_mode[6];
181         char    c_uid[6];
182         char    c_gid[6];
183         char    c_nlink[6];
184         char    c_rdev[6];
185         char    c_mtime[11];
186         char    c_namesize[6];
187         char    c_filesize[11];
188 };
189 .Ed
190 .Pp
191 Except as specified below, the fields here match those specified
192 for the old binary format above.
193 .Bl -tag -width indent
194 .It Va magic
195 The string
196 .Dq 070707 .
197 .It Va namesize
198 The count here includes a terminating NULL byte.
199 .El
200 .Pp
201 The name and file body follow the fixed header.
202 If the files being archived are themselves entirely ASCII, then
203 the resulting archive will be entirely ASCII, except for the
204 NULL byte that terminates the name field.
205 .Ss New ASCII Format
206 The "new" ASCII format uses 8-byte hexadecimal fields for
207 all numbers and separates device numbers into separate fields
208 for major and minor numbers.
209 .Bd -literal -offset indent
210 struct cpio_newc_header {
211         char    c_magic[6];
212         char    c_ino[8];
213         char    c_mode[8];
214         char    c_uid[8];
215         char    c_gid[8];
216         char    c_nlink[8];
217         char    c_mtime[8];
218         char    c_filesize[8];
219         char    c_devmajor[8];
220         char    c_devminor[8];
221         char    c_rdevmajor[8];
222         char    c_rdevminor[8];
223         char    c_namesize[8];
224         char    c_check[8];
225 };
226 .Ed
227 .Pp
228 Except as specified below, the fields here match those specified
229 for the old binary format above.
230 .Bl -tag -width indent
231 .It Va magic
232 The string
233 .Dq 070701 .
234 .It Va check
235 This field is always set to zero by writers and ignored by readers.
236 See the next section for more details.
237 .El
238 .Pp
239 The pathname is followed by NULL bytes so that the total size
240 of the fixed header plus pathname is a multiple of four.
241 Likewise, the file data is padded to a multiple of four bytes.
242 Note that this format supports only 4 gigabyte files (unlike the
243 older ASCII format, which supports 8 gigabyte files).
244 .Ss New CRC Format
245 The CRC format is identical to the new ASCII format described
246 in the previous section except that the magic field is set
247 to
248 .Dq 070702
249 and the
250 .Va check
251 field is set to the sum of all bytes in the file data.
252 This sum is computed treating all bytes as unsigned values
253 and using unsigned arithmetic.
254 Only the least-significant 32 bits of the sum are stored.
255 .Ss HP variants
256 The
257 .Nm cpio
258 implementation distributed with HPUX used XXXX but stored
259 device numbers differently XXX.
260 .Ss Other Extensions and Variants
261 Sun Solaris uses additional file types to store extended file
262 data, including ACLs and extended attributes, as special
263 entries in cpio archives.
264 .Pp
265 XXX Others? XXX
266 .Sh BUGS
267 The
268 .Dq CRC
269 format is mis-named, as it uses a simple checksum and
270 not a cyclic redundancy check.
271 .Pp
272 The old binary format is limited to 16 bits for user id,
273 group id, device, and inode numbers.
274 It is limited to 4 gigabyte file sizes.
275 .Pp
276 The old ASCII format is limited to 18 bits for
277 the user id, group id, device, and inode numbers.
278 It is limited to 8 gigabyte file sizes.
279 .Pp
280 The new ASCII format is limited to 4 gigabyte file sizes.
281 .Pp
282 None of the cpio formats store user or group names,
283 which are essential when moving files between systems with
284 dissimilar user or group numbering.
285 .Pp
286 Especially when writing older cpio variants, it may be necessary
287 to map actual device/inode values to synthesized values that
288 fit the available fields.
289 With very large filesystems, this may be necessary even for
290 the newer formats.
291 .Sh SEE ALSO
292 .Xr cpio 1 ,
293 .Xr tar 5
294 .Sh STANDARDS
295 The
296 .Nm cpio
297 utility is no longer a part of POSIX or the Single Unix Standard.
298 It last appeared in
299 .St -susv2 .
300 It has been supplanted in subsequent standards by
301 .Xr pax 1 .
302 The portable ASCII format is currently part of the specification for the
303 .Xr pax 1
304 utility.
305 .Sh HISTORY
306 The original cpio utility was written by Dick Haight
307 while working in AT&T's Unix Support Group.
308 It was first available in PWB/UNIX 1.0, the
309 .Dq Programmer's Work Bench
310 derived from
311 .At v6
312 that was used internally at AT&T.
313 It became more generally available as part of
314 .At v7 .