1 .\" Copyright (c) 2007 Tim Kientzle
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
32 .Nd format of cpio archive files
36 archive format collects any number of files, directories, and other
37 file system objects (symbolic links, device nodes, etc.) into a single
40 Each file system object in a
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
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)
55 The end of the archive is indicated by a special record with
59 XXX Any documentation of the original PWB/UNIX 1.0 format? XXX
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;
70 unsigned short c_mode;
73 unsigned short c_nlink;
74 unsigned short c_rdev;
75 unsigned short c_mtime[2];
76 unsigned short c_namesize;
77 unsigned short c_filesize[2];
83 fields here are 16-bit integer values; the
85 fields are 32-bit integer values.
86 The fields are as follows
87 .Bl -tag -width indent
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.
93 The device and inode numbers from the disk.
94 These are used by programs that read
96 archives to determine when two entries refer to the same file.
97 Programs that synthesize
99 archives should be careful to set these to distinct values for each entry.
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
105 This masks the file type bits.
107 File type value for sockets.
109 File type value for symbolic links.
110 For symbolic links, the link body is stored as file data.
112 File type value for regular files.
114 File type value for block special devices.
116 File type value for directories.
118 File type value for character special devices.
120 File type value for named pipes or FIFOs.
127 On some systems, this modifies the behavior of executables and/or directories.
129 The lower 9 bits specify read/write/execute permissions
130 for world, group, and user following standard POSIX conventions.
133 The numeric user id and group id of the owner.
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.
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.
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.
151 The number of bytes in the pathname that follows the header.
152 This count includes the trailing NUL byte.
154 The size of the file.
155 Note that this archive format is limited to
156 four gigabyte file sizes.
159 above for a description of the storage of four-byte integers.
162 The pathname immediately follows the fixed header.
165 is odd, an additional NUL byte is added after the pathname.
166 The file data is then appended, padded with NUL
167 bytes to an even length.
169 Hardlinked files are not given special treatment;
170 the full file contents are included with each copy of the
172 .Ss Portable ASCII Format
174 standardized an ASCII variant that is portable across all
176 It is commonly known as the
181 It stores the same numeric fields as the old binary format, but
182 represents them as 6-character or 11-character octal values.
183 .Bd -literal -offset indent
184 struct cpio_odc_header {
199 The fields are identical to those in the old binary format.
200 The name and file body follow the fixed header.
201 Unlike the old binary format, there is no additional padding
202 after the pathname or file contents.
203 If the files being archived are themselves entirely ASCII, then
204 the resulting archive will be entirely ASCII, except for the
205 NUL byte that terminates the name field.
207 The "new" ASCII format uses 8-byte hexadecimal fields for
208 all numbers and separates device numbers into separate fields
209 for major and minor numbers.
210 .Bd -literal -offset indent
211 struct cpio_newc_header {
229 Except as specified below, the fields here match those specified
230 for the old binary format above.
231 .Bl -tag -width indent
236 This field is always set to zero by writers and ignored by readers.
237 See the next section for more details.
240 The pathname is followed by NUL bytes so that the total size
241 of the fixed header plus pathname is a multiple of four.
242 Likewise, the file data is padded to a multiple of four bytes.
243 Note that this format supports only 4 gigabyte files (unlike the
244 older ASCII format, which supports 8 gigabyte files).
246 In this format, hardlinked files are handled by setting the
247 filesize to zero for each entry except the first one that
248 appears in the archive.
250 The CRC format is identical to the new ASCII format described
251 in the previous section except that the magic field is set
256 field is set to the sum of all bytes in the file data.
257 This sum is computed treating all bytes as unsigned values
258 and using unsigned arithmetic.
259 Only the least-significant 32 bits of the sum are stored.
263 implementation distributed with HPUX used XXXX but stored
264 device numbers differently XXX.
265 .Ss Other Extensions and Variants
266 Sun Solaris uses additional file types to store extended file
267 data, including ACLs and extended attributes, as special
268 entries in cpio archives.
277 utility is no longer a part of POSIX or the Single Unix Standard.
280 It has been supplanted in subsequent standards by
282 The portable ASCII format is currently part of the specification for the
286 The original cpio utility was written by Dick Haight
287 while working in AT&T's Unix Support Group.
288 It appeared in 1977 as part of PWB/UNIX 1.0, the
289 .Dq Programmer's Work Bench
292 that was used internally at AT&T.
293 Both the old binary and old character formats were in use
294 by 1980, according to the System III source released
298 The character format was adopted as part of
300 XXX when did "newc" appear? Who invented it? When did HP come out with their variant? When did Sun introduce ACLs and extended attributes? XXX
304 format is mis-named, as it uses a simple checksum and
305 not a cyclic redundancy check.
307 The old binary format is limited to 16 bits for user id,
308 group id, device, and inode numbers.
309 It is limited to 4 gigabyte file sizes.
311 The old ASCII format is limited to 18 bits for
312 the user id, group id, device, and inode numbers.
313 It is limited to 8 gigabyte file sizes.
315 The new ASCII format is limited to 4 gigabyte file sizes.
317 None of the cpio formats store user or group names,
318 which are essential when moving files between systems with
319 dissimilar user or group numbering.
321 Especially when writing older cpio variants, it may be necessary
322 to map actual device/inode values to synthesized values that
323 fit the available fields.
324 With very large filesystems, this may be necessary even for