1 .\" Copyright (c) 2003-2009 Tim Kientzle
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .Nd format of tape archive files
36 archive format collects any number of files, directories, and other
37 file system objects (symbolic links, device nodes, etc.) into a single
39 The format was originally designed to be used with
40 tape drives that operate with fixed-size blocks, but is widely used as
41 a general packaging mechanism.
45 archive consists of a series of 512-byte records.
46 Each file system object requires a header record which stores basic metadata
47 (pathname, owner, permissions, etc.) and zero or more records containing any
49 The end of the archive is indicated by two records consisting
50 entirely of zero bytes.
52 For compatibility with tape drives that use fixed block sizes,
53 programs that read or write tar files always read or write a fixed
54 number of records with each I/O operation.
57 are always a multiple of the record size.
58 The most common block size\(emand the maximum supported by historic
59 implementations\(emis 10240 bytes or 20 records.
64 here are not entirely standard; this document follows the
65 convention established by John Gilmore in documenting
67 .Ss Old-Style Archive Format
68 The original tar archive format has been extended many times to
69 include additional information that various implementors found
71 This section describes the variant implemented by the tar command
74 which seems to be the earliest widely-used version of the tar program.
76 The header record for an old-style
78 archive consists of the following:
79 .Bd -literal -offset indent
80 struct header_old_tar {
93 All unused bytes in the header record are filled with nulls.
94 .Bl -tag -width indent
96 Pathname, stored as a null-terminated string.
97 Early tar implementations only stored regular files (including
98 hardlinks to those files).
99 One common early convention used a trailing "/" character to indicate
100 a directory name, allowing directory permissions and owner information
101 to be archived and restored.
103 File mode, stored as an octal number in ASCII.
105 User id and group id of owner, as octal numbers in ASCII.
107 Size of file, as octal number in ASCII.
108 For regular files only, this indicates the amount of data
109 that follows the header.
110 In particular, this field was ignored by early tar implementations
111 when extracting hardlinks.
112 Modern writers should always store a zero length for hardlink entries.
114 Modification time of file, as an octal number in ASCII.
115 This indicates the number of seconds since the start of the epoch,
116 00:00:00 UTC January 1, 1970.
117 Note that negative values should be avoided
118 here, as they are handled inconsistently.
120 Header checksum, stored as an octal number in ASCII.
121 To compute the checksum, set the checksum field to all spaces,
122 then sum all bytes in the header using unsigned arithmetic.
123 This field should be stored as six octal digits followed by a null and a space
125 Note that many early implementations of tar used signed arithmetic
126 for the checksum field, which can cause interoperability problems
127 when transferring archives between systems.
128 Modern robust readers compute the checksum both ways and accept the
129 header if either computation matches.
130 .It Va linkflag , Va linkname
131 In order to preserve hardlinks and conserve tape, a file
132 with multiple links is only written to the archive the first
133 time it is encountered.
134 The next time it is encountered, the
140 field holds the first name under which this file appears.
141 (Note that regular files have a null value in the
146 Early tar implementations varied in how they terminated these fields.
149 used the following conventions (this is also documented in early BSD manpages):
150 the pathname must be null-terminated;
151 the mode, uid, and gid fields must end in a space and a null byte;
152 the size and mtime fields must end in a space;
153 the checksum is terminated by a null and a space.
154 Early implementations filled the numeric fields with leading spaces.
155 This seems to have been common practice until the
157 standard was released.
158 For best portability, modern implementations should fill the numeric
159 fields with leading zeros.
160 .Ss Pre-POSIX Archives
163 served as the basis for John Gilmore's
165 program and many system implementations from the late 1980s
167 These archives generally follow the POSIX ustar
168 format described below with the following variations:
169 .Bl -bullet -compact -width indent
173 (note the following space).
174 The version field contains a space character followed by a null.
176 The numeric fields are generally filled with leading spaces
177 (not leading zeros as recommended in the final standard).
179 The prefix field is often not used, limiting pathnames to
180 the 100 characters of old-style archives.
182 .Ss POSIX ustar Archives
184 defined a standard tar file format to be read and written
185 by compliant implementations of
187 This format is often called the
189 format, after the magic value used
191 (The name is an acronym for
192 .Dq Unix Standard TAR . )
193 It extends the historic format with new fields:
194 .Bd -literal -offset indent
195 struct header_posix_ustar {
215 .Bl -tag -width indent
218 POSIX extended the earlier
220 field with several new type values:
221 .Bl -tag -width indent -compact
224 NUL should be treated as a synonym, for compatibility purposes.
230 Character device node.
240 A POSIX-compliant implementation must treat any unrecognized typeflag value
242 In particular, writers should ensure that all entries
243 have a valid filename so that they can be restored by readers that do not
244 support the corresponding extension.
245 Uppercase letters "A" through "Z" are reserved for custom extensions.
246 Note that sockets and whiteout entries are not archivable.
248 It is worth noting that the
250 field, in particular, has different meanings depending on the type.
251 For regular files, of course, it indicates the amount of data
252 following the header.
253 For directories, it may be used to indicate the total size of all
254 files in the directory, for use by operating systems that pre-allocate
256 For all other types, it should be set to zero by writers and ignored
259 Contains the magic value
261 followed by a NUL byte to indicate that this is a POSIX standard archive.
262 Full compliance requires the uname and gname fields be properly set.
267 (two copies of the ASCII digit zero) for POSIX standard archives.
268 .It Va uname , Va gname
269 User and group names, as null-terminated ASCII strings.
270 These should be used in preference to the uid/gid values
271 when they are set and the corresponding names exist on
273 .It Va devmajor , Va devminor
274 Major and minor numbers for character device or block device entry.
276 First part of pathname.
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
280 character with the first portion going here.
281 If the prefix field is not empty, the reader will prepend
282 the prefix value and a
284 character to the regular name field to obtain the full pathname.
287 Note that all unused bytes must be set to
290 Field termination is specified slightly differently by POSIX
291 than by previous implementations.
297 fields must have a trailing
304 fields must have a trailing
306 unless they fill the entire field.
307 (In particular, it is possible to store a 256-character pathname if it
310 as the 156th character.)
311 POSIX requires numeric fields to be zero-padded in the front, and allows
312 them to be terminated with either space or
316 Currently, most tar implementations comply with the ustar
317 format, occasionally extending it by adding new fields to the
318 blank area at the end of the header record.
319 .Ss Pax Interchange Format
320 There are many attributes that cannot be portably stored in a
324 .Dq pax interchange format
325 that uses two new types of entries to hold text-formatted
326 metadata that applies to following entries.
327 Note that a pax interchange format archive is a ustar archive in every
329 The new data is stored in ustar-compatible archive entries that use the
334 In particular, older implementations that do not fully support these
335 extensions will extract the metadata into regular files, where the
336 metadata can be examined as necessary.
338 An entry in a pax interchange format archive consists of one or
339 two standard ustar entries, each with its own header and data.
340 The first optional entry stores the extended attributes
341 for the following entry.
342 This optional first entry has an "x" typeflag and a size field that
343 indicates the total size of the extended attributes.
344 The extended attributes themselves are stored as a series of text-format
345 lines encoded in the portable UTF-8 encoding.
346 Each line consists of a decimal number, a space, a key string, an equals
347 sign, a value string, and a new line.
348 The decimal number indicates the length of the entire line, including the
349 initial length field and the trailing newline.
350 An example of such a field is:
351 .Dl 25 ctime=1084839148.1212\en
352 Keys in all lowercase are standard keys.
353 Vendors can add their own keys by prefixing them with an all uppercase
354 vendor name and a period.
355 Note that, unlike the historic header, numeric values are stored using
357 A description of some common keys follows:
358 .Bl -tag -width indent
359 .It Cm atime , Cm ctime , Cm mtime
360 File access, inode change, and modification times.
361 These fields can be negative or include a decimal point and a fractional value.
362 .It Cm uname , Cm uid , Cm gname , Cm gid
363 User name, group name, and numeric UID and GID values.
364 The user name and group name stored here are encoded in UTF8
365 and can thus include non-ASCII characters.
366 The UID and GID fields can be of arbitrary length.
368 The full path of the linked-to file.
369 Note that this is encoded in UTF8 and can thus include non-ASCII characters.
371 The full pathname of the entry.
372 Note that this is encoded in UTF8 and can thus include non-ASCII characters.
373 .It Cm realtime.* , Cm security.*
374 These keys are reserved and may be used for future standardization.
376 The size of the file.
377 Note that there is no length limit on this field, allowing conforming
378 archives to store files much larger than the historic 8GB limit.
380 Vendor-specific attributes used by Joerg Schilling's
383 .It Cm SCHILY.acl.access , Cm SCHILY.acl.default
384 Stores the access and default ACLs as textual strings in a format
385 that is an extension of the format specified by POSIX.1e draft 17.
386 In particular, each user or group access specification can include a fourth
387 colon-separated field with the numeric UID or GID.
388 This allows ACLs to be restored on systems that may not have complete
389 user or group information available (such as when NIS/YP or LDAP services
390 are temporarily unavailable).
391 .It Cm SCHILY.devminor , Cm SCHILY.devmajor
392 The full minor and major numbers for device nodes.
395 .It Cm SCHILY.realsize
396 The full size of the file on disk.
398 .It Cm SCHILY.dev, Cm SCHILY.ino , Cm SCHILY.nlinks
399 The device number, inode number, and link count for the entry.
400 In particular, note that a pax interchange format archive using Joerg
403 extensions can store all of the data from
405 .It Cm LIBARCHIVE.xattr. Ns Ar namespace Ns . Ns Ar key
406 Libarchive stores POSIX.1e-style extended attributes using
410 value is URL-encoded:
411 All non-ASCII characters and the two special characters
417 followed by two uppercase hexadecimal digits.
418 The value of this key is the extended attribute value
420 XXX Detail the base-64 format here XXX
422 XXX document other vendor-specific extensions XXX
425 Any values stored in an extended attribute override the corresponding
426 values in the regular tar header.
427 Note that compliant readers should ignore the regular fields when they
429 This is important, as existing archivers are known to store non-compliant
430 values in the standard header fields in this situation.
431 There are no limits on length for any of these fields.
432 In particular, numeric fields can be arbitrarily large.
433 All text fields are encoded in UTF8.
434 Compliant writers should store only portable 7-bit ASCII characters in
435 the standard ustar header and use extended
436 attributes whenever a text value contains non-ASCII characters.
440 entry described above, the pax interchange format
446 entry is identical in format, but specifies attributes that serve as
447 defaults for all subsequent archive entries.
450 entry is not widely used.
456 entries, the pax interchange format has a few other minor variations
457 from the earlier ustar format.
458 The most troubling one is that hardlinks are permitted to have
460 This allows readers to restore any hardlink to a file without
461 having to rewind the archive to find an earlier entry.
462 However, it creates complications for robust readers, as it is no longer
463 clear whether or not they should ignore the size field for hardlink entries.
465 The GNU tar program started with a pre-POSIX format similar to that
466 described earlier and has extended it using several different mechanisms:
467 It added new fields to the empty space in the header (some of which was later
468 used by POSIX for conflicting purposes);
469 it allowed the header to be continued over multiple records;
470 and it defined new entries that modify following entries
471 (similar in principle to the
473 entry described above, but each GNU special entry is single-purpose,
474 unlike the general-purpose
477 As a result, GNU tar archives are not POSIX compatible, although
478 more lenient POSIX-compliant readers can successfully extract most
480 .Bd -literal -offset indent
481 struct header_gnu_tar {
511 .Bl -tag -width indent
513 GNU tar uses the following special entry types, in addition to
514 those defined by POSIX:
515 .Bl -tag -width indent
517 GNU tar treats type "7" records identically to type "0" records,
518 except on one obscure RTOS where they are used to indicate the
519 pre-allocation of a contiguous file on disk.
521 This indicates a directory entry.
522 Unlike the POSIX-standard "5"
523 typeflag, the header is followed by data records listing the names
524 of files in this directory.
525 Each name is preceded by an ASCII "Y"
526 if the file is stored in this archive or "N" if the file is not
527 stored in this archive.
528 Each name is terminated with a null, and
529 an extra null marks the end of the name list.
531 entry is to support incremental backups; a program restoring from
532 such an archive may wish to delete files on disk that did not exist
533 in the directory when the archive was made.
535 Note that the "D" typeflag specifically violates POSIX, which requires
536 that unrecognized typeflags be restored as normal files.
537 In this case, restoring the "D" entry as a file could interfere
538 with subsequent creation of the like-named directory.
540 The data for this entry is a long linkname for the following regular entry.
542 The data for this entry is a long pathname for the following regular entry.
544 This is a continuation of the last file on the previous volume.
545 GNU multi-volume archives guarantee that each volume begins with a valid
547 To ensure this, a file may be split, with part stored at the end of one volume,
548 and part stored at the beginning of the next volume.
549 The "M" typeflag indicates that this entry continues an existing file.
550 Such entries can only occur as the first or second entry
551 in an archive (the latter only if the first entry is a volume label).
554 field specifies the size of this entry.
557 field at bytes 369-380 specifies the offset where this file fragment
561 field specifies the total size of the file (which must equal
565 When extracting, GNU tar checks that the header file name is the one it is
566 expecting, that the header offset is in the correct sequence, and that
567 the sum of offset and size is equal to realsize.
569 Type "N" records are no longer generated by GNU tar.
571 list of files to be renamed or symlinked after extraction; this was
572 originally used to support long names.
573 The contents of this record
574 are a text description of the operations to be done, in the form
575 .Dq Rename %s to %s\en
577 .Dq Symlink %s to %s\en ;
579 filenames are escaped using K&R C syntax.
580 Due to security concerns, "N" records are now generally ignored
581 when reading archives.
586 Sparse files are stored as a series of fragments.
587 The header contains a list of fragment offset/length pairs.
588 If more than four such entries are required, the header is
589 extended as necessary with
591 header extensions (an older format that is no longer used), or
597 field should be interpreted as a tape/volume header name.
598 This entry should generally be ignored on extraction.
601 The magic field holds the five characters
604 Note that POSIX ustar archives have a trailing null.
606 The version field holds a space character followed by a null.
607 Note that POSIX ustar archives use two copies of the ASCII digit
609 .It Va atime , Va ctime
610 The time the file was last accessed and the time of
611 last change of file information, stored in octal as with
614 This field is apparently no longer used.
615 .It Sparse Va offset / Va numbytes
616 Each such structure specifies a single fragment of a sparse
618 The two fields store values as octal numbers.
619 The fragments are each padded to a multiple of 512 bytes
621 On extraction, the list of fragments is collected from the
622 header (including any extension headers), and the data
623 is then read and written to the file at appropriate offsets.
625 If this is set to non-zero, the header will be followed by additional
628 Each such record contains information about as many as 21 additional
629 sparse blocks as shown here:
630 .Bd -literal -offset indent
631 struct gnu_sparse_header {
641 A binary representation of the file's complete size, with a much larger range
642 than the POSIX file size.
645 type files, the current entry is only a portion of the file.
646 In that case, the POSIX size field will indicate the size of this
649 field will indicate the total size of the file.
651 .Ss GNU tar pax archives
652 GNU tar 1.14 (XXX check this XXX) and later will write
653 pax interchange format archives when you specify the
656 This format uses custom keywords to store sparse file information.
657 There have been three iterations of this support, referred to
663 .Bl -tag -width indent
664 .It Cm GNU.sparse.numblocks , Cm GNU.sparse.offset , Cm GNU.sparse.numbytes , Cm GNU.sparse.size
667 format used an initial
668 .Cm GNU.sparse.numblocks
669 attribute to indicate the number of blocks in the file, a pair of
670 .Cm GNU.sparse.offset
672 .Cm GNU.sparse.numbytes
673 to indicate the offset and size of each block,
676 to indicate the full size of the file.
677 This is not the same as the size in the tar header because the
678 latter value does not include the size of any holes.
679 This format required that the order of attributes be preserved and
680 relied on readers accepting multiple appearances of the same attribute
681 names, which is not officially permitted by the standards.
682 .It Cm GNU.sparse.map
685 format used a single attribute that stored a comma-separated
686 list of decimal numbers.
687 Each pair of numbers indicated the offset and size, respectively,
689 This does not work well if the archive is extracted by an archiver
690 that does not recognize this extension, since many pax implementations
691 simply discard unrecognized attributes.
692 .It Cm GNU.sparse.major , Cm GNU.sparse.minor , Cm GNU.sparse.name , Cm GNU.sparse.realsize
695 format stores the sparse block map in one or more 512-byte blocks
696 prepended to the file data in the entry body.
697 The pax attributes indicate the existence of this map
703 and the full size of the file.
706 holds the true name of the file.
707 To avoid confusion, the name stored in the regular tar header
708 is a modified name so that extraction errors will be apparent
712 XXX More Details Needed XXX
714 Solaris tar (beginning with SunOS XXX 5.7 ?? XXX) supports an
716 format that is fundamentally similar to pax interchange format,
717 with the following differences:
718 .Bl -bullet -compact -width indent
720 Extended attributes are stored in an entry whose type is
724 as used by pax interchange format.
725 The detailed format of this entry appears to be the same
726 as detailed above for the
732 entry is used to store an ACL for the following regular entry.
733 The body of this entry contains a seven-digit octal number
734 followed by a zero byte, followed by the
735 textual ACL description.
736 The octal value is the number of ACL entries
737 plus a constant that indicates the ACL type: 01000000
738 for POSIX.1e ACLs and 03000000 for NFSv4 ACLs.
741 XXX More details needed XXX
743 The tar distributed with Apple's Mac OS X stores most regular files
744 as two separate entries in the tar archive.
745 The two entries have the same name except that the first
748 added to the beginning of the name.
749 This first entry stores the
751 with additional attributes for the file.
754 API is used to separate a file on disk into separate
755 resource and data streams and to reassemble those separate
756 streams when the file is restored to disk.
758 One obvious extension to increase the size of files is to
759 eliminate the terminating characters from the various
761 For example, the standard only allows the size field to contain
762 11 octal digits, reserving the twelfth byte for a trailing
764 Allowing 12 octal digits allows file sizes up to 64 GB.
766 Another extension, utilized by GNU tar, star, and other newer
768 implementations, permits binary numbers in the standard numeric fields.
769 This is flagged by setting the high bit of the first byte.
770 This permits 95-bit values for the length and time fields
771 and 63-bit values for the uid, gid, and device numbers.
772 GNU tar supports this extension for the
773 length, mtime, ctime, and atime fields.
774 Joerg Schilling's star program supports this extension for
776 Note that this extension is largely obsoleted by the extended attribute
777 record provided by the pax interchange format.
779 Another early GNU extension allowed base-64 values rather than octal.
780 This extension was short-lived and is no longer supported by any
789 utility is no longer a part of POSIX or the Single Unix Standard.
792 It has been supplanted in subsequent standards by
794 The ustar format is currently part of the specification for the
797 The pax interchange file format is new with
802 command appeared in Seventh Edition Unix, which was released in January, 1979.
805 program from Fourth Edition Unix which in turn replaced the
807 program from First Edition Unix.
810 public-domain implementation (circa 1987) was highly influential
811 and formed the basis of
815 archiver is another open-source (GPL) archiver (originally developed
816 circa 1985) which features complete support for pax interchange