Blame doc/text/tar.5.txt

Packit 08bd4c
TAR(5)			    BSD File Formats Manual			TAR(5)
Packit 08bd4c
Packit 08bd4c
NAME
Packit 08bd4c
     tar — format of tape archive files
Packit 08bd4c
Packit 08bd4c
DESCRIPTION
Packit 08bd4c
     The tar archive format collects any number of files, directories, and
Packit 08bd4c
     other file system objects (symbolic links, device nodes, etc.) into a
Packit 08bd4c
     single stream of bytes.  The format was originally designed to be used
Packit 08bd4c
     with tape drives that operate with fixed-size blocks, but is widely used
Packit 08bd4c
     as a general packaging mechanism.
Packit 08bd4c
Packit 08bd4c
   General Format
Packit 08bd4c
     A tar archive consists of a series of 512-byte records.  Each file system
Packit 08bd4c
     object requires a header record which stores basic metadata (pathname,
Packit 08bd4c
     owner, permissions, etc.) and zero or more records containing any file
Packit 08bd4c
     data.  The end of the archive is indicated by two records consisting
Packit 08bd4c
     entirely of zero bytes.
Packit 08bd4c
Packit 08bd4c
     For compatibility with tape drives that use fixed block sizes, programs
Packit 08bd4c
     that read or write tar files always read or write a fixed number of
Packit 08bd4c
     records with each I/O operation.  These “blocks” are always a multiple of
Packit 08bd4c
     the record size.  The maximum block size supported by early implementa‐
Packit 08bd4c
     tions was 10240 bytes or 20 records.  This is still the default for most
Packit 08bd4c
     implementations although block sizes of 1MiB (2048 records) or larger are
Packit 08bd4c
     commonly used with modern high-speed tape drives.	(Note: the terms
Packit 08bd4c
     “block” and “record” here are not entirely standard; this document fol‐
Packit 08bd4c
     lows the convention established by John Gilmore in documenting pdtar.)
Packit 08bd4c
Packit 08bd4c
   Old-Style Archive Format
Packit 08bd4c
     The original tar archive format has been extended many times to include
Packit 08bd4c
     additional information that various implementors found necessary.	This
Packit 08bd4c
     section describes the variant implemented by the tar command included in
Packit 08bd4c
     Version 7 AT&T UNIX, which seems to be the earliest widely-used version
Packit 08bd4c
     of the tar program.
Packit 08bd4c
Packit 08bd4c
     The header record for an old-style tar archive consists of the following:
Packit 08bd4c
Packit 08bd4c
	   struct header_old_tar {
Packit 08bd4c
		   char name[100];
Packit 08bd4c
		   char mode[8];
Packit 08bd4c
		   char uid[8];
Packit 08bd4c
		   char gid[8];
Packit 08bd4c
		   char size[12];
Packit 08bd4c
		   char mtime[12];
Packit 08bd4c
		   char checksum[8];
Packit 08bd4c
		   char linkflag[1];
Packit 08bd4c
		   char linkname[100];
Packit 08bd4c
		   char pad[255];
Packit 08bd4c
	   };
Packit 08bd4c
     All unused bytes in the header record are filled with nulls.
Packit 08bd4c
Packit 08bd4c
     name    Pathname, stored as a null-terminated string.  Early tar imple‐
Packit 08bd4c
	     mentations only stored regular files (including hardlinks to
Packit 08bd4c
	     those files).  One common early convention used a trailing "/"
Packit 08bd4c
	     character to indicate a directory name, allowing directory per‐
Packit 08bd4c
	     missions and owner information to be archived and restored.
Packit 08bd4c
Packit 08bd4c
     mode    File mode, stored as an octal number in ASCII.
Packit 08bd4c
Packit 08bd4c
     uid, gid
Packit 08bd4c
	     User id and group id of owner, as octal numbers in ASCII.
Packit 08bd4c
Packit 08bd4c
     size    Size of file, as octal number in ASCII.  For regular files only,
Packit 08bd4c
	     this indicates the amount of data that follows the header.  In
Packit 08bd4c
	     particular, this field was ignored by early tar implementations
Packit 08bd4c
	     when extracting hardlinks.  Modern writers should always store a
Packit 08bd4c
	     zero length for hardlink entries.
Packit 08bd4c
Packit 08bd4c
     mtime   Modification time of file, as an octal number in ASCII.  This
Packit 08bd4c
	     indicates the number of seconds since the start of the epoch,
Packit 08bd4c
	     00:00:00 UTC January 1, 1970.  Note that negative values should
Packit 08bd4c
	     be avoided here, as they are handled inconsistently.
Packit 08bd4c
Packit 08bd4c
     checksum
Packit 08bd4c
	     Header checksum, stored as an octal number in ASCII.  To compute
Packit 08bd4c
	     the checksum, set the checksum field to all spaces, then sum all
Packit 08bd4c
	     bytes in the header using unsigned arithmetic.  This field should
Packit 08bd4c
	     be stored as six octal digits followed by a null and a space
Packit 08bd4c
	     character.  Note that many early implementations of tar used
Packit 08bd4c
	     signed arithmetic for the checksum field, which can cause inter‐
Packit 08bd4c
	     operability problems when transferring archives between systems.
Packit 08bd4c
	     Modern robust readers compute the checksum both ways and accept
Packit 08bd4c
	     the header if either computation matches.
Packit 08bd4c
Packit 08bd4c
     linkflag, linkname
Packit 08bd4c
	     In order to preserve hardlinks and conserve tape, a file with
Packit 08bd4c
	     multiple links is only written to the archive the first time it
