summaryrefslogtreecommitdiffstats
path: root/lib/libarchive/cpio.5
blob: 02077d65120db8e470ce96d2cafb953fe67f6d5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
.\" Copyright (c) 2007 Tim Kientzle
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd October 5, 2007
.Dt CPIO 5
.Os
.Sh NAME
.Nm cpio
.Nd format of cpio archive files
.Sh DESCRIPTION
The
.Nm
archive format collects any number of files, directories, and other
file system objects (symbolic links, device nodes, etc.) into a single
stream of bytes.
.Ss General Format
Each file system object in a
.Nm
archive comprises a header record with basic numeric metadata
followed by the full pathname of the entry and the file data.
The header record stores a series of integer values that generally
follow the fields in
.Va struct stat .
(See
.Xr stat 2
for details.)
The variants differ primarily in how they store those integers
(binary, octal, or hexadecimal).
The header is followed by the pathname of the
entry (the length of the pathname is stored in the header)
and any file data.
The end of the archive is indicated by a special record with
the pathname
.Dq TRAILER!!! .
.Ss PWB format
XXX Any documentation of the original PWB/UNIX 1.0 format? XXX
.Ss Old Binary Format
The old binary
.Nm
format stores numbers as 2-byte and 4-byte binary values.
Each entry begins with a header in the following format:
.Bd -literal -offset indent
struct header_old_cpio {
        unsigned short   c_magic;
        unsigned short   c_dev;
        unsigned short   c_ino;
        unsigned short   c_mode;
        unsigned short   c_uid;
        unsigned short   c_gid;
        unsigned short   c_nlink;
        unsigned short   c_rdev;
	unsigned short   c_mtime[2];
        unsigned short   c_namesize;
	unsigned short   c_filesize[2];
};
.Ed
.Pp
The
.Va unsigned short
fields here are 16-bit integer values; the
.Va unsigned int
fields are 32-bit integer values.
The fields are as follows
.Bl -tag -width indent
.It Va magic
The integer value octal 070707.
This value can be used to determine whether this archive is
written with little-endian or big-endian integers.
.It Va dev , Va ino
The device and inode numbers from the disk.
These are used by programs that read
.Nm
archives to determine when two entries refer to the same file.
Programs that synthesize
.Nm
archives should be careful to set these to distinct values for each entry.
.It Va mode
The mode specifies both the regular permissions and the file type.
It consists of several bit fields as follows:
.Bl -tag -width "MMMMMMM" -compact
.It 0170000
This masks the file type bits.
.It 0140000
File type value for sockets.
.It 0120000
File type value for symbolic links.
For symbolic links, the link body is stored as file data.
.It 0100000
File type value for regular files.
.It 0060000
File type value for block special devices.
.It 0040000
File type value for directories.
.It 0020000
File type value for character special devices.
.It 0010000
File type value for named pipes or FIFOs.
.It 0004000
SUID bit.
.It 0002000
SGID bit.
.It 0001000
Sticky bit.
On some systems, this modifies the behavior of executables and/or directories.
.It 0000777
The lower 9 bits specify read/write/execute permissions
for world, group, and user following standard POSIX conventions.
.El
.It Va uid , Va gid
The numeric user id and group id of the owner.
.It Va nlink
The number of links to this file.
Directories always have a value of at least two here.
Note that hardlinked files include file data with every copy in the archive.
.It Va rdev
For block special and character special entries,
this field contains the associated device number.
For all other entry types, it should be set to zero by writers
and ignored by readers.
.It Va mtime
Modification time of the file, indicated as the number
of seconds since the start of the epoch,
00:00:00 UTC January 1, 1970.
The four-byte integer is stored with the most-significant 16 bits first
followed by the least-significant 16 bits.
Each of the two 16 bit values are stored in machine-native byte order.
.It Va namesize
The number of bytes in the pathname that follows the header.
This count includes the trailing NUL byte.
.It Va filesize
The size of the file.
Note that this archive format is limited to
four gigabyte file sizes.
See
.Va mtime
above for a description of the storage of four-byte integers.
.El
.Pp
The pathname immediately follows the fixed header.
If the
.Cm namesize
is odd, an additional NUL byte is added after the pathname.
The file data is then appended, padded with NUL
bytes to an even length.
.Pp
Hardlinked files are not given special treatment;
the full file contents are included with each copy of the
file.
.Ss Portable ASCII Format
.St -susv2
standardized an ASCII variant that is portable across all
platforms.
It is commonly known as the
.Dq old character
format or as the
.Dq odc
format.
It stores the same numeric fields as the old binary format, but
represents them as 6-character or 11-character octal values.
.Bd -literal -offset indent
struct cpio_odc_header {
        char    c_magic[6];
        char    c_dev[6];
        char    c_ino[6];
        char    c_mode[6];
        char    c_uid[6];
        char    c_gid[6];
        char    c_nlink[6];
        char    c_rdev[6];
        char    c_mtime[11];
        char    c_namesize[6];
        char    c_filesize[11];
};
.Ed
.Pp
The fields are identical to those in the old binary format.
The name and file body follow the fixed header.
Unlike the old binary format, there is no additional padding
after the pathname or file contents.
If the files being archived are themselves entirely ASCII, then
the resulting archive will be entirely ASCII, except for the
NUL byte that terminates the name field.
.Ss New ASCII Format
The "new" ASCII format uses 8-byte hexadecimal fields for
all numbers and separates device numbers into separate fields
for major and minor numbers.
.Bd -literal -offset indent
struct cpio_newc_header {
        char    c_magic[6];
        char    c_ino[8];
        char    c_mode[8];
        char    c_uid[8];
        char    c_gid[8];
        char    c_nlink[8];
        char    c_mtime[8];
        char    c_filesize[8];
        char    c_devmajor[8];
        char    c_devminor[8];
        char    c_rdevmajor[8];
        char    c_rdevminor[8];
        char    c_namesize[8];
        char    c_check[8];
};
.Ed
.Pp
Except as specified below, the fields here match those specified
for the old binary format above.
.Bl -tag -width indent
.It Va magic
The string
.Dq 070701 .
.It Va check
This field is always set to zero by writers and ignored by readers.
See the next section for more details.
.El
.Pp
The pathname is followed by NUL bytes so that the total size
of the fixed header plus pathname is a multiple of four.
Likewise, the file data is padded to a multiple of four bytes.
Note that this format supports only 4 gigabyte files (unlike the
older ASCII format, which supports 8 gigabyte files).
.Pp
In this format, hardlinked files are handled by setting the
filesize to zero for each entry except the last one that
appears in the archive.
.Ss New CRC Format
The CRC format is identical to the new ASCII format described
in the previous section except that the magic field is set
to
.Dq 070702
and the
.Va check
field is set to the sum of all bytes in the file data.
This sum is computed treating all bytes as unsigned values
and using unsigned arithmetic.
Only the least-significant 32 bits of the sum are stored.
.Ss HP variants
The
.Nm cpio
implementation distributed with HPUX used XXXX but stored
device numbers differently XXX.
.Ss Other Extensions and Variants
Sun Solaris uses additional file types to store extended file
data, including ACLs and extended attributes, as special
entries in cpio archives.
.Pp
XXX Others? XXX
.Sh BUGS
The
.Dq CRC
format is mis-named, as it uses a simple checksum and
not a cyclic redundancy check.
.Pp
The old binary format is limited to 16 bits for user id,
group id, device, and inode numbers.
It is limited to 4 gigabyte file sizes.
.Pp
The old ASCII format is limited to 18 bits for
the user id, group id, device, and inode numbers.
It is limited to 8 gigabyte file sizes.
.Pp
The new ASCII format is limited to 4 gigabyte file sizes.
.Pp
None of the cpio formats store user or group names,
which are essential when moving files between systems with
dissimilar user or group numbering.
.Pp
Especially when writing older cpio variants, it may be necessary
to map actual device/inode values to synthesized values that
fit the available fields.
With very large filesystems, this may be necessary even for
the newer formats.
.Sh SEE ALSO
.Xr cpio 1 ,
.Xr tar 5
.Sh STANDARDS
The
.Nm cpio
utility is no longer a part of POSIX or the Single Unix Standard.
It last appeared in
.St -susv2 .
It has been supplanted in subsequent standards by
.Xr pax 1 .
The portable ASCII format is currently part of the specification for the
.Xr pax 1
utility.
.Sh HISTORY
The original cpio utility was written by Dick Haight
while working in AT&T's Unix Support Group.
It appeared in 1977 as part of PWB/UNIX 1.0, the
.Dq Programmer's Work Bench
derived from
.At v6
that was used internally at AT&T.
Both the old binary and old character formats were in use
by 1980, according to the System III source released
by SCO under their
.Dq Ancient Unix
license.
The character format was adopted as part of
.St -p1003.1-88 .
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
OpenPOWER on IntegriCloud