cpio File Format

Purpose

Describes the copy in/out (cpio) archive file.

Description

The cpio utility backs up and recovers files. The files are saved on the backup medium in the cpio format.

When the cpio command is used with the -c flag, the header for the cpio structure reads as follows:

sscanf(Chdr,"%6ho%6ho%6ho%6ho%6ho%6ho%6ho%6ho%11lo%6ho%11lo%s",
&Hdr.h_magic, &Hdr.h_dev, &Hdr.h_ino, &Hdr.h_mode,
&Hdr.h_uid, &Hdr.h_gid, &Hdr.h_nlink, &Hdr.h_rdev,
&Longtime, &Hdr.h_namesize, &Longfile, &Hdr.h_name);
Longtime and Longfile are equivalent to Hdr.h_mtime and Hdr.h_filesize, respectively. The contents of each file, and other items describing the file, are recorded in an element of the array of structures with varying lengths.
Note: Files saved with the -c flag must be restored with the -c flag.

When the -c flag of the cpio command is not used, the header structure contains the following fields:

Item Description
h_magic Contains the constant octal 070707 (or 0x71c7).
h_dev Device that contains a directory entry for this file.
h_ino I-node number that identifies the input file to the file system.
h_mode Mode of the input file, as defined in the mode.h file.
h_uid User ID of the owner of the input file.
h_gid Group ID of the owner of the input file.

For remote files, these fields contain the ID after reverse translation:

Item Description
h_nlink Number of links that are connected to the input file.
h_rdev ID of the remote device from which the input file is taken.
h_mtime Time when data was last modified. For remote files, this field contains the time at the server. This time can be changed by the creat, fclearf, truncate, mknod, openx, pipe, utime, or writex subroutine.
h_namesize Length of the path name, including the terminating null byte.
h_filesize Length of the file in bytes. This is the length of the data section that follows the header structure.
h_name Null-terminated path name. The length of the path name, including the null byte, is indicated by the n variable, where n equals ((h_namesize % 2) + h_namesize). That is, the n variable is equal to the h_namesize field if the h_namesize field is even. If the h_namesize field is odd, the n variable is equal to the h_namesize field + 1.

The last record of the archive always contains the name TRAILER!!!. Special files, directories, and the trailer are recorded with the h_filesize field equal to 0.