Packit 08bd4c
	     is encountered.  The next time it is encountered, the linkflag is
Packit 08bd4c
	     set to an ASCII ‘1’ and the linkname field holds the first name
Packit 08bd4c
	     under which this file appears.  (Note that regular files have a
Packit 08bd4c
	     null value in the linkflag field.)
Packit 08bd4c
Packit 08bd4c
     Early tar implementations varied in how they terminated these fields.
Packit 08bd4c
     The tar command in Version 7 AT&T UNIX used the following conventions
Packit 08bd4c
     (this is also documented in early BSD manpages): the pathname must be
Packit 08bd4c
     null-terminated; the mode, uid, and gid fields must end in a space and a
Packit 08bd4c
     null byte; the size and mtime fields must end in a space; the checksum is
Packit 08bd4c
     terminated by a null and a space.	Early implementations filled the
Packit 08bd4c
     numeric fields with leading spaces.  This seems to have been common prac‐
Packit 08bd4c
     tice until the IEEE Std 1003.1-1988 (“POSIX.1”) standard was released.
Packit 08bd4c
     For best portability, modern implementations should fill the numeric
Packit 08bd4c
     fields with leading zeros.
Packit 08bd4c
Packit 08bd4c
   Pre-POSIX Archives
Packit 08bd4c
     An early draft of IEEE Std 1003.1-1988 (“POSIX.1”) served as the basis
Packit 08bd4c
     for John Gilmore's pdtar program and many system implementations from the
Packit 08bd4c
     late 1980s and early 1990s.  These archives generally follow the POSIX
Packit 08bd4c
     ustar format described below with the following variations:
Packit 08bd4c
     ·	     The magic value consists of the five characters “ustar” followed
Packit 08bd4c
	     by a space.  The version field contains a space character fol‐
Packit 08bd4c
	     lowed by a null.
Packit 08bd4c
     ·	     The numeric fields are generally filled with leading spaces (not
Packit 08bd4c
	     leading zeros as recommended in the final standard).
Packit 08bd4c
     ·	     The prefix field is often not used, limiting pathnames to the 100
Packit 08bd4c
	     characters of old-style archives.
Packit 08bd4c
Packit 08bd4c
   POSIX ustar Archives
Packit 08bd4c
     IEEE Std 1003.1-1988 (“POSIX.1”) defined a standard tar file format to be
Packit 08bd4c
     read and written by compliant implementations of tar(1).  This format is
Packit 08bd4c
     often called the “ustar” format, after the magic value used in the
Packit 08bd4c
     header.  (The name is an acronym for “Unix Standard TAR”.)  It extends
Packit 08bd4c
     the historic format with new fields:
Packit 08bd4c
Packit 08bd4c
	   struct header_posix_ustar {
Packit 08bd4c
		   char name[100];
Packit 08bd4c
		   char mode[8];
Packit 08bd4c
		   char uid[8];
Packit 08bd4c
		   char gid[8];
Packit 08bd4c
		   char size[12];
Packit 08bd4c
		   char mtime[12];
Packit 08bd4c
		   char checksum[8];
Packit 08bd4c
		   char typeflag[1];
Packit 08bd4c
		   char linkname[100];
Packit 08bd4c
		   char magic[6];
Packit 08bd4c
		   char version[2];
Packit 08bd4c
		   char uname[32];
Packit 08bd4c
		   char gname[32];
Packit 08bd4c
		   char devmajor[8];
Packit 08bd4c
		   char devminor[8];
Packit 08bd4c
		   char prefix[155];
Packit 08bd4c
		   char pad[12];
Packit 08bd4c
	   };
Packit 08bd4c
Packit 08bd4c
     typeflag
Packit 08bd4c
	     Type of entry.  POSIX extended the earlier linkflag field with
Packit 08bd4c
	     several new type values:
Packit 08bd4c
	     “0”     Regular file.  NUL should be treated as a synonym, for
Packit 08bd4c
		     compatibility purposes.
Packit 08bd4c
	     “1”     Hard link.
Packit 08bd4c
	     “2”     Symbolic link.
Packit 08bd4c
	     “3”     Character device node.
Packit 08bd4c
	     “4”     Block device node.
Packit 08bd4c
	     “5”     Directory.
Packit 08bd4c
	     “6”     FIFO node.
Packit 08bd4c
	     “7”     Reserved.
Packit 08bd4c
	     Other   A POSIX-compliant implementation must treat any unrecog‐
Packit 08bd4c
		     nized typeflag value as a regular file.  In particular,
Packit 08bd4c
		     writers should ensure that all entries have a valid file‐
Packit 08bd4c
		     name so that they can be restored by readers that do not
Packit 08bd4c
		     support the corresponding extension.  Uppercase letters
Packit 08bd4c
		     "A" through "Z" are reserved for custom extensions.  Note
Packit 08bd4c
		     that sockets and whiteout entries are not archivable.
Packit 08bd4c
	     It is worth noting that the size field, in particular, has dif‐
Packit 08bd4c
	     ferent meanings depending on the type.  For regular files, of
Packit 08bd4c
	     course, it indicates the amount of data following the header.
Packit 08bd4c
	     For directories, it may be used to indicate the total size of all
Packit 08bd4c
	     files in the directory, for use by operating systems that pre-
Packit 08bd4c
	     allocate directory space.	For all other types, it should be set
Packit 08bd4c
	     to zero by writers and ignored by readers.
Packit 08bd4c
Packit 08bd4c
     magic   Contains the magic value “ustar” followed by a NUL byte to indi‐
