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 maximum block size supported by early
59 implementations was 10240 bytes or 20 records.
60 This is still the default for most implementations
61 although block sizes of 1MiB (2048 records) or larger are
62 commonly used with modern high-speed tape drives.
67 here are not entirely standard; this document follows the
68 convention established by John Gilmore in documenting
70 .Ss Old-Style Archive Format
71 The original tar archive format has been extended many times to
72 include additional information that various implementors found
74 This section describes the variant implemented by the tar command
77 which seems to be the earliest widely-used version of the tar program.
79 The header record for an old-style
81 archive consists of the following:
82 .Bd -literal -offset indent
83 struct header_old_tar {
96 All unused bytes in the header record are filled with nulls.
97 .Bl -tag -width indent
99 Pathname, stored as a null-terminated string.
100 Early tar implementations only stored regular files (including
101 hardlinks to those files).
102 One common early convention used a trailing "/" character to indicate
103 a directory name, allowing directory permissions and owner information
104 to be archived and restored.
106 File mode, stored as an octal number in ASCII.
108 User id and group id of owner, as octal numbers in ASCII.
110 Size of file, as octal number in ASCII.
111 For regular files only, this indicates the amount of data
112 that follows the header.
113 In particular, this field was ignored by early tar implementations
114 when extracting hardlinks.
115 Modern writers should always store a zero length for hardlink entries.
117 Modification time of file, as an octal number in ASCII.
118 This indicates the number of seconds since the start of the epoch,
119 00:00:00 UTC January 1, 1970.
120 Note that negative values should be avoided
121 here, as they are handled inconsistently.
123 Header checksum, stored as an octal number in ASCII.
124 To compute the checksum, set the checksum field to all spaces,
125 then sum all bytes in the header using unsigned arithmetic.
126 This field should be stored as six octal digits followed by a null and a space
128 Note that many early implementations of tar used signed arithmetic
129 for the checksum field, which can cause interoperability problems
130 when transferring archives between systems.
131 Modern robust readers compute the checksum both ways and accept the
132 header if either computation matches.
133 .It Va linkflag , Va linkname
134 In order to preserve hardlinks and conserve tape, a file
135 with multiple links is only written to the archive the first
136 time it is encountered.
137 The next time it is encountered, the
143 field holds the first name under which this file appears.
144 (Note that regular files have a null value in the
149 Early tar implementations varied in how they terminated these fields.
152 used the following conventions (this is also documented in early BSD manpages):
153 the pathname must be null-terminated;
154 the mode, uid, and gid fields must end in a space and a null byte;
155 the size and mtime fields must end in a space;
156 the checksum is terminated by a null and a space.
157 Early implementations filled the numeric fields with leading spaces.
158 This seems to have been common practice until the
160 standard was released.
161 For best portability, modern implementations should fill the numeric
162 fields with leading zeros.
163 .Ss Pre-POSIX Archives
166 served as the basis for John Gilmore's
168 program and many system implementations from the late 1980s
170 These archives generally follow the POSIX ustar
171 format described below with the following variations:
172 .Bl -bullet -compact -width indent
174 The magic value consists of the five characters
177 The version field contains a space character followed by a null.
179 The numeric fields are generally filled with leading spaces
180 (not leading zeros as recommended in the final standard).
182 The prefix field is often not used, limiting pathnames to
183 the 100 characters of old-style archives.
185 .Ss POSIX ustar Archives
187 defined a standard tar file format to be read and written
188 by compliant implementations of
190 This format is often called the
192 format, after the magic value used
194 (The name is an acronym for
195 .Dq Unix Standard TAR . )
196 It extends the historic format with new fields:
197 .Bd -literal -offset indent
198 struct header_posix_ustar {
218 .Bl -tag -width indent
221 POSIX extended the earlier
223 field with several new type values:
224 .Bl -tag -width indent -compact
227 NUL should be treated as a synonym, for compatibility purposes.
233 Character device node.
243 A POSIX-compliant implementation must treat any unrecognized typeflag value
245 In particular, writers should ensure that all entries
246 have a valid filename so that they can be restored by readers that do not
247 support the corresponding extension.
248 Uppercase letters "A" through "Z" are reserved for custom extensions.
249 Note that sockets and whiteout entries are not archivable.
251 It is worth noting that the
253 field, in particular, has different meanings depending on the type.
254 For regular files, of course, it indicates the amount of data
255 following the header.
256 For directories, it may be used to indicate the total size of all
257 files in the directory, for use by operating systems that pre-allocate
259 For all other types, it should be set to zero by writers and ignored
262 Contains the magic value
264 followed by a NUL byte to indicate that this is a POSIX standard archive.
265 Full compliance requires the uname and gname fields be properly set.
270 (two copies of the ASCII digit zero) for POSIX standard archives.
271 .It Va uname , Va gname
272 User and group names, as null-terminated ASCII strings.
273 These should be used in preference to the uid/gid values
274 when they are set and the corresponding names exist on
276 .It Va devmajor , Va devminor
277 Major and minor numbers for character device or block device entry.
278 .It Va name , Va prefix
279 If the pathname is too long to fit in the 100 bytes provided by the standard
280 format, it can be split at any
282 character with the first portion going into the prefix field.
283 If the prefix field is not empty, the reader will prepend
284 the prefix value and a
286 character to the regular name field to obtain the full pathname.
287 The standard does not require a trailing
289 character on directory names, though most implementations still
290 include this for compatibility reasons.
293 Note that all unused bytes must be set to
296 Field termination is specified slightly differently by POSIX
297 than by previous implementations.
303 fields must have a trailing
310 fields must have a trailing
312 unless they fill the entire field.
313 (In particular, it is possible to store a 256-character pathname if it
316 as the 156th character.)
317 POSIX requires numeric fields to be zero-padded in the front, and requires
318 them to be terminated with either space or
322 Currently, most tar implementations comply with the ustar
323 format, occasionally extending it by adding new fields to the
324 blank area at the end of the header record.
325 .Ss Numeric Extensions
326 There have been several attempts to extend the range of sizes
327 or times supported by modifying how numbers are stored in the
330 One obvious extension to increase the size of files is to
331 eliminate the terminating characters from the various
333 For example, the standard only allows the size field to contain
334 11 octal digits, reserving the twelfth byte for a trailing
336 Allowing 12 octal digits allows file sizes up to 64 GB.
338 Another extension, utilized by GNU tar, star, and other newer
340 implementations, permits binary numbers in the standard numeric fields.
341 This is flagged by setting the high bit of the first byte.
342 The remainder of the field is treated as a signed twos-complement
344 This permits 95-bit values for the length and time fields
345 and 63-bit values for the uid, gid, and device numbers.
346 In particular, this provides a consistent way to handle
347 negative time values.
348 GNU tar supports this extension for the
349 length, mtime, ctime, and atime fields.
350 Joerg Schilling's star program and the libarchive library support
351 this extension for all numeric fields.
352 Note that this extension is largely obsoleted by the extended
353 attribute record provided by the pax interchange format.
355 Another early GNU extension allowed base-64 values rather than octal.
356 This extension was short-lived and is no longer supported by any
358 .Ss Pax Interchange Format
359 There are many attributes that cannot be portably stored in a
363 .Dq pax interchange format
364 that uses two new types of entries to hold text-formatted
365 metadata that applies to following entries.
366 Note that a pax interchange format archive is a ustar archive in every
368 The new data is stored in ustar-compatible archive entries that use the
373 In particular, older implementations that do not fully support these
374 extensions will extract the metadata into regular files, where the
375 metadata can be examined as necessary.
377 An entry in a pax interchange format archive consists of one or
378 two standard ustar entries, each with its own header and data.
379 The first optional entry stores the extended attributes
380 for the following entry.
381 This optional first entry has an "x" typeflag and a size field that
382 indicates the total size of the extended attributes.
383 The extended attributes themselves are stored as a series of text-format
384 lines encoded in the portable UTF-8 encoding.
385 Each line consists of a decimal number, a space, a key string, an equals
386 sign, a value string, and a new line.
387 The decimal number indicates the length of the entire line, including the
388 initial length field and the trailing newline.
389 An example of such a field is:
390 .Dl 25 ctime=1084839148.1212\en
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
396 A description of some common keys follows:
397 .Bl -tag -width indent
398 .It Cm atime , Cm ctime , Cm mtime
399 File access, inode change, and modification times.
400 These fields can be negative or include a decimal point and a fractional value.
402 The character set used by the pax extension values.
403 By default, all textual values in the pax extended attributes
404 are assumed to be in UTF-8, including pathnames, user names,
406 In some cases, it is not possible to translate local
407 conventions into UTF-8.
408 If this key is present and the value is the six-character ASCII string
410 then all textual values are assumed to be in a platform-dependent
412 Note that there are only two valid values for this key:
415 .Dq ISO-IR\ 10646\ 2000\ UTF-8 .
416 No other values are permitted by the standard, and
417 the latter value should generally not be used as it is the
418 default when this key is not specified.
419 In particular, this flag should not be used as a general
420 mechanism to allow filenames to be stored in arbitrary
422 .It Cm uname , Cm uid , Cm gname , Cm gid
423 User name, group name, and numeric UID and GID values.
424 The user name and group name stored here are encoded in UTF8
425 and can thus include non-ASCII characters.
426 The UID and GID fields can be of arbitrary length.
428 The full path of the linked-to file.
429 Note that this is encoded in UTF8 and can thus include non-ASCII characters.
431 The full pathname of the entry.
432 Note that this is encoded in UTF8 and can thus include non-ASCII characters.
433 .It Cm realtime.* , Cm security.*
434 These keys are reserved and may be used for future standardization.
436 The size of the file.
437 Note that there is no length limit on this field, allowing conforming
438 archives to store files much larger than the historic 8GB limit.
440 Vendor-specific attributes used by Joerg Schilling's
443 .It Cm SCHILY.acl.access , Cm SCHILY.acl.default
444 Stores the access and default ACLs as textual strings in a format
445 that is an extension of the format specified by POSIX.1e draft 17.
446 In particular, each user or group access specification can include a fourth
447 colon-separated field with the numeric UID or GID.
448 This allows ACLs to be restored on systems that may not have complete
449 user or group information available (such as when NIS/YP or LDAP services
450 are temporarily unavailable).
451 .It Cm SCHILY.devminor , Cm SCHILY.devmajor
452 The full minor and major numbers for device nodes.
455 .It Cm SCHILY.realsize
456 The full size of the file on disk.
458 .It Cm SCHILY.dev, Cm SCHILY.ino , Cm SCHILY.nlinks
459 The device number, inode number, and link count for the entry.
460 In particular, note that a pax interchange format archive using Joerg
463 extensions can store all of the data from
466 Vendor-specific attributes used by the
468 library and programs that use it.
469 .It Cm LIBARCHIVE.creationtime
470 The time when the file was created.
471 (This should not be confused with the POSIX
473 attribute, which refers to the time when the file
474 metadata was last changed.)
475 .It Cm LIBARCHIVE.xattr. Ns Ar namespace Ns . Ns Ar key
476 Libarchive stores POSIX.1e-style extended attributes using
480 value is URL-encoded:
481 All non-ASCII characters and the two special characters
487 followed by two uppercase hexadecimal digits.
488 The value of this key is the extended attribute value
490 XXX Detail the base-64 format here XXX
492 XXX document other vendor-specific extensions XXX
495 Any values stored in an extended attribute override the corresponding
496 values in the regular tar header.
497 Note that compliant readers should ignore the regular fields when they
499 This is important, as existing archivers are known to store non-compliant
500 values in the standard header fields in this situation.
501 There are no limits on length for any of these fields.
502 In particular, numeric fields can be arbitrarily large.
503 All text fields are encoded in UTF8.
504 Compliant writers should store only portable 7-bit ASCII characters in
505 the standard ustar header and use extended
506 attributes whenever a text value contains non-ASCII characters.
510 entry described above, the pax interchange format
516 entry is identical in format, but specifies attributes that serve as
517 defaults for all subsequent archive entries.
520 entry is not widely used.
526 entries, the pax interchange format has a few other minor variations
527 from the earlier ustar format.
528 The most troubling one is that hardlinks are permitted to have
530 This allows readers to restore any hardlink to a file without
531 having to rewind the archive to find an earlier entry.
532 However, it creates complications for robust readers, as it is no longer
533 clear whether or not they should ignore the size field for hardlink entries.
535 The GNU tar program started with a pre-POSIX format similar to that
536 described earlier and has extended it using several different mechanisms:
537 It added new fields to the empty space in the header (some of which was later
538 used by POSIX for conflicting purposes);
539 it allowed the header to be continued over multiple records;
540 and it defined new entries that modify following entries
541 (similar in principle to the
543 entry described above, but each GNU special entry is single-purpose,
544 unlike the general-purpose
547 As a result, GNU tar archives are not POSIX compatible, although
548 more lenient POSIX-compliant readers can successfully extract most
550 .Bd -literal -offset indent
551 struct header_gnu_tar {
581 .Bl -tag -width indent
583 GNU tar uses the following special entry types, in addition to
584 those defined by POSIX:
585 .Bl -tag -width indent
587 GNU tar treats type "7" records identically to type "0" records,
588 except on one obscure RTOS where they are used to indicate the
589 pre-allocation of a contiguous file on disk.
591 This indicates a directory entry.
592 Unlike the POSIX-standard "5"
593 typeflag, the header is followed by data records listing the names
594 of files in this directory.
595 Each name is preceded by an ASCII "Y"
596 if the file is stored in this archive or "N" if the file is not
597 stored in this archive.
598 Each name is terminated with a null, and
599 an extra null marks the end of the name list.
601 entry is to support incremental backups; a program restoring from
602 such an archive may wish to delete files on disk that did not exist
603 in the directory when the archive was made.
605 Note that the "D" typeflag specifically violates POSIX, which requires
606 that unrecognized typeflags be restored as normal files.
607 In this case, restoring the "D" entry as a file could interfere
608 with subsequent creation of the like-named directory.
610 The data for this entry is a long linkname for the following regular entry.
612 The data for this entry is a long pathname for the following regular entry.
614 This is a continuation of the last file on the previous volume.
615 GNU multi-volume archives guarantee that each volume begins with a valid
617 To ensure this, a file may be split, with part stored at the end of one volume,
618 and part stored at the beginning of the next volume.
619 The "M" typeflag indicates that this entry continues an existing file.
620 Such entries can only occur as the first or second entry
621 in an archive (the latter only if the first entry is a volume label).
624 field specifies the size of this entry.
627 field at bytes 369-380 specifies the offset where this file fragment
631 field specifies the total size of the file (which must equal
635 When extracting, GNU tar checks that the header file name is the one it is
636 expecting, that the header offset is in the correct sequence, and that
637 the sum of offset and size is equal to realsize.
639 Type "N" records are no longer generated by GNU tar.
641 list of files to be renamed or symlinked after extraction; this was
642 originally used to support long names.
643 The contents of this record
644 are a text description of the operations to be done, in the form
645 .Dq Rename %s to %s\en
647 .Dq Symlink %s to %s\en ;
649 filenames are escaped using K&R C syntax.
650 Due to security concerns, "N" records are now generally ignored
651 when reading archives.
656 Sparse files are stored as a series of fragments.
657 The header contains a list of fragment offset/length pairs.
658 If more than four such entries are required, the header is
659 extended as necessary with
661 header extensions (an older format that is no longer used), or
667 field should be interpreted as a tape/volume header name.
668 This entry should generally be ignored on extraction.
671 The magic field holds the five characters
674 Note that POSIX ustar archives have a trailing null.
676 The version field holds a space character followed by a null.
677 Note that POSIX ustar archives use two copies of the ASCII digit
679 .It Va atime , Va ctime
680 The time the file was last accessed and the time of
681 last change of file information, stored in octal as with
684 This field is apparently no longer used.
685 .It Sparse Va offset / Va numbytes
686 Each such structure specifies a single fragment of a sparse
688 The two fields store values as octal numbers.
689 The fragments are each padded to a multiple of 512 bytes
691 On extraction, the list of fragments is collected from the
692 header (including any extension headers), and the data
693 is then read and written to the file at appropriate offsets.
695 If this is set to non-zero, the header will be followed by additional
698 Each such record contains information about as many as 21 additional
699 sparse blocks as shown here:
700 .Bd -literal -offset indent
701 struct gnu_sparse_header {
711 A binary representation of the file's complete size, with a much larger range
712 than the POSIX file size.
715 type files, the current entry is only a portion of the file.
716 In that case, the POSIX size field will indicate the size of this
719 field will indicate the total size of the file.
721 .Ss GNU tar pax archives
722 GNU tar 1.14 (XXX check this XXX) and later will write
723 pax interchange format archives when you specify the
726 This format follows the pax interchange format closely,
729 tags and introducing new keywords to store sparse file information.
730 There have been three iterations of the sparse file support, referred to
736 .Bl -tag -width indent
737 .It Cm GNU.sparse.numblocks , Cm GNU.sparse.offset , Cm GNU.sparse.numbytes , Cm GNU.sparse.size
740 format used an initial
741 .Cm GNU.sparse.numblocks
742 attribute to indicate the number of blocks in the file, a pair of
743 .Cm GNU.sparse.offset
745 .Cm GNU.sparse.numbytes
746 to indicate the offset and size of each block,
749 to indicate the full size of the file.
750 This is not the same as the size in the tar header because the
751 latter value does not include the size of any holes.
752 This format required that the order of attributes be preserved and
753 relied on readers accepting multiple appearances of the same attribute
754 names, which is not officially permitted by the standards.
755 .It Cm GNU.sparse.map
758 format used a single attribute that stored a comma-separated
759 list of decimal numbers.
760 Each pair of numbers indicated the offset and size, respectively,
762 This does not work well if the archive is extracted by an archiver
763 that does not recognize this extension, since many pax implementations
764 simply discard unrecognized attributes.
765 .It Cm GNU.sparse.major , Cm GNU.sparse.minor , Cm GNU.sparse.name , Cm GNU.sparse.realsize
768 format stores the sparse block map in one or more 512-byte blocks
769 prepended to the file data in the entry body.
770 The pax attributes indicate the existence of this map
776 and the full size of the file.
779 holds the true name of the file.
780 To avoid confusion, the name stored in the regular tar header
781 is a modified name so that extraction errors will be apparent
785 XXX More Details Needed XXX
787 Solaris tar (beginning with SunOS XXX 5.7 ?? XXX) supports an
789 format that is fundamentally similar to pax interchange format,
790 with the following differences:
791 .Bl -bullet -compact -width indent
793 Extended attributes are stored in an entry whose type is
797 as used by pax interchange format.
798 The detailed format of this entry appears to be the same
799 as detailed above for the
805 header is used to store an ACL for the following regular entry.
806 The body of this entry contains a seven-digit octal number
807 followed by a zero byte, followed by the
808 textual ACL description.
809 The octal value is the number of ACL entries
810 plus a constant that indicates the ACL type: 01000000
811 for POSIX.1e ACLs and 03000000 for NFSv4 ACLs.
814 XXX More details needed XXX
816 AIX Tar uses a ustar-formatted header with the type
818 for storing coded ACL information.
819 Unlike the Solaris format, AIX tar writes this header after the
820 regular file body to which it applies.
821 The pathname in this header is either
825 to indicate the type of ACL stored.
826 The actual ACL is stored in platform-specific binary format.
828 The tar distributed with Apple's Mac OS X stores most regular files
829 as two separate files in the tar archive.
830 The two files have the same name except that the first
833 prepended to the last path element.
834 This special file stores an AppleDouble-encoded
835 binary blob with additional metadata about the second file,
836 including ACL, extended attributes, and resources.
837 To recreate the original file on disk, each
838 separate file can be extracted and the Mac OS X
840 function can be used to unpack the separate
841 metadata file and apply it to th regular file.
842 Conversely, the same function provides a
844 option to encode the extended metadata from
845 a file into a separate file whose contents
846 can then be put into a tar archive.
848 Note that the Apple extended attributes interact
849 badly with long filenames.
850 Since each file is stored with the full name,
851 a separate set of extensions needs to be included
852 in the archive for each one, doubling the overhead
853 required for files with long names.
854 .Ss Summary of tar type codes
855 The following list is a condensed summary of the type codes
856 used in tar header records generated by different tar implementations.
857 More details about specific implementations can be found above:
858 .Bl -tag -compact -width XXX
860 Early tar programs stored a zero byte for regular files.
862 POSIX standard type code for a regular file.
864 POSIX standard type code for a hard link description.
866 POSIX standard type code for a symbolic link description.
868 POSIX standard type code for a character device node.
870 POSIX standard type code for a block device node.
872 POSIX standard type code for a directory.
874 POSIX standard type code for a FIFO.
878 GNU tar used for pre-allocated files on some systems.
880 Solaris tar ACL description stored prior to a regular file header.
882 AIX tar ACL description stored after the file body.
884 GNU tar directory dump.
886 GNU tar long linkname for the following header.
888 GNU tar long pathname for the following header.
890 GNU tar multivolume marker, indicating the file is a continuation of a file from the previous volume.
892 GNU tar long filename support. Deprecated.
894 GNU tar sparse regular file.
896 GNU tar tape/volume header name.
898 Solaris tar general-purpose extension header.
900 POSIX pax interchange format global extensions.
902 POSIX pax interchange format per-file extensions.
911 utility is no longer a part of POSIX or the Single Unix Standard.
914 It has been supplanted in subsequent standards by
916 The ustar format is currently part of the specification for the
919 The pax interchange file format is new with
924 command appeared in Seventh Edition Unix, which was released in January, 1979.
927 program from Fourth Edition Unix which in turn replaced the
929 program from First Edition Unix.
932 public-domain implementation (circa 1987) was highly influential
933 and formed the basis of
938 archiver is another open-source (CDDL) archiver (originally developed
939 circa 1985) which features complete support for pax interchange
942 This documentation was written as part of the
947 .An Tim Kientzle Aq kientzle@FreeBSD.org .