Blame doc/text/tar.5.txt

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