Packit 08bd4c
	     cate that this is a POSIX standard archive.  Full compliance
Packit 08bd4c
	     requires the uname and gname fields be properly set.
Packit 08bd4c
Packit 08bd4c
     version
Packit 08bd4c
	     Version.  This should be “00” (two copies of the ASCII digit
Packit 08bd4c
	     zero) for POSIX standard archives.
Packit 08bd4c
Packit 08bd4c
     uname, gname
Packit 08bd4c
	     User and group names, as null-terminated ASCII strings.  These
Packit 08bd4c
	     should be used in preference to the uid/gid values when they are
Packit 08bd4c
	     set and the corresponding names exist on the system.
Packit 08bd4c
Packit 08bd4c
     devmajor, devminor
Packit 08bd4c
	     Major and minor numbers for character device or block device
Packit 08bd4c
	     entry.
Packit 08bd4c
Packit 08bd4c
     name, prefix
Packit 08bd4c
	     If the pathname is too long to fit in the 100 bytes provided by
Packit 08bd4c
	     the standard format, it can be split at any / character with the
Packit 08bd4c
	     first portion going into the prefix field.  If the prefix field
Packit 08bd4c
	     is not empty, the reader will prepend the prefix value and a /
Packit 08bd4c
	     character to the regular name field to obtain the full pathname.
Packit 08bd4c
	     The standard does not require a trailing / character on directory
Packit 08bd4c
	     names, though most implementations still include this for compat‐
Packit 08bd4c
	     ibility reasons.
Packit 08bd4c
Packit 08bd4c
     Note that all unused bytes must be set to NUL.
Packit 08bd4c
Packit 08bd4c
     Field termination is specified slightly differently by POSIX than by pre‐
Packit 08bd4c
     vious implementations.  The magic, uname, and gname fields must have a
Packit 08bd4c
     trailing NUL.  The pathname, linkname, and prefix fields must have a
Packit 08bd4c
     trailing NUL unless they fill the entire field.  (In particular, it is
Packit 08bd4c
     possible to store a 256-character pathname if it happens to have a / as
Packit 08bd4c
     the 156th character.)  POSIX requires numeric fields to be zero-padded in
Packit 08bd4c
     the front, and requires them to be terminated with either space or NUL
Packit 08bd4c
     characters.
Packit 08bd4c
Packit 08bd4c
     Currently, most tar implementations comply with the ustar format, occa‐
Packit 08bd4c
     sionally extending it by adding new fields to the blank area at the end
Packit 08bd4c
     of the header record.
Packit 08bd4c
Packit 08bd4c
   Numeric Extensions
Packit 08bd4c
     There have been several attempts to extend the range of sizes or times
Packit 08bd4c
     supported by modifying how numbers are stored in the header.
Packit 08bd4c
Packit 08bd4c
     One obvious extension to increase the size of files is to eliminate the
Packit 08bd4c
     terminating characters from the various numeric fields.  For example, the
Packit 08bd4c
     standard only allows the size field to contain 11 octal digits, reserving
Packit 08bd4c
     the twelfth byte for a trailing NUL character.  Allowing 12 octal digits
Packit 08bd4c
     allows file sizes up to 64 GB.
Packit 08bd4c
Packit 08bd4c
     Another extension, utilized by GNU tar, star, and other newer tar imple‐
Packit 08bd4c
     mentations, permits binary numbers in the standard numeric fields.  This
Packit 08bd4c
     is flagged by setting the high bit of the first byte.  The remainder of
Packit 08bd4c
     the field is treated as a signed twos-complement value.  This permits
Packit 08bd4c
     95-bit values for the length and time fields and 63-bit values for the
Packit 08bd4c
     uid, gid, and device numbers.  In particular, this provides a consistent
Packit 08bd4c
     way to handle negative time values.  GNU tar supports this extension for
Packit 08bd4c
     the length, mtime, ctime, and atime fields.  Joerg Schilling's star pro‐
Packit 08bd4c
     gram and the libarchive library support this extension for all numeric
Packit 08bd4c
     fields.  Note that this extension is largely obsoleted by the extended
Packit 08bd4c
     attribute record provided by the pax interchange format.
Packit 08bd4c
Packit 08bd4c
     Another early GNU extension allowed base-64 values rather than octal.
Packit 08bd4c
     This extension was short-lived and is no longer supported by any imple‐
Packit 08bd4c
     mentation.
Packit 08bd4c
Packit 08bd4c
   Pax Interchange Format
Packit 08bd4c
     There are many attributes that cannot be portably stored in a POSIX ustar
Packit 08bd4c
     archive.  IEEE Std 1003.1-2001 (“POSIX.1”) defined a “pax interchange
Packit 08bd4c
     format” that uses two new types of entries to hold text-formatted meta‐
Packit 08bd4c
     data that applies to following entries.  Note that a pax interchange for‐
Packit 08bd4c
     mat archive is a ustar archive in every respect.  The new data is stored
Packit 08bd4c
     in ustar-compatible archive entries that use the “x” or “g” typeflag.  In
Packit 08bd4c
     particular, older implementations that do not fully support these exten‐
Packit 08bd4c
     sions will extract the metadata into regular files, where the metadata
Packit 08bd4c
     can be examined as necessary.
Packit 08bd4c
Packit 08bd4c
     An entry in a pax interchange format archive consists of one or two stan‐
Packit 08bd4c
     dard ustar entries, each with its own header and data.  The first
Packit 08bd4c
     optional entry stores the extended attributes for the following entry.
Packit 08bd4c
     This optional first entry has an "x" typeflag and a size field that indi‐
