tar.5 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  1. .TH TAR 5 "December 27, 2016" ""
  2. .SH NAME
  3. .ad l
  4. \fB\%tar\fP
  5. \- format of tape archive files
  6. .SH DESCRIPTION
  7. .ad l
  8. The
  9. \fB\%tar\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. The format was originally designed to be used with
  14. tape drives that operate with fixed-size blocks, but is widely used as
  15. a general packaging mechanism.
  16. .SS General Format
  17. A
  18. \fB\%tar\fP
  19. archive consists of a series of 512-byte records.
  20. Each file system object requires a header record which stores basic metadata
  21. (pathname, owner, permissions, etc.) and zero or more records containing any
  22. file data.
  23. The end of the archive is indicated by two records consisting
  24. entirely of zero bytes.
  25. .PP
  26. For compatibility with tape drives that use fixed block sizes,
  27. programs that read or write tar files always read or write a fixed
  28. number of records with each I/O operation.
  29. These
  30. ``blocks''
  31. are always a multiple of the record size.
  32. The maximum block size supported by early
  33. implementations was 10240 bytes or 20 records.
  34. This is still the default for most implementations
  35. although block sizes of 1MiB (2048 records) or larger are
  36. commonly used with modern high-speed tape drives.
  37. (Note: the terms
  38. ``block''
  39. and
  40. ``record''
  41. here are not entirely standard; this document follows the
  42. convention established by John Gilmore in documenting
  43. \fB\%pdtar\fP.)
  44. .SS Old-Style Archive Format
  45. The original tar archive format has been extended many times to
  46. include additional information that various implementors found
  47. necessary.
  48. This section describes the variant implemented by the tar command
  49. included in
  50. At v7,
  51. which seems to be the earliest widely-used version of the tar program.
  52. .PP
  53. The header record for an old-style
  54. \fB\%tar\fP
  55. archive consists of the following:
  56. .RS 4
  57. .nf
  58. struct header_old_tar {
  59. char name[100];
  60. char mode[8];
  61. char uid[8];
  62. char gid[8];
  63. char size[12];
  64. char mtime[12];
  65. char checksum[8];
  66. char linkflag[1];
  67. char linkname[100];
  68. char pad[255];
  69. };
  70. .RE
  71. All unused bytes in the header record are filled with nulls.
  72. .RS 5
  73. .TP
  74. \fIname\fP
  75. Pathname, stored as a null-terminated string.
  76. Early tar implementations only stored regular files (including
  77. hardlinks to those files).
  78. One common early convention used a trailing "/" character to indicate
  79. a directory name, allowing directory permissions and owner information
  80. to be archived and restored.
  81. .TP
  82. \fImode\fP
  83. File mode, stored as an octal number in ASCII.
  84. .TP
  85. \fIuid\fP, \fIgid\fP
  86. User id and group id of owner, as octal numbers in ASCII.
  87. .TP
  88. \fIsize\fP
  89. Size of file, as octal number in ASCII.
  90. For regular files only, this indicates the amount of data
  91. that follows the header.
  92. In particular, this field was ignored by early tar implementations
  93. when extracting hardlinks.
  94. Modern writers should always store a zero length for hardlink entries.
  95. .TP
  96. \fImtime\fP
  97. Modification time of file, as an octal number in ASCII.
  98. This indicates the number of seconds since the start of the epoch,
  99. 00:00:00 UTC January 1, 1970.
  100. Note that negative values should be avoided
  101. here, as they are handled inconsistently.
  102. .TP
  103. \fIchecksum\fP
  104. Header checksum, stored as an octal number in ASCII.
  105. To compute the checksum, set the checksum field to all spaces,
  106. then sum all bytes in the header using unsigned arithmetic.
  107. This field should be stored as six octal digits followed by a null and a space
  108. character.
  109. Note that many early implementations of tar used signed arithmetic
  110. for the checksum field, which can cause interoperability problems
  111. when transferring archives between systems.
  112. Modern robust readers compute the checksum both ways and accept the
  113. header if either computation matches.
  114. .TP
  115. \fIlinkflag\fP, \fIlinkname\fP
  116. In order to preserve hardlinks and conserve tape, a file
  117. with multiple links is only written to the archive the first
  118. time it is encountered.
  119. The next time it is encountered, the
  120. \fIlinkflag\fP
  121. is set to an ASCII
  122. Sq 1
  123. and the
  124. \fIlinkname\fP
  125. field holds the first name under which this file appears.
  126. (Note that regular files have a null value in the
  127. \fIlinkflag\fP
  128. field.)
  129. .RE
  130. .PP
  131. Early tar implementations varied in how they terminated these fields.
  132. The tar command in
  133. At v7
  134. used the following conventions (this is also documented in early BSD manpages):
  135. the pathname must be null-terminated;
  136. the mode, uid, and gid fields must end in a space and a null byte;
  137. the size and mtime fields must end in a space;
  138. the checksum is terminated by a null and a space.
  139. Early implementations filled the numeric fields with leading spaces.
  140. This seems to have been common practice until the
  141. IEEE Std 1003.1-1988 (``POSIX.1'')
  142. standard was released.
  143. For best portability, modern implementations should fill the numeric
  144. fields with leading zeros.
  145. .SS Pre-POSIX Archives
  146. An early draft of
  147. IEEE Std 1003.1-1988 (``POSIX.1'')
  148. served as the basis for John Gilmore's
  149. \fB\%pdtar\fP
  150. program and many system implementations from the late 1980s
  151. and early 1990s.
  152. These archives generally follow the POSIX ustar
  153. format described below with the following variations:
  154. .RS 5
  155. .IP \(bu
  156. The magic value consists of the five characters
  157. ``ustar''
  158. followed by a space.
  159. The version field contains a space character followed by a null.
  160. .IP \(bu
  161. The numeric fields are generally filled with leading spaces
  162. (not leading zeros as recommended in the final standard).
  163. .IP \(bu
  164. The prefix field is often not used, limiting pathnames to
  165. the 100 characters of old-style archives.
  166. .RE
  167. .SS POSIX ustar Archives
  168. IEEE Std 1003.1-1988 (``POSIX.1'')
  169. defined a standard tar file format to be read and written
  170. by compliant implementations of
  171. \fBtar\fP(1).
  172. This format is often called the
  173. ``ustar''
  174. format, after the magic value used
  175. in the header.
  176. (The name is an acronym for
  177. ``Unix Standard TAR''.)
  178. It extends the historic format with new fields:
  179. .RS 4
  180. .nf
  181. struct header_posix_ustar {
  182. char name[100];
  183. char mode[8];
  184. char uid[8];
  185. char gid[8];
  186. char size[12];
  187. char mtime[12];
  188. char checksum[8];
  189. char typeflag[1];
  190. char linkname[100];
  191. char magic[6];
  192. char version[2];
  193. char uname[32];
  194. char gname[32];
  195. char devmajor[8];
  196. char devminor[8];
  197. char prefix[155];
  198. char pad[12];
  199. };
  200. .RE
  201. .RS 5
  202. .TP
  203. \fItypeflag\fP
  204. Type of entry.
  205. POSIX extended the earlier
  206. \fIlinkflag\fP
  207. field with several new type values:
  208. .RS 5
  209. .TP
  210. ``0''
  211. Regular file.
  212. NUL should be treated as a synonym, for compatibility purposes.
  213. .TP
  214. ``1''
  215. Hard link.
  216. .TP
  217. ``2''
  218. Symbolic link.
  219. .TP
  220. ``3''
  221. Character device node.
  222. .TP
  223. ``4''
  224. Block device node.
  225. .TP
  226. ``5''
  227. Directory.
  228. .TP
  229. ``6''
  230. FIFO node.
  231. .TP
  232. ``7''
  233. Reserved.
  234. .TP
  235. Other
  236. A POSIX-compliant implementation must treat any unrecognized typeflag value
  237. as a regular file.
  238. In particular, writers should ensure that all entries
  239. have a valid filename so that they can be restored by readers that do not
  240. support the corresponding extension.
  241. Uppercase letters "A" through "Z" are reserved for custom extensions.
  242. Note that sockets and whiteout entries are not archivable.
  243. .RE
  244. It is worth noting that the
  245. \fIsize\fP
  246. field, in particular, has different meanings depending on the type.
  247. For regular files, of course, it indicates the amount of data
  248. following the header.
  249. For directories, it may be used to indicate the total size of all
  250. files in the directory, for use by operating systems that pre-allocate
  251. directory space.
  252. For all other types, it should be set to zero by writers and ignored
  253. by readers.
  254. .TP
  255. \fImagic\fP
  256. Contains the magic value
  257. ``ustar''
  258. followed by a NUL byte to indicate that this is a POSIX standard archive.
  259. Full compliance requires the uname and gname fields be properly set.
  260. .TP
  261. \fIversion\fP
  262. Version.
  263. This should be
  264. ``00''
  265. (two copies of the ASCII digit zero) for POSIX standard archives.
  266. .TP
  267. \fIuname\fP, \fIgname\fP
  268. User and group names, as null-terminated ASCII strings.
  269. These should be used in preference to the uid/gid values
  270. when they are set and the corresponding names exist on
  271. the system.
  272. .TP
  273. \fIdevmajor\fP, \fIdevminor\fP
  274. Major and minor numbers for character device or block device entry.
  275. .TP
  276. \fIname\fP, \fIprefix\fP
  277. If the pathname is too long to fit in the 100 bytes provided by the standard
  278. format, it can be split at any
  279. \fI/\fP
  280. character with the first portion going into the prefix field.
  281. If the prefix field is not empty, the reader will prepend
  282. the prefix value and a
  283. \fI/\fP
  284. character to the regular name field to obtain the full pathname.
  285. The standard does not require a trailing
  286. \fI/\fP
  287. character on directory names, though most implementations still
  288. include this for compatibility reasons.
  289. .RE
  290. .PP
  291. Note that all unused bytes must be set to
  292. .BR NUL.
  293. .PP
  294. Field termination is specified slightly differently by POSIX
  295. than by previous implementations.
  296. The
  297. \fImagic\fP,
  298. \fIuname\fP,
  299. and
  300. \fIgname\fP
  301. fields must have a trailing
  302. .BR NUL.
  303. The
  304. \fIpathname\fP,
  305. \fIlinkname\fP,
  306. and
  307. \fIprefix\fP
  308. fields must have a trailing
  309. .BR NUL
  310. unless they fill the entire field.
  311. (In particular, it is possible to store a 256-character pathname if it
  312. happens to have a
  313. \fI/\fP
  314. as the 156th character.)
  315. POSIX requires numeric fields to be zero-padded in the front, and requires
  316. them to be terminated with either space or
  317. .BR NUL
  318. characters.
  319. .PP
  320. Currently, most tar implementations comply with the ustar
  321. format, occasionally extending it by adding new fields to the
  322. blank area at the end of the header record.
  323. .SS Numeric Extensions
  324. There have been several attempts to extend the range of sizes
  325. or times supported by modifying how numbers are stored in the
  326. header.
  327. .PP
  328. One obvious extension to increase the size of files is to
  329. eliminate the terminating characters from the various
  330. numeric fields.
  331. For example, the standard only allows the size field to contain
  332. 11 octal digits, reserving the twelfth byte for a trailing
  333. NUL character.
  334. Allowing 12 octal digits allows file sizes up to 64 GB.
  335. .PP
  336. Another extension, utilized by GNU tar, star, and other newer
  337. \fB\%tar\fP
  338. implementations, permits binary numbers in the standard numeric fields.
  339. This is flagged by setting the high bit of the first byte.
  340. The remainder of the field is treated as a signed twos-complement
  341. value.
  342. This permits 95-bit values for the length and time fields
  343. and 63-bit values for the uid, gid, and device numbers.
  344. In particular, this provides a consistent way to handle
  345. negative time values.
  346. GNU tar supports this extension for the
  347. length, mtime, ctime, and atime fields.
  348. Joerg Schilling's star program and the libarchive library support
  349. this extension for all numeric fields.
  350. Note that this extension is largely obsoleted by the extended
  351. attribute record provided by the pax interchange format.
  352. .PP
  353. Another early GNU extension allowed base-64 values rather than octal.
  354. This extension was short-lived and is no longer supported by any
  355. implementation.
  356. .SS Pax Interchange Format
  357. There are many attributes that cannot be portably stored in a
  358. POSIX ustar archive.
  359. IEEE Std 1003.1-2001 (``POSIX.1'')
  360. defined a
  361. ``pax interchange format''
  362. that uses two new types of entries to hold text-formatted
  363. metadata that applies to following entries.
  364. Note that a pax interchange format archive is a ustar archive in every
  365. respect.
  366. The new data is stored in ustar-compatible archive entries that use the
  367. ``x''
  368. or
  369. ``g''
  370. typeflag.
  371. In particular, older implementations that do not fully support these
  372. extensions will extract the metadata into regular files, where the
  373. metadata can be examined as necessary.
  374. .PP
  375. An entry in a pax interchange format archive consists of one or
  376. two standard ustar entries, each with its own header and data.
  377. The first optional entry stores the extended attributes
  378. for the following entry.
  379. This optional first entry has an "x" typeflag and a size field that
  380. indicates the total size of the extended attributes.
  381. The extended attributes themselves are stored as a series of text-format
  382. lines encoded in the portable UTF-8 encoding.
  383. Each line consists of a decimal number, a space, a key string, an equals
  384. sign, a value string, and a new line.
  385. The decimal number indicates the length of the entire line, including the
  386. initial length field and the trailing newline.
  387. An example of such a field is:
  388. .RS 4
  389. 25 ctime=1084839148.1212\en
  390. .RE
  391. Keys in all lowercase are standard keys.
  392. Vendors can add their own keys by prefixing them with an all uppercase
  393. vendor name and a period.
  394. Note that, unlike the historic header, numeric values are stored using
  395. decimal, not octal.
  396. A description of some common keys follows:
  397. .RS 5
  398. .TP
  399. \fBatime\fP, \fBctime\fP, \fBmtime\fP
  400. File access, inode change, and modification times.
  401. These fields can be negative or include a decimal point and a fractional value.
  402. .TP
  403. \fBhdrcharset\fP
  404. The character set used by the pax extension values.
  405. By default, all textual values in the pax extended attributes
  406. are assumed to be in UTF-8, including pathnames, user names,
  407. and group names.
  408. In some cases, it is not possible to translate local
  409. conventions into UTF-8.
  410. If this key is present and the value is the six-character ASCII string
  411. ``BINARY'',
  412. then all textual values are assumed to be in a platform-dependent
  413. multi-byte encoding.
  414. Note that there are only two valid values for this key:
  415. ``BINARY''
  416. or
  417. ``ISO-IR\ 10646\ 2000\ UTF-8''.
  418. No other values are permitted by the standard, and
  419. the latter value should generally not be used as it is the
  420. default when this key is not specified.
  421. In particular, this flag should not be used as a general
  422. mechanism to allow filenames to be stored in arbitrary
  423. encodings.
  424. .TP
  425. \fBuname\fP, \fBuid\fP, \fBgname\fP, \fBgid\fP
  426. User name, group name, and numeric UID and GID values.
  427. The user name and group name stored here are encoded in UTF8
  428. and can thus include non-ASCII characters.
  429. The UID and GID fields can be of arbitrary length.
  430. .TP
  431. \fBlinkpath\fP
  432. The full path of the linked-to file.
  433. Note that this is encoded in UTF8 and can thus include non-ASCII characters.
  434. .TP
  435. \fBpath\fP
  436. The full pathname of the entry.
  437. Note that this is encoded in UTF8 and can thus include non-ASCII characters.
  438. .TP
  439. \fBrealtime.*\fP, \fBsecurity.*\fP
  440. These keys are reserved and may be used for future standardization.
  441. .TP
  442. \fBsize\fP
  443. The size of the file.
  444. Note that there is no length limit on this field, allowing conforming
  445. archives to store files much larger than the historic 8GB limit.
  446. .TP
  447. \fBSCHILY.*\fP
  448. Vendor-specific attributes used by Joerg Schilling's
  449. \fB\%star\fP
  450. implementation.
  451. .TP
  452. \fBSCHILY.acl.access\fP, \fBSCHILY.acl.default\fP, \fBSCHILY.acl.ace\fP
  453. Stores the access, default and NFSv4 ACLs as textual strings in a format
  454. that is an extension of the format specified by POSIX.1e draft 17.
  455. In particular, each user or group access specification can include
  456. an additional colon-separated field with the numeric UID or GID.
  457. This allows ACLs to be restored on systems that may not have complete
  458. user or group information available (such as when NIS/YP or LDAP services
  459. are temporarily unavailable).
  460. .TP
  461. \fBSCHILY.devminor\fP, \fBSCHILY.devmajor\fP
  462. The full minor and major numbers for device nodes.
  463. .TP
  464. \fBSCHILY.fflags\fP
  465. The file flags.
  466. .TP
  467. \fBSCHILY.realsize\fP
  468. The full size of the file on disk.
  469. XXX explain? XXX
  470. .TP
  471. \fBSCHILY.dev\fP, \fBSCHILY.ino\fP, \fBSCHILY.nlinks\fP
  472. The device number, inode number, and link count for the entry.
  473. In particular, note that a pax interchange format archive using Joerg
  474. Schilling's
  475. \fBSCHILY.*\fP
  476. extensions can store all of the data from
  477. \fIstruct\fP stat.
  478. .TP
  479. \fBLIBARCHIVE.*\fP
  480. Vendor-specific attributes used by the
  481. \fB\%libarchive\fP
  482. library and programs that use it.
  483. .TP
  484. \fBLIBARCHIVE.creationtime\fP
  485. The time when the file was created.
  486. (This should not be confused with the POSIX
  487. ``ctime''
  488. attribute, which refers to the time when the file
  489. metadata was last changed.)
  490. .TP
  491. \fBLIBARCHIVE.xattr\fP. \fInamespace\fP. \fIkey\fP
  492. Libarchive stores POSIX.1e-style extended attributes using
  493. keys of this form.
  494. The
  495. \fIkey\fP
  496. value is URL-encoded:
  497. All non-ASCII characters and the two special characters
  498. ``=''
  499. and
  500. ``%''
  501. are encoded as
  502. ``%''
  503. followed by two uppercase hexadecimal digits.
  504. The value of this key is the extended attribute value
  505. encoded in base 64.
  506. XXX Detail the base-64 format here XXX
  507. .TP
  508. \fBVENDOR.*\fP
  509. XXX document other vendor-specific extensions XXX
  510. .RE
  511. .PP
  512. Any values stored in an extended attribute override the corresponding
  513. values in the regular tar header.
  514. Note that compliant readers should ignore the regular fields when they
  515. are overridden.
  516. This is important, as existing archivers are known to store non-compliant
  517. values in the standard header fields in this situation.
  518. There are no limits on length for any of these fields.
  519. In particular, numeric fields can be arbitrarily large.
  520. All text fields are encoded in UTF8.
  521. Compliant writers should store only portable 7-bit ASCII characters in
  522. the standard ustar header and use extended
  523. attributes whenever a text value contains non-ASCII characters.
  524. .PP
  525. In addition to the
  526. \fBx\fP
  527. entry described above, the pax interchange format
  528. also supports a
  529. \fBg\fP
  530. entry.
  531. The
  532. \fBg\fP
  533. entry is identical in format, but specifies attributes that serve as
  534. defaults for all subsequent archive entries.
  535. The
  536. \fBg\fP
  537. entry is not widely used.
  538. .PP
  539. Besides the new
  540. \fBx\fP
  541. and
  542. \fBg\fP
  543. entries, the pax interchange format has a few other minor variations
  544. from the earlier ustar format.
  545. The most troubling one is that hardlinks are permitted to have
  546. data following them.
  547. This allows readers to restore any hardlink to a file without
  548. having to rewind the archive to find an earlier entry.
  549. However, it creates complications for robust readers, as it is no longer
  550. clear whether or not they should ignore the size field for hardlink entries.
  551. .SS GNU Tar Archives
  552. The GNU tar program started with a pre-POSIX format similar to that
  553. described earlier and has extended it using several different mechanisms:
  554. It added new fields to the empty space in the header (some of which was later
  555. used by POSIX for conflicting purposes);
  556. it allowed the header to be continued over multiple records;
  557. and it defined new entries that modify following entries
  558. (similar in principle to the
  559. \fBx\fP
  560. entry described above, but each GNU special entry is single-purpose,
  561. unlike the general-purpose
  562. \fBx\fP
  563. entry).
  564. As a result, GNU tar archives are not POSIX compatible, although
  565. more lenient POSIX-compliant readers can successfully extract most
  566. GNU tar archives.
  567. .RS 4
  568. .nf
  569. struct header_gnu_tar {
  570. char name[100];
  571. char mode[8];
  572. char uid[8];
  573. char gid[8];
  574. char size[12];
  575. char mtime[12];
  576. char checksum[8];
  577. char typeflag[1];
  578. char linkname[100];
  579. char magic[6];
  580. char version[2];
  581. char uname[32];
  582. char gname[32];
  583. char devmajor[8];
  584. char devminor[8];
  585. char atime[12];
  586. char ctime[12];
  587. char offset[12];
  588. char longnames[4];
  589. char unused[1];
  590. struct {
  591. char offset[12];
  592. char numbytes[12];
  593. } sparse[4];
  594. char isextended[1];
  595. char realsize[12];
  596. char pad[17];
  597. };
  598. .RE
  599. .RS 5
  600. .TP
  601. \fItypeflag\fP
  602. GNU tar uses the following special entry types, in addition to
  603. those defined by POSIX:
  604. .RS 5
  605. .TP
  606. 7
  607. GNU tar treats type "7" records identically to type "0" records,
  608. except on one obscure RTOS where they are used to indicate the
  609. pre-allocation of a contiguous file on disk.
  610. .TP
  611. D
  612. This indicates a directory entry.
  613. Unlike the POSIX-standard "5"
  614. typeflag, the header is followed by data records listing the names
  615. of files in this directory.
  616. Each name is preceded by an ASCII "Y"
  617. if the file is stored in this archive or "N" if the file is not
  618. stored in this archive.
  619. Each name is terminated with a null, and
  620. an extra null marks the end of the name list.
  621. The purpose of this
  622. entry is to support incremental backups; a program restoring from
  623. such an archive may wish to delete files on disk that did not exist
  624. in the directory when the archive was made.
  625. .PP
  626. Note that the "D" typeflag specifically violates POSIX, which requires
  627. that unrecognized typeflags be restored as normal files.
  628. In this case, restoring the "D" entry as a file could interfere
  629. with subsequent creation of the like-named directory.
  630. .TP
  631. K
  632. The data for this entry is a long linkname for the following regular entry.
  633. .TP
  634. L
  635. The data for this entry is a long pathname for the following regular entry.
  636. .TP
  637. M
  638. This is a continuation of the last file on the previous volume.
  639. GNU multi-volume archives guarantee that each volume begins with a valid
  640. entry header.
  641. To ensure this, a file may be split, with part stored at the end of one volume,
  642. and part stored at the beginning of the next volume.
  643. The "M" typeflag indicates that this entry continues an existing file.
  644. Such entries can only occur as the first or second entry
  645. in an archive (the latter only if the first entry is a volume label).
  646. The
  647. \fIsize\fP
  648. field specifies the size of this entry.
  649. The
  650. \fIoffset\fP
  651. field at bytes 369-380 specifies the offset where this file fragment
  652. begins.
  653. The
  654. \fIrealsize\fP
  655. field specifies the total size of the file (which must equal
  656. \fIsize\fP
  657. plus
  658. \fIoffset\fP).
  659. When extracting, GNU tar checks that the header file name is the one it is
  660. expecting, that the header offset is in the correct sequence, and that
  661. the sum of offset and size is equal to realsize.
  662. .TP
  663. N
  664. Type "N" records are no longer generated by GNU tar.
  665. They contained a
  666. list of files to be renamed or symlinked after extraction; this was
  667. originally used to support long names.
  668. The contents of this record
  669. are a text description of the operations to be done, in the form
  670. ``Rename %s to %s\en''
  671. or
  672. ``Symlink %s to %s\en ;''
  673. in either case, both
  674. filenames are escaped using K&R C syntax.
  675. Due to security concerns, "N" records are now generally ignored
  676. when reading archives.
  677. .TP
  678. S
  679. This is a
  680. ``sparse''
  681. regular file.
  682. Sparse files are stored as a series of fragments.
  683. The header contains a list of fragment offset/length pairs.
  684. If more than four such entries are required, the header is
  685. extended as necessary with
  686. ``extra''
  687. header extensions (an older format that is no longer used), or
  688. ``sparse''
  689. extensions.
  690. .TP
  691. V
  692. The
  693. \fIname\fP
  694. field should be interpreted as a tape/volume header name.
  695. This entry should generally be ignored on extraction.
  696. .RE
  697. .TP
  698. \fImagic\fP
  699. The magic field holds the five characters
  700. ``ustar''
  701. followed by a space.
  702. Note that POSIX ustar archives have a trailing null.
  703. .TP
  704. \fIversion\fP
  705. The version field holds a space character followed by a null.
  706. Note that POSIX ustar archives use two copies of the ASCII digit
  707. ``0''.
  708. .TP
  709. \fIatime\fP, \fIctime\fP
  710. The time the file was last accessed and the time of
  711. last change of file information, stored in octal as with
  712. \fImtime\fP.
  713. .TP
  714. \fIlongnames\fP
  715. This field is apparently no longer used.
  716. .TP
  717. Sparse \fIoffset\fP / \fInumbytes\fP
  718. Each such structure specifies a single fragment of a sparse
  719. file.
  720. The two fields store values as octal numbers.
  721. The fragments are each padded to a multiple of 512 bytes
  722. in the archive.
  723. On extraction, the list of fragments is collected from the
  724. header (including any extension headers), and the data
  725. is then read and written to the file at appropriate offsets.
  726. .TP
  727. \fIisextended\fP
  728. If this is set to non-zero, the header will be followed by additional
  729. ``sparse header''
  730. records.
  731. Each such record contains information about as many as 21 additional
  732. sparse blocks as shown here:
  733. .RS 4
  734. .nf
  735. struct gnu_sparse_header {
  736. struct {
  737. char offset[12];
  738. char numbytes[12];
  739. } sparse[21];
  740. char isextended[1];
  741. char padding[7];
  742. };
  743. .RE
  744. .TP
  745. \fIrealsize\fP
  746. A binary representation of the file's complete size, with a much larger range
  747. than the POSIX file size.
  748. In particular, with
  749. \fBM\fP
  750. type files, the current entry is only a portion of the file.
  751. In that case, the POSIX size field will indicate the size of this
  752. entry; the
  753. \fIrealsize\fP
  754. field will indicate the total size of the file.
  755. .RE
  756. .SS GNU tar pax archives
  757. GNU tar 1.14 (XXX check this XXX) and later will write
  758. pax interchange format archives when you specify the
  759. \fB\--posix\fP
  760. flag.
  761. This format follows the pax interchange format closely,
  762. using some
  763. \fBSCHILY\fP
  764. tags and introducing new keywords to store sparse file information.
  765. There have been three iterations of the sparse file support, referred to
  766. as
  767. ``0.0'',
  768. ``0.1'',
  769. and
  770. ``1.0''.
  771. .RS 5
  772. .TP
  773. \fBGNU.sparse.numblocks\fP, \fBGNU.sparse.offset\fP, \fBGNU.sparse.numbytes\fP, \fBGNU.sparse.size\fP
  774. The
  775. ``0.0''
  776. format used an initial
  777. \fBGNU.sparse.numblocks\fP
  778. attribute to indicate the number of blocks in the file, a pair of
  779. \fBGNU.sparse.offset\fP
  780. and
  781. \fBGNU.sparse.numbytes\fP
  782. to indicate the offset and size of each block,
  783. and a single
  784. \fBGNU.sparse.size\fP
  785. to indicate the full size of the file.
  786. This is not the same as the size in the tar header because the
  787. latter value does not include the size of any holes.
  788. This format required that the order of attributes be preserved and
  789. relied on readers accepting multiple appearances of the same attribute
  790. names, which is not officially permitted by the standards.
  791. .TP
  792. \fBGNU.sparse.map\fP
  793. The
  794. ``0.1''
  795. format used a single attribute that stored a comma-separated
  796. list of decimal numbers.
  797. Each pair of numbers indicated the offset and size, respectively,
  798. of a block of data.
  799. This does not work well if the archive is extracted by an archiver
  800. that does not recognize this extension, since many pax implementations
  801. simply discard unrecognized attributes.
  802. .TP
  803. \fBGNU.sparse.major\fP, \fBGNU.sparse.minor\fP, \fBGNU.sparse.name\fP, \fBGNU.sparse.realsize\fP
  804. The
  805. ``1.0''
  806. format stores the sparse block map in one or more 512-byte blocks
  807. prepended to the file data in the entry body.
  808. The pax attributes indicate the existence of this map
  809. (via the
  810. \fBGNU.sparse.major\fP
  811. and
  812. \fBGNU.sparse.minor\fP
  813. fields)
  814. and the full size of the file.
  815. The
  816. \fBGNU.sparse.name\fP
  817. holds the true name of the file.
  818. To avoid confusion, the name stored in the regular tar header
  819. is a modified name so that extraction errors will be apparent
  820. to users.
  821. .RE
  822. .SS Solaris Tar
  823. XXX More Details Needed XXX
  824. .PP
  825. Solaris tar (beginning with SunOS XXX 5.7 ?? XXX) supports an
  826. ``extended''
  827. format that is fundamentally similar to pax interchange format,
  828. with the following differences:
  829. .RS 5
  830. .IP \(bu
  831. Extended attributes are stored in an entry whose type is
  832. \fBX\fP,
  833. not
  834. \fBx\fP,
  835. as used by pax interchange format.
  836. The detailed format of this entry appears to be the same
  837. as detailed above for the
  838. \fBx\fP
  839. entry.
  840. .IP \(bu
  841. An additional
  842. \fBA\fP
  843. header is used to store an ACL for the following regular entry.
  844. The body of this entry contains a seven-digit octal number
  845. followed by a zero byte, followed by the
  846. textual ACL description.
  847. The octal value is the number of ACL entries
  848. plus a constant that indicates the ACL type: 01000000
  849. for POSIX.1e ACLs and 03000000 for NFSv4 ACLs.
  850. .RE
  851. .SS AIX Tar
  852. XXX More details needed XXX
  853. .PP
  854. AIX Tar uses a ustar-formatted header with the type
  855. \fBA\fP
  856. for storing coded ACL information.
  857. Unlike the Solaris format, AIX tar writes this header after the
  858. regular file body to which it applies.
  859. The pathname in this header is either
  860. \fBNFS4\fP
  861. or
  862. \fBAIXC\fP
  863. to indicate the type of ACL stored.
  864. The actual ACL is stored in platform-specific binary format.
  865. .SS Mac OS X Tar
  866. The tar distributed with Apple's Mac OS X stores most regular files
  867. as two separate files in the tar archive.
  868. The two files have the same name except that the first
  869. one has
  870. ``._''
  871. prepended to the last path element.
  872. This special file stores an AppleDouble-encoded
  873. binary blob with additional metadata about the second file,
  874. including ACL, extended attributes, and resources.
  875. To recreate the original file on disk, each
  876. separate file can be extracted and the Mac OS X
  877. \fB\%copyfile\fP()
  878. function can be used to unpack the separate
  879. metadata file and apply it to th regular file.
  880. Conversely, the same function provides a
  881. ``pack''
  882. option to encode the extended metadata from
  883. a file into a separate file whose contents
  884. can then be put into a tar archive.
  885. .PP
  886. Note that the Apple extended attributes interact
  887. badly with long filenames.
  888. Since each file is stored with the full name,
  889. a separate set of extensions needs to be included
  890. in the archive for each one, doubling the overhead
  891. required for files with long names.
  892. .SS Summary of tar type codes
  893. The following list is a condensed summary of the type codes
  894. used in tar header records generated by different tar implementations.
  895. More details about specific implementations can be found above:
  896. .RS 5
  897. .TP
  898. NUL
  899. Early tar programs stored a zero byte for regular files.
  900. .TP
  901. \fB0\fP
  902. POSIX standard type code for a regular file.
  903. .TP
  904. \fB1\fP
  905. POSIX standard type code for a hard link description.
  906. .TP
  907. \fB2\fP
  908. POSIX standard type code for a symbolic link description.
  909. .TP
  910. \fB3\fP
  911. POSIX standard type code for a character device node.
  912. .TP
  913. \fB4\fP
  914. POSIX standard type code for a block device node.
  915. .TP
  916. \fB5\fP
  917. POSIX standard type code for a directory.
  918. .TP
  919. \fB6\fP
  920. POSIX standard type code for a FIFO.
  921. .TP
  922. \fB7\fP
  923. POSIX reserved.
  924. .TP
  925. \fB7\fP
  926. GNU tar used for pre-allocated files on some systems.
  927. .TP
  928. \fBA\fP
  929. Solaris tar ACL description stored prior to a regular file header.
  930. .TP
  931. \fBA\fP
  932. AIX tar ACL description stored after the file body.
  933. .TP
  934. \fBD\fP
  935. GNU tar directory dump.
  936. .TP
  937. \fBK\fP
  938. GNU tar long linkname for the following header.
  939. .TP
  940. \fBL\fP
  941. GNU tar long pathname for the following header.
  942. .TP
  943. \fBM\fP
  944. GNU tar multivolume marker, indicating the file is a continuation of a file from the previous volume.
  945. .TP
  946. \fBN\fP
  947. GNU tar long filename support.
  948. Deprecated.
  949. .TP
  950. \fBS\fP
  951. GNU tar sparse regular file.
  952. .TP
  953. \fBV\fP
  954. GNU tar tape/volume header name.
  955. .TP
  956. \fBX\fP
  957. Solaris tar general-purpose extension header.
  958. .TP
  959. \fBg\fP
  960. POSIX pax interchange format global extensions.
  961. .TP
  962. \fBx\fP
  963. POSIX pax interchange format per-file extensions.
  964. .RE
  965. .SH SEE ALSO
  966. .ad l
  967. \fBar\fP(1),
  968. \fBpax\fP(1),
  969. \fBtar\fP(1)
  970. .SH STANDARDS
  971. .ad l
  972. The
  973. \fB\%tar\fP
  974. utility is no longer a part of POSIX or the Single Unix Standard.
  975. It last appeared in
  976. Version 2 of the Single UNIX Specification (``SUSv2'').
  977. It has been supplanted in subsequent standards by
  978. \fBpax\fP(1).
  979. The ustar format is currently part of the specification for the
  980. \fBpax\fP(1)
  981. utility.
  982. The pax interchange file format is new with
  983. IEEE Std 1003.1-2001 (``POSIX.1'').
  984. .SH HISTORY
  985. .ad l
  986. A
  987. \fB\%tar\fP
  988. command appeared in Seventh Edition Unix, which was released in January, 1979.
  989. It replaced the
  990. \fB\%tp\fP
  991. program from Fourth Edition Unix which in turn replaced the
  992. \fB\%tap\fP
  993. program from First Edition Unix.
  994. John Gilmore's
  995. \fB\%pdtar\fP
  996. public-domain implementation (circa 1987) was highly influential
  997. and formed the basis of
  998. \fB\%GNU\fP tar
  999. (circa 1988).
  1000. Joerg Shilling's
  1001. \fB\%star\fP
  1002. archiver is another open-source (CDDL) archiver (originally developed
  1003. circa 1985) which features complete support for pax interchange
  1004. format.
  1005. .PP
  1006. This documentation was written as part of the
  1007. \fB\%libarchive\fP
  1008. and
  1009. \fB\%bsdtar\fP
  1010. project by
  1011. Tim Kientzle \%<[email protected].>