1 CPIO(5) FreeBSD File Formats Manual CPIO(5)
4 cpio -- format of cpio archive files
7 The cpio archive format collects any number of files, directories, and
8 other file system objects (symbolic links, device nodes, etc.) into a
9 single stream of bytes.
12 Each file system object in a cpio archive comprises a header record with
13 basic numeric metadata followed by the full pathname of the entry and the
14 file data. The header record stores a series of integer values that gen-
15 erally follow the fields in struct stat. (See stat(2) for details.) The
16 variants differ primarily in how they store those integers (binary,
17 octal, or hexadecimal). The header is followed by the pathname of the
18 entry (the length of the pathname is stored in the header) and any file
19 data. The end of the archive is indicated by a special record with the
20 pathname ``TRAILER!!!''.
23 XXX Any documentation of the original PWB/UNIX 1.0 format? XXX
26 The old binary cpio format stores numbers as 2-byte and 4-byte binary
27 values. Each entry begins with a header in the following format:
29 struct header_old_cpio {
30 unsigned short c_magic;
33 unsigned short c_mode;
36 unsigned short c_nlink;
37 unsigned short c_rdev;
38 unsigned short c_mtime[2];
39 unsigned short c_namesize;
40 unsigned short c_filesize[2];
43 The unsigned short fields here are 16-bit integer values; the unsigned
44 int fields are 32-bit integer values. The fields are as follows
46 magic The integer value octal 070707. This value can be used to deter-
47 mine whether this archive is written with little-endian or big-
51 The device and inode numbers from the disk. These are used by
52 programs that read cpio archives to determine when two entries
53 refer to the same file. Programs that synthesize cpio archives
54 should be careful to set these to distinct values for each entry.
56 mode The mode specifies both the regular permissions and the file
57 type. It consists of several bit fields as follows:
58 0170000 This masks the file type bits.
59 0140000 File type value for sockets.
60 0120000 File type value for symbolic links. For symbolic links,
61 the link body is stored as file data.
62 0100000 File type value for regular files.
63 0060000 File type value for block special devices.
64 0040000 File type value for directories.
65 0020000 File type value for character special devices.
66 0010000 File type value for named pipes or FIFOs.
69 0001000 Sticky bit. On some systems, this modifies the behavior
70 of executables and/or directories.
71 0000777 The lower 9 bits specify read/write/execute permissions
72 for world, group, and user following standard POSIX con-
76 The numeric user id and group id of the owner.
78 nlink The number of links to this file. Directories always have a
79 value of at least two here. Note that hardlinked files include
80 file data with every copy in the archive.
82 rdev For block special and character special entries, this field con-
83 tains the associated device number. For all other entry types,
84 it should be set to zero by writers and ignored by readers.
86 mtime Modification time of the file, indicated as the number of seconds
87 since the start of the epoch, 00:00:00 UTC January 1, 1970. The
88 four-byte integer is stored with the most-significant 16 bits
89 first followed by the least-significant 16 bits. Each of the two
90 16 bit values are stored in machine-native byte order.
93 The number of bytes in the pathname that follows the header.
94 This count includes the trailing NUL byte.
97 The size of the file. Note that this archive format is limited
98 to four gigabyte file sizes. See mtime above for a description
99 of the storage of four-byte integers.
101 The pathname immediately follows the fixed header. If the namesize is
102 odd, an additional NUL byte is added after the pathname. The file data
103 is then appended, padded with NUL bytes to an even length.
105 Hardlinked files are not given special treatment; the full file contents
106 are included with each copy of the file.
108 Portable ASCII Format
109 Version 2 of the Single UNIX Specification (``SUSv2'') standardized an
110 ASCII variant that is portable across all platforms. It is commonly
111 known as the ``old character'' format or as the ``odc'' format. It
112 stores the same numeric fields as the old binary format, but represents
113 them as 6-character or 11-character octal values.
115 struct cpio_odc_header {
129 The fields are identical to those in the old binary format. The name and
130 file body follow the fixed header. Unlike the old binary format, there
131 is no additional padding after the pathname or file contents. If the
132 files being archived are themselves entirely ASCII, then the resulting
133 archive will be entirely ASCII, except for the NUL byte that terminates
137 The "new" ASCII format uses 8-byte hexadecimal fields for all numbers and
138 separates device numbers into separate fields for major and minor num-
141 struct cpio_newc_header {
158 Except as specified below, the fields here match those specified for the
159 old binary format above.
161 magic The string ``070701''.
163 check This field is always set to zero by writers and ignored by read-
164 ers. See the next section for more details.
166 The pathname is followed by NUL bytes so that the total size of the fixed
167 header plus pathname is a multiple of four. Likewise, the file data is
168 padded to a multiple of four bytes. Note that this format supports only
169 4 gigabyte files (unlike the older ASCII format, which supports 8 giga-
172 In this format, hardlinked files are handled by setting the filesize to
173 zero for each entry except the last one that appears in the archive.
176 The CRC format is identical to the new ASCII format described in the pre-
177 vious section except that the magic field is set to ``070702'' and the
178 check field is set to the sum of all bytes in the file data. This sum is
179 computed treating all bytes as unsigned values and using unsigned arith-
180 metic. Only the least-significant 32 bits of the sum are stored.
183 The cpio implementation distributed with HPUX used XXXX but stored device
184 numbers differently XXX.
186 Other Extensions and Variants
187 Sun Solaris uses additional file types to store extended file data,
188 including ACLs and extended attributes, as special entries in cpio ar-
194 The ``CRC'' format is mis-named, as it uses a simple checksum and not a
195 cyclic redundancy check.
197 The old binary format is limited to 16 bits for user id, group id,
198 device, and inode numbers. It is limited to 4 gigabyte file sizes.
200 The old ASCII format is limited to 18 bits for the user id, group id,
201 device, and inode numbers. It is limited to 8 gigabyte file sizes.
203 The new ASCII format is limited to 4 gigabyte file sizes.
205 None of the cpio formats store user or group names, which are essential
206 when moving files between systems with dissimilar user or group number-
209 Especially when writing older cpio variants, it may be necessary to map
210 actual device/inode values to synthesized values that fit the available
211 fields. With very large filesystems, this may be necessary even for the
218 The cpio utility is no longer a part of POSIX or the Single Unix Stan-
219 dard. It last appeared in Version 2 of the Single UNIX Specification
220 (``SUSv2''). It has been supplanted in subsequent standards by pax(1).
221 The portable ASCII format is currently part of the specification for the
225 The original cpio utility was written by Dick Haight while working in
226 AT&T's Unix Support Group. It appeared in 1977 as part of PWB/UNIX 1.0,
227 the ``Programmer's Work Bench'' derived from Version 6 AT&T UNIX that was
228 used internally at AT&T. Both the old binary and old character formats
229 were in use by 1980, according to the System III source released by SCO
230 under their ``Ancient Unix'' license. The character format was adopted
231 as part of IEEE Std 1003.1-1988 (``POSIX.1''). XXX when did "newc"
232 appear? Who invented it? When did HP come out with their variant? When
233 did Sun introduce ACLs and extended attributes? XXX
235 FreeBSD 6.0 October 5, 2007 FreeBSD 6.0