Packit 08bd4c
     cates the total size of the extended attributes.  The extended attributes
Packit 08bd4c
     themselves are stored as a series of text-format lines encoded in the
Packit 08bd4c
     portable UTF-8 encoding.  Each line consists of a decimal number, a
Packit 08bd4c
     space, a key string, an equals sign, a value string, and a new line.  The
Packit 08bd4c
     decimal number indicates the length of the entire line, including the
Packit 08bd4c
     initial length field and the trailing newline.  An example of such a
Packit 08bd4c
     field is:
Packit 08bd4c
	   25 ctime=1084839148.1212\n
Packit 08bd4c
     Keys in all lowercase are standard keys.  Vendors can add their own keys
Packit 08bd4c
     by prefixing them with an all uppercase vendor name and a period.	Note
Packit 08bd4c
     that, unlike the historic header, numeric values are stored using deci‐
Packit 08bd4c
     mal, not octal.  A description of some common keys follows:
Packit 08bd4c
Packit 08bd4c
     atime, ctime, mtime
Packit 08bd4c
	     File access, inode change, and modification times.  These fields
Packit 08bd4c
	     can be negative or include a decimal point and a fractional
Packit 08bd4c
	     value.
Packit 08bd4c
Packit 08bd4c
     hdrcharset
Packit 08bd4c
	     The character set used by the pax extension values.  By default,
Packit 08bd4c
	     all textual values in the pax extended attributes are assumed to
Packit 08bd4c
	     be in UTF-8, including pathnames, user names, and group names.
Packit 08bd4c
	     In some cases, it is not possible to translate local conventions
Packit 08bd4c
	     into UTF-8.  If this key is present and the value is the six-
Packit 08bd4c
	     character ASCII string “BINARY”, then all textual values are
Packit 08bd4c
	     assumed to be in a platform-dependent multi-byte encoding.  Note
Packit 08bd4c
	     that there are only two valid values for this key: “BINARY” or
Packit 08bd4c
	     “ISO-IR 10646 2000 UTF-8”.  No other values are permitted by the
Packit 08bd4c
	     standard, and the latter value should generally not be used as it
Packit 08bd4c
	     is the default when this key is not specified.  In particular,
Packit 08bd4c
	     this flag should not be used as a general mechanism to allow
Packit 08bd4c
	     filenames to be stored in arbitrary encodings.
Packit 08bd4c
Packit 08bd4c
     uname, uid, gname, gid
Packit 08bd4c
	     User name, group name, and numeric UID and GID values.  The user
Packit 08bd4c
	     name and group name stored here are encoded in UTF8 and can thus
Packit 08bd4c
	     include non-ASCII characters.  The UID and GID fields can be of
Packit 08bd4c
	     arbitrary length.
Packit 08bd4c
Packit 08bd4c
     linkpath
Packit 08bd4c
	     The full path of the linked-to file.  Note that this is encoded
Packit 08bd4c
	     in UTF8 and can thus include non-ASCII characters.
Packit 08bd4c
Packit 08bd4c
     path    The full pathname of the entry.  Note that this is encoded in
Packit 08bd4c
	     UTF8 and can thus include non-ASCII characters.
Packit 08bd4c
Packit 08bd4c
     realtime.*, security.*
Packit 08bd4c
	     These keys are reserved and may be used for future standardiza‐
Packit 08bd4c
	     tion.
Packit 08bd4c
Packit 08bd4c
     size    The size of the file.  Note that there is no length limit on this
Packit 08bd4c
	     field, allowing conforming archives to store files much larger
Packit 08bd4c
	     than the historic 8GB limit.
Packit 08bd4c
Packit 08bd4c
     SCHILY.*
Packit 08bd4c
	     Vendor-specific attributes used by Joerg Schilling's star imple‐
Packit 08bd4c
	     mentation.
Packit 08bd4c
Packit 08bd4c
     SCHILY.acl.access, SCHILY.acl.default, SCHILY.acl.ace
Packit 08bd4c
	     Stores the access, default and NFSv4 ACLs as textual strings in a
Packit 08bd4c
	     format that is an extension of the format specified by POSIX.1e
Packit 08bd4c
	     draft 17.	In particular, each user or group access specification
Packit 08bd4c
	     can include an additional colon-separated field with the numeric
Packit 08bd4c
	     UID or GID.  This allows ACLs to be restored on systems that may
Packit 08bd4c
	     not have complete user or group information available (such as
Packit 08bd4c
	     when NIS/YP or LDAP services are temporarily unavailable).
Packit 08bd4c
Packit 08bd4c
     SCHILY.devminor, SCHILY.devmajor
Packit 08bd4c
	     The full minor and major numbers for device nodes.
Packit 08bd4c
Packit 08bd4c
     SCHILY.fflags
Packit 08bd4c
	     The file flags.
Packit 08bd4c
Packit 08bd4c
     SCHILY.realsize
Packit 08bd4c
	     The full size of the file on disk.  XXX explain? XXX
Packit 08bd4c
Packit 08bd4c
     SCHILY.dev, SCHILY.ino, SCHILY.nlinks
Packit 08bd4c
	     The device number, inode number, and link count for the entry.
Packit 08bd4c
	     In particular, note that a pax interchange format archive using
Packit 08bd4c
	     Joerg Schilling's SCHILY.* extensions can store all of the data
Packit 08bd4c
	     from struct stat.
Packit 08bd4c
Packit 08bd4c
     LIBARCHIVE.*
Packit 08bd4c
	     Vendor-specific attributes used by the libarchive library and
