Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Copy in and out (CPIO) archive format

The copy in and out (CPIO) archive format is an archive format that predates TAR but is still being used e.g. in initramfs or rpm.

Overview

There are multiple variants of the CPIO format:

  • binary CPIO format
  • portable ASCII CPIO format
  • new ASCII CPIO format

A CPIO file consists of:

  • An array of CPIO file records where the last record contains the path “TRAILER!!!”
  • Trailing 0-byte values

Note that the format does not require (or enforce) parent directory file records to exist within the archive file.

CharacteristicsDescription
Byte orderformat dependent
Date and time valuesPOSIX timestamp in UTC
Character stringsUTF-8 or a narrow character (Single Byte Character (SBC) or Multi Byte Character (MBC)) stored using a system defined codepage

Binary CPIO format

The binary CPIO format (or “bin”), sometimes referred to as the old CPIO format, stores the values as either big-endian or little-endian binary data.

Binary CPIO file record

The binary CPIO file record is variable of size and consists of:

OffsetSizeValueDescription
02Signature, which is 070707 in octal where [0x71, 0xc7] indicates the format is in big-endian and [0xc7, 0x71] little-endian
22Device number of the host file system
42Inode number
62File mode (permissions and type)
82Owner identifier (uid)
102Group identifier (gid)
122Number of links
142Block or character special device identifier or 0 if not set
164Modification time, where the most significant 16-bits are stored in the first 2 bytes and the least significant 16-bits in the last 2 bytes
202Size of path string, including the end-of-string character (NUL)
224File data size, where the most the most significant 16-bits in the first 2 bytes and the least significant 16-bits in the last 2 bytes
26...Path string
......16-bit alignment padding, which should be set to 0
......File data
......16-bit alignment padding, which should be set to 0

Portable ASCII CPIO format

The portable ASCII CPIO format (or “odc”), sometimes referred to as the old character or POSIX.1 format, stores the values are as octal strings.

OffsetSizeValueDescription
06"070707"Signature
66Device number of the host file system
126Inode number
186File mode (permissions and type)
246Owner identifier (uid)
306Group identifier (gid)
366Number of links
426Block or character special device identifier or 0 if not set
4811Modification time
596Size of path string, including the end-of-string character (NUL)
6511File data size
76...Path string
......File data

New ASCII CPIO format

The new (SVR4) ASCII CPIO format stores the values as hexadecimal strings. The new ASCII CPIO format is technically 2 different formats one without (“newc”) and one with a checksum (“crc”). Both support file systems having more than 65536 inodes.

OffsetSizeValueDescription
06"070701" or "070702"Signature
68Inode number
148File mode (permissions and type)
228Owner identifier (uid)
308Group identifier (gid)
388Number of links
468Modification time
548File data size
628Device major number of the host file system
708Device minor number of the host file system
788Block or character special device major number
868Block or character special device minor number
948Size of path string, including the end-of-string character (NUL)
1028Checksum, which contains a a Sum32 if signature is "070702", or 0 otherwise
110...Path string
......32-bit alignment padding, which should be set to 0
......File data
......32-bit alignment padding, which Should be set to 0

Checksum

TODO: complete section

File mode

ValueIdentifierDescription
0x01ffPermissions
0x0200Sticky bit
0x0400SGID bit
0x0800SUID bit
File type (0xf000)
0x1000Named pipe or FIFO
0x2000Character special device
0x4000Directory
0x6000Block special device
0x8000Regular file
0xa000Symbolic link
0xc000Socket

The link target of a symbolic link is stored as file data.