cpio — Format of cpio archives

Related information

You can use the cpio command to back up or restore files. The cpio command reads and writes either a compact binary format header or an ASCII format header. The tar command reads and writes headers in either the original TAR format from UNIX systems or the USTAR format defined by the POSIX 1003.1 standard.

The pax command reads and writes headers in any of the cpio formats.

Description

A cpio archive consists of one or more concatenated member files. Each member file contains a header optionally followed by file contents as indicated in the header. The end of the archive is indicated by another header describing an (empty) file named TRAILER!!.

There are two types of cpio archives, differing only in the style of the header:
  • ASCII archives have totally printable header information; thus, if the files being archived are also ASCII files, the whole archive is ASCII.
  • By default, cpio writes archives with binary headers. However, binary archive files cannot usually be ported to other operating systems, so you should not use these.

The information in an ASCII archive header is stored in fixed-width, octal (base 8) numbers padded with zeros on the left. Table 1 gives the order and field width for the information in the ASCII header:

Table 1. Archive file: ASCII header
Field width Field name Meaning
6 magic Magic number 070707
6 dev Device where file resides
6 ino I-number of file
6 mode File mode
6 uid Owner user ID
6 gid Owner group ID
6 nlink Number of links to file
6 rdev Device major/minor for special file
11 mtime Modify time of file
6 namesize Length of filename
11 filesize Length of file

After the header information, namesize bytes of path name are stored. namesize includes the null byte of the end of the path name. After this, filesize bytes of the file contents are recorded.

Binary headers contain the same information in 2-byte (short) and 4-byte (long) integers as follows:
Bytes
Field names
2
magic
2
dev
2
ino
2
mode
2
uid
2
gid
2
nlink
2
rdev
2
mtime
2
namesize
2
filesize

After the header information comes the filename, with namesize rounded up to the nearest 2-byte boundary. Then the file contents appear as in the ASCII archive. The byte ordering of the 2- and 4-byte integers in the binary format is machine-dependent and thus portability of this format is not easily guaranteed.

Related information

The compress, cpio, pax, and tar commands