Packit 08bd4c
	     programs that use it.
Packit 08bd4c
Packit 08bd4c
     LIBARCHIVE.creationtime
Packit 08bd4c
	     The time when the file was created.  (This should not be confused
Packit 08bd4c
	     with the POSIX “ctime” attribute, which refers to the time when
Packit 08bd4c
	     the file metadata was last changed.)
Packit 08bd4c
Packit 08bd4c
     LIBARCHIVE.xattr.namespace.key
Packit 08bd4c
	     Libarchive stores POSIX.1e-style extended attributes using keys
Packit 08bd4c
	     of this form.  The key value is URL-encoded: All non-ASCII char‐
Packit 08bd4c
	     acters and the two special characters “=” and “%” are encoded as
Packit 08bd4c
	     “%” followed by two uppercase hexadecimal digits.	The value of
Packit 08bd4c
	     this key is the extended attribute value encoded in base 64.  XXX
Packit 08bd4c
	     Detail the base-64 format here XXX
Packit 08bd4c
Packit 08bd4c
     VENDOR.*
Packit 08bd4c
	     XXX document other vendor-specific extensions XXX
Packit 08bd4c
Packit 08bd4c
     Any values stored in an extended attribute override the corresponding
Packit 08bd4c
     values in the regular tar header.	Note that compliant readers should
Packit 08bd4c
     ignore the regular fields when they are overridden.  This is important,
Packit 08bd4c
     as existing archivers are known to store non-compliant values in the
Packit 08bd4c
     standard header fields in this situation.	There are no limits on length
Packit 08bd4c
     for any of these fields.  In particular, numeric fields can be arbitrar‐
Packit 08bd4c
     ily large.  All text fields are encoded in UTF8.  Compliant writers
Packit 08bd4c
     should store only portable 7-bit ASCII characters in the standard ustar
Packit 08bd4c
     header and use extended attributes whenever a text value contains non-
Packit 08bd4c
     ASCII characters.
Packit 08bd4c
Packit 08bd4c
     In addition to the x entry described above, the pax interchange format
Packit 08bd4c
     also supports a g entry.  The g entry is identical in format, but speci‐
Packit 08bd4c
     fies attributes that serve as defaults for all subsequent archive
Packit 08bd4c
     entries.  The g entry is not widely used.
Packit 08bd4c
Packit 08bd4c
     Besides the new x and g entries, the pax interchange format has a few
Packit 08bd4c
     other minor variations from the earlier ustar format.  The most troubling
Packit 08bd4c
     one is that hardlinks are permitted to have data following them.  This
Packit 08bd4c
     allows readers to restore any hardlink to a file without having to rewind
Packit 08bd4c
     the archive to find an earlier entry.  However, it creates complications
Packit 08bd4c
     for robust readers, as it is no longer clear whether or not they should
Packit 08bd4c
     ignore the size field for hardlink entries.
Packit 08bd4c
Packit 08bd4c
   GNU Tar Archives
Packit 08bd4c
     The GNU tar program started with a pre-POSIX format similar to that
Packit 08bd4c
     described earlier and has extended it using several different mechanisms:
Packit 08bd4c
     It added new fields to the empty space in the header (some of which was
Packit 08bd4c
     later used by POSIX for conflicting purposes); it allowed the header to
Packit 08bd4c
     be continued over multiple records; and it defined new entries that mod‐
Packit 08bd4c
     ify following entries (similar in principle to the x entry described
Packit 08bd4c
     above, but each GNU special entry is single-purpose, unlike the general-
Packit 08bd4c
     purpose x entry).	As a result, GNU tar archives are not POSIX compati‐
Packit 08bd4c
     ble, although more lenient POSIX-compliant readers can successfully
Packit 08bd4c
     extract most GNU tar archives.
Packit 08bd4c
Packit 08bd4c
	   struct header_gnu_tar {
Packit 08bd4c
		   char name[100];
Packit 08bd4c
		   char mode[8];
Packit 08bd4c
		   char uid[8];
Packit 08bd4c
		   char gid[8];
Packit 08bd4c
		   char size[12];
Packit 08bd4c
		   char mtime[12];
Packit 08bd4c
		   char checksum[8];
Packit 08bd4c
		   char typeflag[1];
Packit 08bd4c
		   char linkname[100];
Packit 08bd4c
		   char magic[6];
Packit 08bd4c
		   char version[2];
Packit 08bd4c
		   char uname[32];
Packit 08bd4c
		   char gname[32];
Packit 08bd4c
		   char devmajor[8];
Packit 08bd4c
		   char devminor[8];
Packit 08bd4c
		   char atime[12];
Packit 08bd4c
		   char ctime[12];
Packit 08bd4c
		   char offset[12];
Packit 08bd4c
		   char longnames[4];
Packit 08bd4c
		   char unused[1];
Packit 08bd4c
		   struct {
Packit 08bd4c
			   char offset[12];
Packit 08bd4c
			   char numbytes[12];
Packit 08bd4c
		   } sparse[4];
Packit 08bd4c
		   char isextended[1];
Packit 08bd4c
		   char realsize[12];
Packit 08bd4c
		   char pad[17];
Packit 08bd4c
	   };
Packit 08bd4c
Packit 08bd4c
     typeflag
Packit 08bd4c
	     GNU tar uses the following special entry types, in addition to
Packit 08bd4c
	     those defined by POSIX:
Packit 08bd4c
Packit 08bd4c
	     7	     GNU tar treats type "7" records identically to type "0"
Packit 08bd4c
		     records, except on one obscure RTOS where they are used
