cpio.5 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. .TH CPIO 5 "December 23, 2011" ""
  2. .SH NAME
  3. .ad l
  4. \fB\%cpio\fP
  5. \- format of cpio archive files
  6. .SH DESCRIPTION
  7. .ad l
  8. The
  9. \fB\%cpio\fP
  10. archive format collects any number of files, directories, and other
  11. file system objects (symbolic links, device nodes, etc.) into a single
  12. stream of bytes.
  13. .SS General Format
  14. Each file system object in a
  15. \fB\%cpio\fP
  16. archive comprises a header record with basic numeric metadata
  17. followed by the full pathname of the entry and the file data.
  18. The header record stores a series of integer values that generally
  19. follow the fields in
  20. \fIstruct\fP stat.
  21. (See
  22. \fBstat\fP(2)
  23. for details.)
  24. The variants differ primarily in how they store those integers
  25. (binary, octal, or hexadecimal).
  26. The header is followed by the pathname of the
  27. entry (the length of the pathname is stored in the header)
  28. and any file data.
  29. The end of the archive is indicated by a special record with
  30. the pathname
  31. ``TRAILER!!!''.
  32. .SS PWB format
  33. The PWB binary
  34. \fB\%cpio\fP
  35. format is the original format, when cpio was introduced as part of the
  36. Programmer's Work Bench system, a variant of 6th Edition UNIX. It
  37. stores numbers as 2-byte and 4-byte binary values.
  38. Each entry begins with a header in the following format:
  39. .PP
  40. .RS 4
  41. .nf
  42. struct header_pwb_cpio {
  43. short h_magic;
  44. short h_dev;
  45. short h_ino;
  46. short h_mode;
  47. short h_uid;
  48. short h_gid;
  49. short h_nlink;
  50. short h_majmin;
  51. long h_mtime;
  52. short h_namesize;
  53. long h_filesize;
  54. };
  55. .RE
  56. .PP
  57. The
  58. \fIshort\fP
  59. fields here are 16-bit integer values, while the
  60. \fIlong\fP
  61. fields are 32 bit integers. Since PWB UNIX, like the 6th Edition UNIX
  62. it was based on, only ran on PDP-11 computers, they
  63. are in PDP-endian format, which has little-endian shorts, and
  64. big-endian longs. That is, the long integer whose hexadecimal
  65. representation is 0x12345678 would be stored in four successive bytes
  66. as 0x34, 0x12, 0x78, 0x56.
  67. The fields are as follows:
  68. .RS 5
  69. .TP
  70. \fIh_magic\fP
  71. The integer value octal 070707.
  72. .TP
  73. \fIh_dev\fP, \fIh_ino\fP
  74. The device and inode numbers from the disk.
  75. These are used by programs that read
  76. \fB\%cpio\fP
  77. archives to determine when two entries refer to the same file.
  78. Programs that synthesize
  79. \fB\%cpio\fP
  80. archives should be careful to set these to distinct values for each entry.
  81. .TP
  82. \fIh_mode\fP
  83. The mode specifies both the regular permissions and the file type, and
  84. it also holds a couple of bits that are irrelevant to the cpio format,
  85. because the field is actually a raw copy of the mode field in the inode
  86. representing the file. These are the IALLOC flag, which shows that
  87. the inode entry is in use, and the ILARG flag, which shows that the
  88. file it represents is large enough to have indirect blocks pointers in
  89. the inode.
  90. The mode is decoded as follows:
  91. .PP
  92. .RS 5
  93. .TP
  94. 0100000
  95. IALLOC flag - irrelevant to cpio.
  96. .TP
  97. 0060000
  98. This masks the file type bits.
  99. .TP
  100. 0040000
  101. File type value for directories.
  102. .TP
  103. 0020000
  104. File type value for character special devices.
  105. .TP
  106. 0060000
  107. File type value for block special devices.
  108. .TP
  109. 0010000
  110. ILARG flag - irrelevant to cpio.
  111. .TP
  112. 0004000
  113. SUID bit.
  114. .TP
  115. 0002000
  116. SGID bit.
  117. .TP
  118. 0001000
  119. Sticky bit.
  120. .TP
  121. 0000777
  122. The lower 9 bits specify read/write/execute permissions
  123. for world, group, and user following standard POSIX conventions.
  124. .RE
  125. .TP
  126. \fIh_uid\fP, \fIh_gid\fP
  127. The numeric user id and group id of the owner.
  128. .TP
  129. \fIh_nlink\fP
  130. The number of links to this file.
  131. Directories always have a value of at least two here.
  132. Note that hardlinked files include file data with every copy in the archive.
  133. .TP
  134. \fIh_majmin\fP
  135. For block special and character special entries,
  136. this field contains the associated device number, with the major
  137. number in the high byte, and the minor number in the low byte.
  138. For all other entry types, it should be set to zero by writers
  139. and ignored by readers.
  140. .TP
  141. \fIh_mtime\fP
  142. Modification time of the file, indicated as the number
  143. of seconds since the start of the epoch,
  144. 00:00:00 UTC January 1, 1970.
  145. .TP
  146. \fIh_namesize\fP
  147. The number of bytes in the pathname that follows the header.
  148. This count includes the trailing NUL byte.
  149. .TP
  150. \fIh_filesize\fP
  151. The size of the file. Note that this archive format is limited to 16
  152. megabyte file sizes, because PWB UNIX, like 6th Edition, only used
  153. an unsigned 24 bit integer for the file size internally.
  154. .RE
  155. .PP
  156. The pathname immediately follows the fixed header.
  157. If
  158. \fBh_namesize\fP
  159. is odd, an additional NUL byte is added after the pathname.
  160. The file data is then appended, again with an additional NUL
  161. appended if needed to get the next header at an even offset.
  162. .PP
  163. Hardlinked files are not given special treatment;
  164. the full file contents are included with each copy of the
  165. file.
  166. .SS New Binary Format
  167. The new binary
  168. \fB\%cpio\fP
  169. format showed up when cpio was adopted into late 7th Edition UNIX.
  170. It is exactly like the PWB binary format, described above, except for
  171. three changes:
  172. .PP
  173. First, UNIX now ran on more than one hardware type, so the endianness
  174. of 16 bit integers must be determined by observing the magic number at
  175. the start of the header. The 32 bit integers are still always stored
  176. with the most significant word first, though, so each of those two, in
  177. the struct shown above, was stored as an array of two 16 bit integers,
  178. in the traditional order. Those 16 bit integers, like all the others
  179. in the struct, were accessed using a macro that byte swapped them if
  180. necessary.
  181. .PP
  182. Next, 7th Edition had more file types to store, and the IALLOC and ILARG
  183. flag bits were re-purposed to accommodate these. The revised use of the
  184. various bits is as follows:
  185. .PP
  186. .RS 5
  187. .TP
  188. 0170000
  189. This masks the file type bits.
  190. .TP
  191. 0140000
  192. File type value for sockets.
  193. .TP
  194. 0120000
  195. File type value for symbolic links.
  196. For symbolic links, the link body is stored as file data.
  197. .TP
  198. 0100000
  199. File type value for regular files.
  200. .TP
  201. 0060000
  202. File type value for block special devices.
  203. .TP
  204. 0040000
  205. File type value for directories.
  206. .TP
  207. 0020000
  208. File type value for character special devices.
  209. .TP
  210. 0010000
  211. File type value for named pipes or FIFOs.
  212. .TP
  213. 0004000
  214. SUID bit.
  215. .TP
  216. 0002000
  217. SGID bit.
  218. .TP
  219. 0001000
  220. Sticky bit.
  221. .TP
  222. 0000777
  223. The lower 9 bits specify read/write/execute permissions
  224. for world, group, and user following standard POSIX conventions.
  225. .RE
  226. .PP
  227. Finally, the file size field now represents a signed 32 bit integer in
  228. the underlying file system, so the maximum file size has increased to
  229. 2 gigabytes.
  230. .PP
  231. Note that there is no obvious way to tell which of the two binary
  232. formats an archive uses, other than to see which one makes more
  233. sense. The typical error scenario is that a PWB format archive
  234. unpacked as if it were in the new format will create named sockets
  235. instead of directories, and then fail to unpack files that should
  236. go in those directories. Running
  237. \fIbsdcpio\fP -itv
  238. on an unknown archive will make it obvious which it is: if it's
  239. PWB format, directories will be listed with an 's' instead of
  240. a 'd' as the first character of the mode string, and the larger
  241. files will have a '?' in that position.
  242. .SS Portable ASCII Format
  243. Version 2 of the Single UNIX Specification (``SUSv2'')
  244. standardized an ASCII variant that is portable across all
  245. platforms.
  246. It is commonly known as the
  247. ``old character''
  248. format or as the
  249. ``odc''
  250. format.
  251. It stores the same numeric fields as the old binary format, but
  252. represents them as 6-character or 11-character octal values.
  253. .PP
  254. .RS 4
  255. .nf
  256. struct cpio_odc_header {
  257. char c_magic[6];
  258. char c_dev[6];
  259. char c_ino[6];
  260. char c_mode[6];
  261. char c_uid[6];
  262. char c_gid[6];
  263. char c_nlink[6];
  264. char c_rdev[6];
  265. char c_mtime[11];
  266. char c_namesize[6];
  267. char c_filesize[11];
  268. };
  269. .RE
  270. .PP
  271. The fields are identical to those in the new binary format.
  272. The name and file body follow the fixed header.
  273. Unlike the binary formats, there is no additional padding
  274. after the pathname or file contents.
  275. If the files being archived are themselves entirely ASCII, then
  276. the resulting archive will be entirely ASCII, except for the
  277. NUL byte that terminates the name field.
  278. .SS New ASCII Format
  279. The "new" ASCII format uses 8-byte hexadecimal fields for
  280. all numbers and separates device numbers into separate fields
  281. for major and minor numbers.
  282. .PP
  283. .RS 4
  284. .nf
  285. struct cpio_newc_header {
  286. char c_magic[6];
  287. char c_ino[8];
  288. char c_mode[8];
  289. char c_uid[8];
  290. char c_gid[8];
  291. char c_nlink[8];
  292. char c_mtime[8];
  293. char c_filesize[8];
  294. char c_devmajor[8];
  295. char c_devminor[8];
  296. char c_rdevmajor[8];
  297. char c_rdevminor[8];
  298. char c_namesize[8];
  299. char c_check[8];
  300. };
  301. .RE
  302. .PP
  303. Except as specified below, the fields here match those specified
  304. for the new binary format above.
  305. .RS 5
  306. .TP
  307. \fImagic\fP
  308. The string
  309. ``070701''.
  310. .TP
  311. \fIcheck\fP
  312. This field is always set to zero by writers and ignored by readers.
  313. See the next section for more details.
  314. .RE
  315. .PP
  316. The pathname is followed by NUL bytes so that the total size
  317. of the fixed header plus pathname is a multiple of four.
  318. Likewise, the file data is padded to a multiple of four bytes.
  319. Note that this format supports only 4 gigabyte files (unlike the
  320. older ASCII format, which supports 8 gigabyte files).
  321. .PP
  322. In this format, hardlinked files are handled by setting the
  323. filesize to zero for each entry except the first one that
  324. appears in the archive.
  325. .SS New CRC Format
  326. The CRC format is identical to the new ASCII format described
  327. in the previous section except that the magic field is set
  328. to
  329. ``070702''
  330. and the
  331. \fIcheck\fP
  332. field is set to the sum of all bytes in the file data.
  333. This sum is computed treating all bytes as unsigned values
  334. and using unsigned arithmetic.
  335. Only the least-significant 32 bits of the sum are stored.
  336. .SS HP variants
  337. The
  338. \fB\%cpio\fP
  339. implementation distributed with HPUX used XXXX but stored
  340. device numbers differently XXX.
  341. .SS Other Extensions and Variants
  342. Sun Solaris uses additional file types to store extended file
  343. data, including ACLs and extended attributes, as special
  344. entries in cpio archives.
  345. .PP
  346. XXX Others? XXX
  347. .SH SEE ALSO
  348. .ad l
  349. \fBcpio\fP(1),
  350. \fBtar\fP(5)
  351. .SH STANDARDS
  352. .ad l
  353. The
  354. \fB\%cpio\fP
  355. utility is no longer a part of POSIX or the Single Unix Standard.
  356. It last appeared in
  357. Version 2 of the Single UNIX Specification (``SUSv2'').
  358. It has been supplanted in subsequent standards by
  359. \fBpax\fP(1).
  360. The portable ASCII format is currently part of the specification for the
  361. \fBpax\fP(1)
  362. utility.
  363. .SH HISTORY
  364. .ad l
  365. The original cpio utility was written by Dick Haight
  366. while working in AT&T's Unix Support Group.
  367. It appeared in 1977 as part of PWB/UNIX 1.0, the
  368. ``Programmer's Work Bench''
  369. derived from
  370. At v6
  371. that was used internally at AT&T.
  372. Both the new binary and old character formats were in use
  373. by 1980, according to the System III source released
  374. by SCO under their
  375. ``Ancient Unix''
  376. license.
  377. The character format was adopted as part of
  378. IEEE Std 1003.1-1988 (``POSIX.1'').
  379. 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
  380. .SH BUGS
  381. .ad l
  382. The
  383. ``CRC''
  384. format is mis-named, as it uses a simple checksum and
  385. not a cyclic redundancy check.
  386. .PP
  387. The binary formats are limited to 16 bits for user id, group id,
  388. device, and inode numbers. They are limited to 16 megabyte and 2
  389. gigabyte file sizes for the older and newer variants, respectively.
  390. .PP
  391. The old ASCII format is limited to 18 bits for
  392. the user id, group id, device, and inode numbers.
  393. It is limited to 8 gigabyte file sizes.
  394. .PP
  395. The new ASCII format is limited to 4 gigabyte file sizes.
  396. .PP
  397. None of the cpio formats store user or group names,
  398. which are essential when moving files between systems with
  399. dissimilar user or group numbering.
  400. .PP
  401. Especially when writing older cpio variants, it may be necessary
  402. to map actual device/inode values to synthesized values that
  403. fit the available fields.
  404. With very large filesystems, this may be necessary even for
  405. the newer formats.