cpio

format of cpio archives

File Format


DESCRIPTION

This document describes the format of archives read and written by the cpio utility. A cpio archive consists of the concatenation of one or more member files. Each member file contains a header (as described later in this reference page) 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.

The information in ASCII archive headers is stored in fixed-width, octal (base 8) numbers zero-padded on the left. Table 1 gives the order and field width for the informationin the 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 file name
11 filesize length of file to follow

Table 1: ASCII Header Format for cpio File

Most of this information is compatible with that returned by the UNIX stat() function; see also stat. After this information, namesize bytes of path name is 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 shown in Table 2.

Bytes Field Name
2 magic
2 dev
2 ino
2 mode
2 uid
2 gid
2 nlink
2 rdev
4 mtime
2 namesize
4 filesize

Table 2: Binary Header Format for cpio File

After this information comes the file name (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.


PORTABILITY

For maximum portability among different system architectures, only the ASCII archive format should be used.


SEE ALSO

Commands:
cpio, pax, tar

File Formats:
tar

Miscellaneous:
stat


Updated MKS Toolkit [3khat16.ico]HP3000 [3khat16.ico]3kMail [archive16.gif]