Packit 08bd4c
		     to indicate the pre-allocation of a contiguous file on
Packit 08bd4c
		     disk.
Packit 08bd4c
Packit 08bd4c
	     D	     This indicates a directory entry.	Unlike the POSIX-stan‐
Packit 08bd4c
		     dard "5" typeflag, the header is followed by data records
Packit 08bd4c
		     listing the names of files in this directory.  Each name
Packit 08bd4c
		     is preceded by an ASCII "Y" if the file is stored in this
Packit 08bd4c
		     archive or "N" if the file is not stored in this archive.
Packit 08bd4c
		     Each name is terminated with a null, and an extra null
Packit 08bd4c
		     marks the end of the name list.  The purpose of this
Packit 08bd4c
		     entry is to support incremental backups; a program
Packit 08bd4c
		     restoring from such an archive may wish to delete files
Packit 08bd4c
		     on disk that did not exist in the directory when the ar‐
Packit 08bd4c
		     chive was made.
Packit 08bd4c
Packit 08bd4c
		     Note that the "D" typeflag specifically violates POSIX,
Packit 08bd4c
		     which requires that unrecognized typeflags be restored as
Packit 08bd4c
		     normal files.  In this case, restoring the "D" entry as a
Packit 08bd4c
		     file could interfere with subsequent creation of the
Packit 08bd4c
		     like-named directory.
Packit 08bd4c
Packit 08bd4c
	     K	     The data for this entry is a long linkname for the fol‐
Packit 08bd4c
		     lowing regular entry.
Packit 08bd4c
Packit 08bd4c
	     L	     The data for this entry is a long pathname for the fol‐
Packit 08bd4c
		     lowing regular entry.
Packit 08bd4c
Packit 08bd4c
	     M	     This is a continuation of the last file on the previous
Packit 08bd4c
		     volume.  GNU multi-volume archives guarantee that each
Packit 08bd4c
		     volume begins with a valid entry header.  To ensure this,
Packit 08bd4c
		     a file may be split, with part stored at the end of one
Packit 08bd4c
		     volume, and part stored at the beginning of the next vol‐
Packit 08bd4c
		     ume.  The "M" typeflag indicates that this entry contin‐
Packit 08bd4c
		     ues an existing file.  Such entries can only occur as the
Packit 08bd4c
		     first or second entry in an archive (the latter only if
Packit 08bd4c
		     the first entry is a volume label).  The size field spec‐
Packit 08bd4c
		     ifies the size of this entry.  The offset field at bytes
Packit 08bd4c
		     369-380 specifies the offset where this file fragment
Packit 08bd4c
		     begins.  The realsize field specifies the total size of
Packit 08bd4c
		     the file (which must equal size plus offset).  When
Packit 08bd4c
		     extracting, GNU tar checks that the header file name is
Packit 08bd4c
		     the one it is expecting, that the header offset is in the
Packit 08bd4c
		     correct sequence, and that the sum of offset and size is
Packit 08bd4c
		     equal to realsize.
Packit 08bd4c
Packit 08bd4c
	     N	     Type "N" records are no longer generated by GNU tar.
Packit 08bd4c
		     They contained a list of files to be renamed or symlinked
Packit 08bd4c
		     after extraction; this was originally used to support
Packit 08bd4c
		     long names.  The contents of this record are a text
Packit 08bd4c
		     description of the operations to be done, in the form
Packit 08bd4c
		     “Rename %s to %s\n” or “Symlink %s to %s\n”; in either
Packit 08bd4c
		     case, both filenames are escaped using K&R C syntax.  Due
Packit 08bd4c
		     to security concerns, "N" records are now generally
Packit 08bd4c
		     ignored when reading archives.
Packit 08bd4c
Packit 08bd4c
	     S	     This is a “sparse” regular file.  Sparse files are stored
Packit 08bd4c
		     as a series of fragments.	The header contains a list of
Packit 08bd4c
		     fragment offset/length pairs.  If more than four such
Packit 08bd4c
		     entries are required, the header is extended as necessary
Packit 08bd4c
		     with “extra” header extensions (an older format that is
Packit 08bd4c
		     no longer used), or “sparse” extensions.
Packit 08bd4c
Packit 08bd4c
	     V	     The name field should be interpreted as a tape/volume
Packit 08bd4c
		     header name.  This entry should generally be ignored on
Packit 08bd4c
		     extraction.
Packit 08bd4c
Packit 08bd4c
     magic   The magic field holds the five characters “ustar” followed by a
Packit 08bd4c
	     space.  Note that POSIX ustar archives have a trailing null.
Packit 08bd4c
Packit 08bd4c
     version
Packit 08bd4c
	     The version field holds a space character followed by a null.
Packit 08bd4c
	     Note that POSIX ustar archives use two copies of the ASCII digit
Packit 08bd4c
	     “0”.
Packit 08bd4c
Packit 08bd4c
     atime, ctime
Packit 08bd4c
	     The time the file was last accessed and the time of last change
Packit 08bd4c
	     of file information, stored in octal as with mtime.
Packit 08bd4c
Packit 08bd4c
     longnames
Packit 08bd4c
	     This field is apparently no longer used.
Packit 08bd4c
Packit 08bd4c
     Sparse offset / numbytes
Packit 08bd4c
	     Each such structure specifies a single fragment of a sparse file.
Packit 08bd4c
	     The two fields store values as octal numbers.  The fragments are
Packit 08bd4c
	     each padded to a multiple of 512 bytes in the archive.  On
Packit 08bd4c
	     extraction, the list of fragments is collected from the header
