Blame libarchive/cpio.5

Packit Service 1d0348
.\" Copyright (c) 2007 Tim Kientzle
Packit Service 1d0348
.\" All rights reserved.
Packit Service 1d0348
.\"
Packit Service 1d0348
.\" Redistribution and use in source and binary forms, with or without
Packit Service 1d0348
.\" modification, are permitted provided that the following conditions
Packit Service 1d0348
.\" are met:
Packit Service 1d0348
.\" 1. Redistributions of source code must retain the above copyright
Packit Service 1d0348
.\"    notice, this list of conditions and the following disclaimer.
Packit Service 1d0348
.\" 2. Redistributions in binary form must reproduce the above copyright
Packit Service 1d0348
.\"    notice, this list of conditions and the following disclaimer in the
Packit Service 1d0348
.\"    documentation and/or other materials provided with the distribution.
Packit Service 1d0348
.\"
Packit Service 1d0348
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
Packit Service 1d0348
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit Service 1d0348
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit Service 1d0348
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
Packit Service 1d0348
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit Service 1d0348
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit Service 1d0348
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit Service 1d0348
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit Service 1d0348
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit Service 1d0348
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit Service 1d0348
.\" SUCH DAMAGE.
Packit Service 1d0348
.\"
Packit Service 1d0348
.\" $FreeBSD$
Packit Service 1d0348
.\"
Packit Service 1d0348
.Dd December 23, 2011
Packit Service 1d0348
.Dt CPIO 5
Packit Service 1d0348
.Os
Packit Service 1d0348
.Sh NAME
Packit Service 1d0348
.Nm cpio
Packit Service 1d0348
.Nd format of cpio archive files
Packit Service 1d0348
.Sh DESCRIPTION
Packit Service 1d0348
The
Packit Service 1d0348
.Nm
Packit Service 1d0348
archive format collects any number of files, directories, and other
Packit Service 1d0348
file system objects (symbolic links, device nodes, etc.) into a single
Packit Service 1d0348
stream of bytes.
Packit Service 1d0348
.Ss General Format
Packit Service 1d0348
Each file system object in a
Packit Service 1d0348
.Nm
Packit Service 1d0348
archive comprises a header record with basic numeric metadata
Packit Service 1d0348
followed by the full pathname of the entry and the file data.
Packit Service 1d0348
The header record stores a series of integer values that generally
Packit Service 1d0348
follow the fields in
Packit Service 1d0348
.Va struct stat .
Packit Service 1d0348
(See
Packit Service 1d0348
.Xr stat 2
Packit Service 1d0348
for details.)
Packit Service 1d0348
The variants differ primarily in how they store those integers
Packit Service 1d0348
(binary, octal, or hexadecimal).
Packit Service 1d0348
The header is followed by the pathname of the
Packit Service 1d0348
entry (the length of the pathname is stored in the header)
Packit Service 1d0348
and any file data.
Packit Service 1d0348
The end of the archive is indicated by a special record with
Packit Service 1d0348
the pathname
Packit Service 1d0348
.Dq TRAILER!!! .
Packit Service 1d0348
.Ss PWB format
Packit Service 1d0348
XXX Any documentation of the original PWB/UNIX 1.0 format? XXX
Packit Service 1d0348
.Ss Old Binary Format
Packit Service 1d0348
The old binary
Packit Service 1d0348
.Nm
Packit Service 1d0348
format stores numbers as 2-byte and 4-byte binary values.
Packit Service 1d0348
Each entry begins with a header in the following format:
Packit Service 1d0348
.Bd -literal -offset indent
Packit Service 1d0348
struct header_old_cpio {
Packit Service 1d0348
        unsigned short   c_magic;
Packit Service 1d0348
        unsigned short   c_dev;
Packit Service 1d0348
        unsigned short   c_ino;
Packit Service 1d0348
        unsigned short   c_mode;
Packit Service 1d0348
        unsigned short   c_uid;
Packit Service 1d0348
        unsigned short   c_gid;
Packit Service 1d0348
        unsigned short   c_nlink;
Packit Service 1d0348
        unsigned short   c_rdev;
Packit Service 1d0348
	unsigned short   c_mtime[2];
Packit Service 1d0348
        unsigned short   c_namesize;
Packit Service 1d0348
	unsigned short   c_filesize[2];
Packit Service 1d0348
};
Packit Service 1d0348
.Ed
Packit Service 1d0348
.Pp
Packit Service 1d0348
The
Packit Service 1d0348
.Va unsigned short
Packit Service 1d0348
fields here are 16-bit integer values; the
Packit Service 1d0348
.Va unsigned int
Packit Service 1d0348
fields are 32-bit integer values.
Packit Service 1d0348
The fields are as follows
Packit Service 1d0348
.Bl -tag -width indent
Packit Service 1d0348
.It Va magic
Packit Service 1d0348
The integer value octal 070707.
Packit Service 1d0348
This value can be used to determine whether this archive is
Packit Service 1d0348
written with little-endian or big-endian integers.
Packit Service 1d0348
.It Va dev , Va ino
Packit Service 1d0348
The device and inode numbers from the disk.
Packit Service 1d0348
These are used by programs that read
Packit Service 1d0348
.Nm
Packit Service 1d0348
archives to determine when two entries refer to the same file.
Packit Service 1d0348
Programs that synthesize
Packit Service 1d0348
.Nm
Packit Service 1d0348
archives should be careful to set these to distinct values for each entry.
Packit Service 1d0348
.It Va mode
Packit Service 1d0348
The mode specifies both the regular permissions and the file type.
Packit Service 1d0348
It consists of several bit fields as follows:
Packit Service 1d0348
.Bl -tag -width "MMMMMMM" -compact
Packit Service 1d0348
.It 0170000
Packit Service 1d0348
This masks the file type bits.
Packit Service 1d0348
.It 0140000
Packit Service 1d0348
File type value for sockets.
Packit Service 1d0348
.It 0120000
Packit Service 1d0348
File type value for symbolic links.
Packit Service 1d0348
For symbolic links, the link body is stored as file data.
Packit Service 1d0348
.It 0100000
Packit Service 1d0348
File type value for regular files.
Packit Service 1d0348
.It 0060000
Packit Service 1d0348
File type value for block special devices.
Packit Service 1d0348
.It 0040000
Packit Service 1d0348
File type value for directories.
Packit Service 1d0348
.It 0020000
Packit Service 1d0348
File type value for character special devices.
Packit Service 1d0348
.It 0010000
Packit Service 1d0348
File type value for named pipes or FIFOs.
Packit Service 1d0348
.It 0004000
Packit Service 1d0348
SUID bit.
Packit Service 1d0348
.It 0002000
Packit Service 1d0348
SGID bit.
Packit Service 1d0348
.It 0001000
Packit Service 1d0348
Sticky bit.
Packit Service 1d0348
On some systems, this modifies the behavior of executables and/or directories.
Packit Service 1d0348
.It 0000777
Packit Service 1d0348
The lower 9 bits specify read/write/execute permissions
Packit Service 1d0348
for world, group, and user following standard POSIX conventions.
Packit Service 1d0348
.El
Packit Service 1d0348
.It Va uid , Va gid
Packit Service 1d0348
The numeric user id and group id of the owner.
Packit Service 1d0348
.It Va nlink
Packit Service 1d0348
The number of links to this file.
Packit Service 1d0348
Directories always have a value of at least two here.
Packit Service 1d0348
Note that hardlinked files include file data with every copy in the archive.
Packit Service 1d0348
.It Va rdev
Packit Service 1d0348
For block special and character special entries,
Packit Service 1d0348
this field contains the associated device number.
Packit Service 1d0348
For all other entry types, it should be set to zero by writers
Packit Service 1d0348
and ignored by readers.
Packit Service 1d0348
.It Va mtime
Packit Service 1d0348
Modification time of the file, indicated as the number
Packit Service 1d0348
of seconds since the start of the epoch,
Packit Service 1d0348
00:00:00 UTC January 1, 1970.
Packit Service 1d0348
The four-byte integer is stored with the most-significant 16 bits first
Packit Service 1d0348
followed by the least-significant 16 bits.
Packit Service 1d0348
Each of the two 16 bit values are stored in machine-native byte order.
Packit Service 1d0348
.It Va namesize
Packit Service 1d0348
The number of bytes in the pathname that follows the header.
Packit Service 1d0348
This count includes the trailing NUL byte.
Packit Service 1d0348
.It Va filesize
Packit Service 1d0348
The size of the file.
Packit Service 1d0348
Note that this archive format is limited to
Packit Service 1d0348
four gigabyte file sizes.
Packit Service 1d0348
See
Packit Service 1d0348
.Va mtime
Packit Service 1d0348
above for a description of the storage of four-byte integers.
Packit Service 1d0348
.El
Packit Service 1d0348
.Pp
Packit Service 1d0348
The pathname immediately follows the fixed header.
Packit Service 1d0348
If the
Packit Service 1d0348
.Cm namesize
Packit Service 1d0348
is odd, an additional NUL byte is added after the pathname.
Packit Service 1d0348
The file data is then appended, padded with NUL
Packit Service 1d0348
bytes to an even length.
Packit Service 1d0348
.Pp
Packit Service 1d0348
Hardlinked files are not given special treatment;
Packit Service 1d0348
the full file contents are included with each copy of the
Packit Service 1d0348
file.
Packit Service 1d0348
.Ss Portable ASCII Format
Packit Service 1d0348
.St -susv2
Packit Service 1d0348
standardized an ASCII variant that is portable across all
Packit Service 1d0348
platforms.
Packit Service 1d0348
It is commonly known as the
Packit Service 1d0348
.Dq old character
Packit Service 1d0348
format or as the
Packit Service 1d0348
.Dq odc
Packit Service 1d0348
format.
Packit Service 1d0348
It stores the same numeric fields as the old binary format, but
Packit Service 1d0348
represents them as 6-character or 11-character octal values.
Packit Service 1d0348
.Bd -literal -offset indent
Packit Service 1d0348
struct cpio_odc_header {
Packit Service 1d0348
        char    c_magic[6];
Packit Service 1d0348
        char    c_dev[6];
Packit Service 1d0348
        char    c_ino[6];
Packit Service 1d0348
        char    c_mode[6];
Packit Service 1d0348
        char    c_uid[6];
Packit Service 1d0348
        char    c_gid[6];
Packit Service 1d0348
        char    c_nlink[6];
Packit Service 1d0348
        char    c_rdev[6];
Packit Service 1d0348
        char    c_mtime[11];
Packit Service 1d0348
        char    c_namesize[6];
Packit Service 1d0348
        char    c_filesize[11];
Packit Service 1d0348
};
Packit Service 1d0348
.Ed
Packit Service 1d0348
.Pp
Packit Service 1d0348
The fields are identical to those in the old binary format.
Packit Service 1d0348
The name and file body follow the fixed header.
Packit Service 1d0348
Unlike the old binary format, there is no additional padding
Packit Service 1d0348
after the pathname or file contents.
Packit Service 1d0348
If the files being archived are themselves entirely ASCII, then
Packit Service 1d0348
the resulting archive will be entirely ASCII, except for the
Packit Service 1d0348
NUL byte that terminates the name field.
Packit Service 1d0348
.Ss New ASCII Format
Packit Service 1d0348
The "new" ASCII format uses 8-byte hexadecimal fields for
Packit Service 1d0348
all numbers and separates device numbers into separate fields
Packit Service 1d0348
for major and minor numbers.
Packit Service 1d0348
.Bd -literal -offset indent
Packit Service 1d0348
struct cpio_newc_header {
Packit Service 1d0348
        char    c_magic[6];
Packit Service 1d0348
        char    c_ino[8];
Packit Service 1d0348
        char    c_mode[8];
Packit Service 1d0348
        char    c_uid[8];
Packit Service 1d0348
        char    c_gid[8];
Packit Service 1d0348
        char    c_nlink[8];
Packit Service 1d0348
        char    c_mtime[8];
Packit Service 1d0348
        char    c_filesize[8];
Packit Service 1d0348
        char    c_devmajor[8];
Packit Service 1d0348
        char    c_devminor[8];
Packit Service 1d0348
        char    c_rdevmajor[8];
Packit Service 1d0348
        char    c_rdevminor[8];
Packit Service 1d0348
        char    c_namesize[8];
Packit Service 1d0348
        char    c_check[8];
Packit Service 1d0348
};
Packit Service 1d0348
.Ed
Packit Service 1d0348
.Pp
Packit Service 1d0348
Except as specified below, the fields here match those specified
Packit Service 1d0348
for the old binary format above.
Packit Service 1d0348
.Bl -tag -width indent
Packit Service 1d0348
.It Va magic
Packit Service 1d0348
The string
Packit Service 1d0348
.Dq 070701 .
Packit Service 1d0348
.It Va check
Packit Service 1d0348
This field is always set to zero by writers and ignored by readers.
Packit Service 1d0348
See the next section for more details.
Packit Service 1d0348
.El
Packit Service 1d0348
.Pp
Packit Service 1d0348
The pathname is followed by NUL bytes so that the total size
Packit Service 1d0348
of the fixed header plus pathname is a multiple of four.
Packit Service 1d0348
Likewise, the file data is padded to a multiple of four bytes.
Packit Service 1d0348
Note that this format supports only 4 gigabyte files (unlike the
Packit Service 1d0348
older ASCII format, which supports 8 gigabyte files).
Packit Service 1d0348
.Pp
Packit Service 1d0348
In this format, hardlinked files are handled by setting the
Packit Service 1d0348
filesize to zero for each entry except the last one that
Packit Service 1d0348
appears in the archive.
Packit Service 1d0348
.Ss New CRC Format
Packit Service 1d0348
The CRC format is identical to the new ASCII format described
Packit Service 1d0348
in the previous section except that the magic field is set
Packit Service 1d0348
to
Packit Service 1d0348
.Dq 070702
Packit Service 1d0348
and the
Packit Service 1d0348
.Va check
Packit Service 1d0348
field is set to the sum of all bytes in the file data.
Packit Service 1d0348
This sum is computed treating all bytes as unsigned values
Packit Service 1d0348
and using unsigned arithmetic.
Packit Service 1d0348
Only the least-significant 32 bits of the sum are stored.
Packit Service 1d0348
.Ss HP variants
Packit Service 1d0348
The
Packit Service 1d0348
.Nm cpio
Packit Service 1d0348
implementation distributed with HPUX used XXXX but stored
Packit Service 1d0348
device numbers differently XXX.
Packit Service 1d0348
.Ss Other Extensions and Variants
Packit Service 1d0348
Sun Solaris uses additional file types to store extended file
Packit Service 1d0348
data, including ACLs and extended attributes, as special
Packit Service 1d0348
entries in cpio archives.
Packit Service 1d0348
.Pp
Packit Service 1d0348
XXX Others? XXX
Packit Service 1d0348
.Sh SEE ALSO
Packit Service 1d0348
.Xr cpio 1 ,
Packit Service 1d0348
.Xr tar 5
Packit Service 1d0348
.Sh STANDARDS
Packit Service 1d0348
The
Packit Service 1d0348
.Nm cpio
Packit Service 1d0348
utility is no longer a part of POSIX or the Single Unix Standard.
Packit Service 1d0348
It last appeared in
Packit Service 1d0348
.St -susv2 .
Packit Service 1d0348
It has been supplanted in subsequent standards by
Packit Service 1d0348
.Xr pax 1 .
Packit Service 1d0348
The portable ASCII format is currently part of the specification for the
Packit Service 1d0348
.Xr pax 1
Packit Service 1d0348
utility.
Packit Service 1d0348
.Sh HISTORY
Packit Service 1d0348
The original cpio utility was written by Dick Haight
Packit Service 1d0348
while working in AT&T's Unix Support Group.
Packit Service 1d0348
It appeared in 1977 as part of PWB/UNIX 1.0, the
Packit Service 1d0348
.Dq Programmer's Work Bench
Packit Service 1d0348
derived from
Packit Service 1d0348
.At v6
Packit Service 1d0348
that was used internally at AT&T.
Packit Service 1d0348
Both the old binary and old character formats were in use
Packit Service 1d0348
by 1980, according to the System III source released
Packit Service 1d0348
by SCO under their
Packit Service 1d0348
.Dq Ancient Unix
Packit Service 1d0348
license.
Packit Service 1d0348
The character format was adopted as part of
Packit Service 1d0348
.St -p1003.1-88 .
Packit Service 1d0348
XXX when did "newc" appear?  Who invented it?  When did HP come out with their variant?  When did Sun introduce ACLs and extended attributes? XXX
Packit Service 1d0348
.Sh BUGS
Packit Service 1d0348
The
Packit Service 1d0348
.Dq CRC
Packit Service 1d0348
format is mis-named, as it uses a simple checksum and
Packit Service 1d0348
not a cyclic redundancy check.
Packit Service 1d0348
.Pp
Packit Service 1d0348
The old binary format is limited to 16 bits for user id,
Packit Service 1d0348
group id, device, and inode numbers.
Packit Service 1d0348
It is limited to 4 gigabyte file sizes.
Packit Service 1d0348
.Pp
Packit Service 1d0348
The old ASCII format is limited to 18 bits for
Packit Service 1d0348
the user id, group id, device, and inode numbers.
Packit Service 1d0348
It is limited to 8 gigabyte file sizes.
Packit Service 1d0348
.Pp
Packit Service 1d0348
The new ASCII format is limited to 4 gigabyte file sizes.
Packit Service 1d0348
.Pp
Packit Service 1d0348
None of the cpio formats store user or group names,
Packit Service 1d0348
which are essential when moving files between systems with
Packit Service 1d0348
dissimilar user or group numbering.
Packit Service 1d0348
.Pp
Packit Service 1d0348
Especially when writing older cpio variants, it may be necessary
Packit Service 1d0348
to map actual device/inode values to synthesized values that
Packit Service 1d0348
fit the available fields.
Packit Service 1d0348
With very large filesystems, this may be necessary even for
Packit Service 1d0348
the newer formats.