pkgsrc - initial commit
[pkgsrc.git] / archivers / libarchive / files / doc / text / cpio.5
1 CPIO(5)                   FreeBSD File Formats Manual                  CPIO(5)
2
3 NAME
4      cpio -- format of cpio archive files
5
6 DESCRIPTION
7      The cpio archive format collects any number of files, directories, and
8      other file system objects (symbolic links, device nodes, etc.) into a
9      single stream of bytes.
10
11    General Format
12      Each file system object in a cpio archive comprises a header record with
13      basic numeric metadata followed by the full pathname of the entry and the
14      file data.  The header record stores a series of integer values that gen-
15      erally follow the fields in struct stat.  (See stat(2) for details.)  The
16      variants differ primarily in how they store those integers (binary,
17      octal, or hexadecimal).  The header is followed by the pathname of the
18      entry (the length of the pathname is stored in the header) and any file
19      data.  The end of the archive is indicated by a special record with the
20      pathname ``TRAILER!!!''.
21
22    PWB format
23      XXX Any documentation of the original PWB/UNIX 1.0 format? XXX
24
25    Old Binary Format
26      The old binary cpio format stores numbers as 2-byte and 4-byte binary
27      values.  Each entry begins with a header in the following format:
28
29            struct header_old_cpio {
30                    unsigned short   c_magic;
31                    unsigned short   c_dev;
32                    unsigned short   c_ino;
33                    unsigned short   c_mode;
34                    unsigned short   c_uid;
35                    unsigned short   c_gid;
36                    unsigned short   c_nlink;
37                    unsigned short   c_rdev;
38                    unsigned short   c_mtime[2];
39                    unsigned short   c_namesize;
40                    unsigned short   c_filesize[2];
41            };
42
43      The unsigned short fields here are 16-bit integer values; the unsigned
44      int fields are 32-bit integer values.  The fields are as follows
45
46      magic   The integer value octal 070707.  This value can be used to deter-
47              mine whether this archive is written with little-endian or big-
48              endian integers.
49
50      dev, ino
51              The device and inode numbers from the disk.  These are used by
52              programs that read cpio archives to determine when two entries
53              refer to the same file.  Programs that synthesize cpio archives
54              should be careful to set these to distinct values for each entry.
55
56      mode    The mode specifies both the regular permissions and the file
57              type.  It consists of several bit fields as follows:
58              0170000  This masks the file type bits.
59              0140000  File type value for sockets.
60              0120000  File type value for symbolic links.  For symbolic links,
61                       the link body is stored as file data.
62              0100000  File type value for regular files.
63              0060000  File type value for block special devices.
64              0040000  File type value for directories.
65              0020000  File type value for character special devices.
66              0010000  File type value for named pipes or FIFOs.
67              0004000  SUID bit.
68              0002000  SGID bit.
69              0001000  Sticky bit.  On some systems, this modifies the behavior
70                       of executables and/or directories.
71              0000777  The lower 9 bits specify read/write/execute permissions
72                       for world, group, and user following standard POSIX con-
73                       ventions.
74
75      uid, gid
76              The numeric user id and group id of the owner.
77
78      nlink   The number of links to this file.  Directories always have a
79              value of at least two here.  Note that hardlinked files include
80              file data with every copy in the archive.
81
82      rdev    For block special and character special entries, this field con-
83              tains the associated device number.  For all other entry types,
84              it should be set to zero by writers and ignored by readers.
85
86      mtime   Modification time of the file, indicated as the number of seconds
87              since the start of the epoch, 00:00:00 UTC January 1, 1970.  The
88              four-byte integer is stored with the most-significant 16 bits
89              first followed by the least-significant 16 bits.  Each of the two
90              16 bit values are stored in machine-native byte order.
91
92      namesize
93              The number of bytes in the pathname that follows the header.
94              This count includes the trailing NUL byte.
95
96      filesize
97              The size of the file.  Note that this archive format is limited
98              to four gigabyte file sizes.  See mtime above for a description
99              of the storage of four-byte integers.
100
101      The pathname immediately follows the fixed header.  If the namesize is
102      odd, an additional NUL byte is added after the pathname.  The file data
103      is then appended, padded with NUL bytes to an even length.
104
105      Hardlinked files are not given special treatment; the full file contents
106      are included with each copy of the file.
107
108    Portable ASCII Format
109      Version 2 of the Single UNIX Specification (``SUSv2'') standardized an
110      ASCII variant that is portable across all platforms.  It is commonly
111      known as the ``old character'' format or as the ``odc'' format.  It
112      stores the same numeric fields as the old binary format, but represents
113      them as 6-character or 11-character octal values.
114
115            struct cpio_odc_header {
116                    char    c_magic[6];
117                    char    c_dev[6];
118                    char    c_ino[6];
119                    char    c_mode[6];
120                    char    c_uid[6];
121                    char    c_gid[6];
122                    char    c_nlink[6];
123                    char    c_rdev[6];
124                    char    c_mtime[11];
125                    char    c_namesize[6];
126                    char    c_filesize[11];
127            };
128
129      The fields are identical to those in the old binary format.  The name and
130      file body follow the fixed header.  Unlike the old binary format, there
131      is no additional padding after the pathname or file contents.  If the
132      files being archived are themselves entirely ASCII, then the resulting
133      archive will be entirely ASCII, except for the NUL byte that terminates
134      the name field.
135
136    New ASCII Format
137      The "new" ASCII format uses 8-byte hexadecimal fields for all numbers and
138      separates device numbers into separate fields for major and minor num-
139      bers.
140
141            struct cpio_newc_header {
142                    char    c_magic[6];
143                    char    c_ino[8];
144                    char    c_mode[8];
145                    char    c_uid[8];
146                    char    c_gid[8];
147                    char    c_nlink[8];
148                    char    c_mtime[8];
149                    char    c_filesize[8];
150                    char    c_devmajor[8];
151                    char    c_devminor[8];
152                    char    c_rdevmajor[8];
153                    char    c_rdevminor[8];
154                    char    c_namesize[8];
155                    char    c_check[8];
156            };
157
158      Except as specified below, the fields here match those specified for the
159      old binary format above.
160
161      magic   The string ``070701''.
162
163      check   This field is always set to zero by writers and ignored by read-
164              ers.  See the next section for more details.
165
166      The pathname is followed by NUL bytes so that the total size of the fixed
167      header plus pathname is a multiple of four.  Likewise, the file data is
168      padded to a multiple of four bytes.  Note that this format supports only
169      4 gigabyte files (unlike the older ASCII format, which supports 8 giga-
170      byte files).
171
172      In this format, hardlinked files are handled by setting the filesize to
173      zero for each entry except the last one that appears in the archive.
174
175    New CRC Format
176      The CRC format is identical to the new ASCII format described in the pre-
177      vious section except that the magic field is set to ``070702'' and the
178      check field is set to the sum of all bytes in the file data.  This sum is
179      computed treating all bytes as unsigned values and using unsigned arith-
180      metic.  Only the least-significant 32 bits of the sum are stored.
181
182    HP variants
183      The cpio implementation distributed with HPUX used XXXX but stored device
184      numbers differently XXX.
185
186    Other Extensions and Variants
187      Sun Solaris uses additional file types to store extended file data,
188      including ACLs and extended attributes, as special entries in cpio ar-
189      chives.
190
191      XXX Others? XXX
192
193 BUGS
194      The ``CRC'' format is mis-named, as it uses a simple checksum and not a
195      cyclic redundancy check.
196
197      The old binary format is limited to 16 bits for user id, group id,
198      device, and inode numbers.  It is limited to 4 gigabyte file sizes.
199
200      The old ASCII format is limited to 18 bits for the user id, group id,
201      device, and inode numbers.  It is limited to 8 gigabyte file sizes.
202
203      The new ASCII format is limited to 4 gigabyte file sizes.
204
205      None of the cpio formats store user or group names, which are essential
206      when moving files between systems with dissimilar user or group number-
207      ing.
208
209      Especially when writing older cpio variants, it may be necessary to map
210      actual device/inode values to synthesized values that fit the available
211      fields.  With very large filesystems, this may be necessary even for the
212      newer formats.
213
214 SEE ALSO
215      cpio(1), tar(5)
216
217 STANDARDS
218      The cpio utility is no longer a part of POSIX or the Single Unix Stan-
219      dard.  It last appeared in Version 2 of the Single UNIX Specification
220      (``SUSv2'').  It has been supplanted in subsequent standards by pax(1).
221      The portable ASCII format is currently part of the specification for the
222      pax(1) utility.
223
224 HISTORY
225      The original cpio utility was written by Dick Haight while working in
226      AT&T's Unix Support Group.  It appeared in 1977 as part of PWB/UNIX 1.0,
227      the ``Programmer's Work Bench'' derived from Version 6 AT&T UNIX that was
228      used internally at AT&T.  Both the old binary and old character formats
229      were in use by 1980, according to the System III source released by SCO
230      under their ``Ancient Unix'' license.  The character format was adopted
231      as part of IEEE Std 1003.1-1988 (``POSIX.1'').  XXX when did "newc"
232      appear?  Who invented it?  When did HP come out with their variant?  When
233      did Sun introduce ACLs and extended attributes? XXX
234
235 FreeBSD 6.0                     October 5, 2007                    FreeBSD 6.0