Packit 08bd4c
	     (including any extension headers), and the data is then read and
Packit 08bd4c
	     written to the file at appropriate offsets.
Packit 08bd4c
Packit 08bd4c
     isextended
Packit 08bd4c
	     If this is set to non-zero, the header will be followed by addi‐
Packit 08bd4c
	     tional “sparse header” records.  Each such record contains infor‐
Packit 08bd4c
	     mation about as many as 21 additional sparse blocks as shown
Packit 08bd4c
	     here:
Packit 08bd4c
Packit 08bd4c
		   struct gnu_sparse_header {
Packit 08bd4c
			   struct {
Packit 08bd4c
				   char offset[12];
Packit 08bd4c
				   char numbytes[12];
Packit 08bd4c
			   } sparse[21];
Packit 08bd4c
			   char    isextended[1];
Packit 08bd4c
			   char    padding[7];
Packit 08bd4c
		   };
Packit 08bd4c
Packit 08bd4c
     realsize
Packit 08bd4c
	     A binary representation of the file's complete size, with a much
Packit 08bd4c
	     larger range than the POSIX file size.  In particular, with M
Packit 08bd4c
	     type files, the current entry is only a portion of the file.  In
Packit 08bd4c
	     that case, the POSIX size field will indicate the size of this
Packit 08bd4c
	     entry; the realsize field will indicate the total size of the
Packit 08bd4c
	     file.
Packit 08bd4c
Packit 08bd4c
   GNU tar pax archives
Packit 08bd4c
     GNU tar 1.14 (XXX check this XXX) and later will write pax interchange
Packit 08bd4c
     format archives when you specify the --posix flag.  This format follows
Packit 08bd4c
     the pax interchange format closely, using some SCHILY tags and introduc‐
Packit 08bd4c
     ing new keywords to store sparse file information.  There have been three
Packit 08bd4c
     iterations of the sparse file support, referred to as “0.0”, “0.1”, and
Packit 08bd4c
     “1.0”.
Packit 08bd4c
Packit 08bd4c
     GNU.sparse.numblocks, GNU.sparse.offset, GNU.sparse.numbytes,
Packit 08bd4c
	     GNU.sparse.size
Packit 08bd4c
	     The “0.0” format used an initial GNU.sparse.numblocks attribute
Packit 08bd4c
	     to indicate the number of blocks in the file, a pair of
Packit 08bd4c
	     GNU.sparse.offset and GNU.sparse.numbytes to indicate the offset
Packit 08bd4c
	     and size of each block, and a single GNU.sparse.size to indicate
Packit 08bd4c
	     the full size of the file.  This is not the same as the size in
Packit 08bd4c
	     the tar header because the latter value does not include the size
Packit 08bd4c
	     of any holes.  This format required that the order of attributes
Packit 08bd4c
	     be preserved and relied on readers accepting multiple appearances
Packit 08bd4c
	     of the same attribute names, which is not officially permitted by
Packit 08bd4c
	     the standards.
Packit 08bd4c
Packit 08bd4c
     GNU.sparse.map
Packit 08bd4c
	     The “0.1” format used a single attribute that stored a comma-sep‐
Packit 08bd4c
	     arated list of decimal numbers.  Each pair of numbers indicated
Packit 08bd4c
	     the offset and size, respectively, of a block of data.  This does
Packit 08bd4c
	     not work well if the archive is extracted by an archiver that
Packit 08bd4c
	     does not recognize this extension, since many pax implementations
Packit 08bd4c
	     simply discard unrecognized attributes.
Packit 08bd4c
Packit 08bd4c
     GNU.sparse.major, GNU.sparse.minor, GNU.sparse.name, GNU.sparse.realsize
Packit 08bd4c
	     The “1.0” format stores the sparse block map in one or more
Packit 08bd4c
	     512-byte blocks prepended to the file data in the entry body.
Packit 08bd4c
	     The pax attributes indicate the existence of this map (via the
Packit 08bd4c
	     GNU.sparse.major and GNU.sparse.minor fields) and the full size
Packit 08bd4c
	     of the file.  The GNU.sparse.name holds the true name of the
Packit 08bd4c
	     file.  To avoid confusion, the name stored in the regular tar
Packit 08bd4c
	     header is a modified name so that extraction errors will be
Packit 08bd4c
	     apparent to users.
Packit 08bd4c
Packit 08bd4c
   Solaris Tar
Packit 08bd4c
     XXX More Details Needed XXX
Packit 08bd4c
Packit 08bd4c
     Solaris tar (beginning with SunOS XXX 5.7 ?? XXX) supports an “extended”
Packit 08bd4c
     format that is fundamentally similar to pax interchange format, with the
Packit 08bd4c
     following differences:
Packit 08bd4c
     ·	     Extended attributes are stored in an entry whose type is X, not
Packit 08bd4c
	     x, as used by pax interchange format.  The detailed format of
Packit 08bd4c
	     this entry appears to be the same as detailed above for the x
Packit 08bd4c
	     entry.
Packit 08bd4c
     ·	     An additional A header is used to store an ACL for the following
Packit 08bd4c
	     regular entry.  The body of this entry contains a seven-digit
Packit 08bd4c
	     octal number followed by a zero byte, followed by the textual ACL
Packit 08bd4c
	     description.  The octal value is the number of ACL entries plus a
Packit 08bd4c
	     constant that indicates the ACL type: 01000000 for POSIX.1e ACLs
Packit 08bd4c
	     and 03000000 for NFSv4 ACLs.
Packit 08bd4c
Packit 08bd4c
   AIX Tar
