Every cpio entry is a header, the path name (with its NUL) and the file’s data. The
four header formats below are told apart by their magic. This page follows the
cpio(5) manual page in libarchive
(dated 23 December 2011, read 2026-11-13) and the odc format in the
POSIX pax specification
(“cpio Interchange Format”, read 2026-11-13). cpio(5) itself says it has gaps (“XXX” notes on the
HP variants, other extensions and the history of newc). A file starts with the magic of its first entry;
the magic of the two binary variants is the same (070707 octal as a 16-bit number), and
cpio(5) says there is no obvious way to tell the PWB and new binary variants apart other than seeing which
one makes sense (a PWB archive read as new binary shows directories as sockets, and
bsdcpio -itv shows an s instead of d for them and ? for large files).
Old binary header
The original PWB/Unix format: thirteen 16-bit words, 26 bytes. The magic is
070707 octal (0x71C7) as a 16-bit number, so it reads
C7 71 when written little-endian and 71 C7 big-endian; a
reader uses it to learn the byte order of the whole header. The 32-bit fields are
two 16-bit words, most significant word first, each word in that byte order (on a
little-endian machine 0x12345678 is stored 34 12 78 56).
| Offset | Size | Name | Description |
|---|---|---|---|
0 | 2 | h_magic | 070707 octal. |
2 | 2 | h_dev | Device holding the file (used with h_ino to spot hard links). |
4 | 2 | h_ino | Inode number. |
6 | 2 | h_mode | File type and permissions; see mode. |
8 | 2 | h_uid | Owner’s user ID. |
10 | 2 | h_gid | Owner’s group ID. |
12 | 2 | h_nlink | Number of links. |
14 | 2 | h_majmin | For block and character special entries, the device number: the major number in the high byte and the minor number in the low byte. For all other entries writers should set it to zero and readers ignore it. |
16 | 4 | h_mtime | Modification time, seconds since 1970. |
20 | 2 | h_namesize | Length of the path name including its NUL. |
22 | 4 | h_filesize | Size of the data. |
Padding: if h_namesize is odd, one NUL follows the name, and a NUL
follows the data when needed so the next header starts at an even offset. In the
original PWB format the size was limited to 16 MiB; the later “new binary” form of the
same header treats it as a signed 32-bit number (2 GiB). User, group, device and inode
numbers are limited to 16 bits.
odc (POSIX portable ASCII) header
76 bytes of ASCII text: every field is octal digits with leading zeros. POSIX.1
defines it for pax -x cpio.
| Offset | Size | Name | Description |
|---|---|---|---|
0 | 6 | c_magic | 070707. |
6 | 6 | c_dev | Device. |
12 | 6 | c_ino | Inode number. |
18 | 6 | c_mode | Type and permissions. |
24 | 6 | c_uid | User ID. |
30 | 6 | c_gid | Group ID. |
36 | 6 | c_nlink | Number of links. |
42 | 6 | c_rdev | POSIX calls it “implementation-defined information for character or block special files”; cpio(5) treats it like the binary format’s device number. |
48 | 11 | c_mtime | Modification time. |
59 | 6 | c_namesize | Name length including the NUL. |
65 | 11 | c_filesize | Data size. |
No padding after the name or the data. Six octal digits allow 18-bit IDs and device and inode numbers; eleven allow files up to 8 GiB.
newc (SVR4) and crc headers
110 bytes of ASCII text: every field after the magic is 8 hexadecimal digits. The header plus pathname is padded to a multiple of four bytes, and a file’s data too; the format supports only 4 GiB files.
| Offset | Size | Name | Description |
|---|---|---|---|
0 | 6 | c_magic | 070701 (newc) or 070702 (crc). |
6 | 8 | c_ino | Inode number. |
14 | 8 | c_mode | Type and permissions. |
22 | 8 | c_uid | User ID. |
30 | 8 | c_gid | Group ID. |
38 | 8 | c_nlink | Number of links. |
46 | 8 | c_mtime | Modification time, seconds since 1970. |
54 | 8 | c_filesize | Data size; up to 4 GiB. |
62 | 8 | c_devmajor | Major number of the device holding the file. |
70 | 8 | c_devminor | Its minor number. |
78 | 8 | c_rdevmajor | Major number, for device files. |
86 | 8 | c_rdevminor | Minor number, for device files. |
94 | 8 | c_namesize | Name length including the NUL. |
102 | 8 | c_check | newc: zero, ignored. crc: the checksum of the data. |
Padding: NULs after the name so that header and name together are a multiple of 4 bytes, and NULs after the data to the next multiple of 4.
The crc checksum
Despite the name it is not a CRC: it is the sum of every byte of the file’s data as unsigned numbers, keeping the low 32 bits.
Mode
| Octal | Meaning |
|---|---|
0170000 | Mask for the file type |
0140000 | Socket |
0120000 | Symbolic link; the data is the link target |
0100000 | Regular file |
0060000 | Block device |
0040000 | Directory |
0020000 | Character device |
0010000 | FIFO (named pipe) |
0004000 | Set user ID |
0002000 | Set group ID |
0001000 | Sticky bit (POSIX’s table calls C_ISVTX “Reserved”) |
0110000 | Reserved in POSIX’s table (C_ISCTG); not in cpio(5) |
0000777 | Read, write and execute for owner, group and others |
In the old PWB binary format, 0100000 was IALLOC and
0010000 ILARG, inode flags with no meaning to cpio; the
later formats reuse those bits for the file types above.
Hard links and the trailer
In the binary and odc formats, every hard link carries a full copy of the data. In
newc and crc, entries with the same device and inode are links to one file, and the
data is stored once: the other entries have a size of zero. cpio(5) says the data goes
with the first entry that appears in the archive; it does not say what other writers do.
POSIX pax requires c_dev and c_ino to identify a file uniquely within
the archive (no two files share the pair unless they are links to the same file), set “in an
unspecified manner”, and c_nlink to be at least the number of links in the archive.
The archive ends with an entry named TRAILER!!!, with no data. POSIX says an archive
may be recorded as fixed-size blocks of octets, only to make physical I/O efficient, with the last
group of blocks always full, and that the contents of the octets after the trailer header in the last
block are undefined. Special entries per POSIX: FIFOs, directories and the trailer have
c_filesize 0; a symbolic link’s size is the length of its target (its data); for other special
files the size is unspecified. Only regular files and symbolic links have data to restore. The pathname is
written in ISO/IEC 646 characters, and an entry is written one after another with no gap. cpio(5)
gives no block size.
Other variants exist: cpio(5) says Solaris uses additional file types to store ACLs and extended attributes as special entries and that the HP-UX implementation stored device numbers differently, leaving both undescribed (“XXXX”). cpio(5)’s BUGS list the limits: the binary formats keep user and group IDs, device and inode numbers in 16 bits; the old ASCII format in 18 bits (8 GiB files); the new ASCII format limits files to 4 GiB. No cpio format stores user or group names. The “crc” format is misnamed: its check is a sum of bytes, not a cyclic redundancy check.
Example
A newc header for a 5-byte file hi, mode 0100644:
070701 c_magic
00000001 c_ino
000081A4 c_mode 0100644, regular file rw-r--r--
000003E8 c_uid 1000
000003E8 c_gid 1000
00000001 c_nlink
5F5E1000 c_mtime
00000005 c_filesize
00000008 00000001 c_devmajor, c_devminor
00000000 00000000 c_rdevmajor, c_rdevminor
00000003 c_namesize ("hi" and NUL)
00000000 c_check
hi\0 \0\0\0 the name, its NUL, then padding
The fields are written one after another with no spaces; they are split into lines here only for reading. Header and name are 113 bytes, so three NULs bring them to 116, a multiple of 4. The 5 data bytes are followed by three NULs to reach the next multiple of 4.