tar.5 31 KB

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