Packit 08bd4c
     XXX More details needed XXX
Packit 08bd4c
Packit 08bd4c
     AIX Tar uses a ustar-formatted header with the type A for storing coded
Packit 08bd4c
     ACL information.  Unlike the Solaris format, AIX tar writes this header
Packit 08bd4c
     after the regular file body to which it applies.  The pathname in this
Packit 08bd4c
     header is either NFS4 or AIXC to indicate the type of ACL stored.	The
Packit 08bd4c
     actual ACL is stored in platform-specific binary format.
Packit 08bd4c
Packit 08bd4c
   Mac OS X Tar
Packit 08bd4c
     The tar distributed with Apple's Mac OS X stores most regular files as
Packit 08bd4c
     two separate files in the tar archive.  The two files have the same name
Packit 08bd4c
     except that the first one has “._” prepended to the last path element.
Packit 08bd4c
     This special file stores an AppleDouble-encoded binary blob with addi‐
Packit 08bd4c
     tional metadata about the second file, including ACL, extended
Packit 08bd4c
     attributes, and resources.  To recreate the original file on disk, each
Packit 08bd4c
     separate file can be extracted and the Mac OS X copyfile() function can
Packit 08bd4c
     be used to unpack the separate metadata file and apply it to th regular
Packit 08bd4c
     file.  Conversely, the same function provides a “pack” option to encode
Packit 08bd4c
     the extended metadata from a file into a separate file whose contents can
Packit 08bd4c
     then be put into a tar archive.
Packit 08bd4c
Packit 08bd4c
     Note that the Apple extended attributes interact badly with long file‐
Packit 08bd4c
     names.  Since each file is stored with the full name, a separate set of
Packit 08bd4c
     extensions needs to be included in the archive for each one, doubling the
Packit 08bd4c
     overhead required for files with long names.
Packit 08bd4c
Packit 08bd4c
   Summary of tar type codes
Packit 08bd4c
     The following list is a condensed summary of the type codes used in tar
Packit 08bd4c
     header records generated by different tar implementations.  More details
Packit 08bd4c
     about specific implementations can be found above:
Packit 08bd4c
     NUL  Early tar programs stored a zero byte for regular files.
Packit 08bd4c
     0	  POSIX standard type code for a regular file.
Packit 08bd4c
     1	  POSIX standard type code for a hard link description.
Packit 08bd4c
     2	  POSIX standard type code for a symbolic link description.
Packit 08bd4c
     3	  POSIX standard type code for a character device node.
Packit 08bd4c
     4	  POSIX standard type code for a block device node.
Packit 08bd4c
     5	  POSIX standard type code for a directory.
Packit 08bd4c
     6	  POSIX standard type code for a FIFO.
Packit 08bd4c
     7	  POSIX reserved.
Packit 08bd4c
     7	  GNU tar used for pre-allocated files on some systems.
Packit 08bd4c
     A	  Solaris tar ACL description stored prior to a regular file header.
Packit 08bd4c
     A	  AIX tar ACL description stored after the file body.
Packit 08bd4c
     D	  GNU tar directory dump.
Packit 08bd4c
     K	  GNU tar long linkname for the following header.
Packit 08bd4c
     L	  GNU tar long pathname for the following header.
Packit 08bd4c
     M	  GNU tar multivolume marker, indicating the file is a continuation of
Packit 08bd4c
	  a file from the previous volume.
Packit 08bd4c
     N	  GNU tar long filename support.  Deprecated.
Packit 08bd4c
     S	  GNU tar sparse regular file.
Packit 08bd4c
     V	  GNU tar tape/volume header name.
Packit 08bd4c
     X	  Solaris tar general-purpose extension header.
Packit 08bd4c
     g	  POSIX pax interchange format global extensions.
Packit 08bd4c
     x	  POSIX pax interchange format per-file extensions.
Packit 08bd4c
Packit 08bd4c
SEE ALSO
Packit 08bd4c
     ar(1), pax(1), tar(1)
Packit 08bd4c
Packit 08bd4c
STANDARDS
Packit 08bd4c
     The tar utility is no longer a part of POSIX or the Single Unix Standard.
Packit 08bd4c
     It last appeared in Version 2 of the Single UNIX Specification (“SUSv2”).
Packit 08bd4c
     It has been supplanted in subsequent standards by pax(1).	The ustar for‐
Packit 08bd4c
     mat is currently part of the specification for the pax(1) utility.  The
Packit 08bd4c
     pax interchange file format is new with IEEE Std 1003.1-2001 (“POSIX.1”).
Packit 08bd4c
Packit 08bd4c
HISTORY
Packit 08bd4c
     A tar command appeared in Seventh Edition Unix, which was released in
Packit 08bd4c
     January, 1979.  It replaced the tp program from Fourth Edition Unix which
Packit 08bd4c
     in turn replaced the tap program from First Edition Unix.	John Gilmore's
Packit 08bd4c
     pdtar public-domain implementation (circa 1987) was highly influential
Packit 08bd4c
     and formed the basis of GNU tar (circa 1988).  Joerg Shilling's star
Packit 08bd4c
     archiver is another open-source (CDDL) archiver (originally developed
Packit 08bd4c
     circa 1985) which features complete support for pax interchange format.
Packit 08bd4c
Packit 08bd4c
     This documentation was written as part of the libarchive and bsdtar
Packit 08bd4c
     project by Tim Kientzle <kientzle@FreeBSD.org>.
Packit 08bd4c
Packit 08bd4c
BSD			       December 27, 2016			   BSD