The typeflag byte at offset 156 of the
header says what kind of member it
describes. It is a single ASCII character. Some flags describe a file system object;
others mark a header that carries information about the member after it. The names in
the tables are those of the tar.h header file.
Files, links and folders
These are the flags of POSIX.1-1988, with the NUL of Version 7. The last column says whether data blocks follow the header.
| Flag | Name | Member | Description | Data |
|---|---|---|---|---|
0 (30) | REGTYPE | Regular file | The data blocks after the header are the file’s contents. | size bytes |
NUL (00) | AREGTYPE | Regular file | The old form of 0, kept for compatibility. In old archives a name ending in / is a folder. | size bytes |
1 | LNKTYPE | Hard link | Another name for a file stored earlier in the archive; linkname names it. | none in ustar; size bytes in a pax archive made with -o linkdata |
2 | SYMTYPE | Symbolic link | linkname holds the link’s target. | none |
3 | CHRTYPE | Character device | devmajor and devminor give the device numbers. | none |
4 | BLKTYPE | Block device | As for a character device. | none |
5 | DIRTYPE | Directory | A folder. POSIX lets size give a space limit, zero for none; writers end the name with /. | none |
6 | FIFOTYPE | FIFO | A named pipe. | none |
7 | CONTTYPE | Contiguous file | Reserved by POSIX for high-performance files stored in one piece. Readers treat it as 0. | size bytes |
For types 2 to 6, Go and libarchive skip no data whatever
size says; one of Go’s test archives has a size of 5 on such members. The
explorer does the same, and follows the size only when the block after the header is
not a header and the block after the data would be, reporting it when it does.
Type 1 is less simple. In the ustar format a hard link carries no data
and its size is zero, but POSIX.1-2001 lets a hard link in a pax archive have data, so
that a reader can restore any link without going back for the first copy: “data blocks
for files of typeflag 1 (the digit one) (hard link) may be included”, and archives
made with pax -o linkdata have them. tar(5) calls this “the most troubling”
of the pax changes, since a reader cannot tell. libarchive obeys the size once it knows
the archive is pax, and otherwise ignores it when a valid header follows. The explorer
does the same: after any x or g header in the archive, a hard
link’s size is obeyed unless the blocks where its data would end are not a header
(or the end of the file).
Extended headers
POSIX.1-2001 added two flags for headers whose data is a list of key and value records. See pax extensions.
| Flag | Name | Header | Description |
|---|---|---|---|
x | XHDTYPE | Extended header | Records that apply to the next member only, such as its full path or exact size. |
g | XGLTYPE | Global extended header | Records that apply to every following member, until changed by another g header. |
X | SOLARIS_XHDTYPE | Solaris extended header | Written by Sun’s tar. libarchive reads it like x (“Used by SUN tar; same as ‘x’.”), and so does the explorer. |
Vendor flags
POSIX reserves the capital letters A to Z for custom
implementations, and other values for future use. A reader that meets a flag it does
not know must extract the member as a regular file if its size says data follows, and
the pax utility must report it; libarchive’s tar(5) puts it as “A
POSIX-compliant implementation must treat any unrecognized typeflag value as a
regular file.” This is why an old program extracting a pax archive leaves small extra
files named after the pax headers.
These are the vendor flags readers meet in ustar archives. Most belong to other formats, and the explorer links each to its page there.
| Flag | From | Meaning |
|---|---|---|
A | Solaris and AIX | Security attributes of the next file (Solaris) or an access control list for the file before (AIX): see ACL members. |
D | GNU tar | A dump directory in an incremental backup. |
E | Solaris | An extended attribute: a header member, then a member holding the attribute. |
I | star | Inode metadata only, usually after an x header; used by incremental backups. star(5): “The size field holds the length of the file. No file data follows this header.” |
K | GNU tar | Its data is the long link target of the next member. |
L | GNU tar | Its data is the long name of the next member. |
M | GNU tar | The rest of a file begun on the previous volume of a multi-volume archive. |
N | GNU tar | An old way of storing long names. See old names. |
S | GNU tar | A sparse file, with only the parts that hold data stored. |
V | GNU tar | A volume label, held in name. |
In a pax archive the same information has standard places: long names in
path and linkpath records, and sparse files in
GNU.sparse.
records.
ACL members (A)
Solaris tar writes a member of type A
(ACL_HDR) just before a file that has an access control list or other
security attributes. Its size is the length of the encoded attributes, and its data is
a run of records (struct sec_attr in illumos’s tar.c), one
after another until the size is used up:
| Offset | Size | Name | Meaning |
|---|---|---|---|
0 | 1 | attr_type | What the record holds (below). |
1 | 7 | attr_len | Six digits and a NUL: for an ACL the number of entries, in octal; for a Trusted Extensions record the length of the text, in decimal. |
8 | varies | attr_info | The text, then a NUL. The record is 8 bytes plus the text plus 1. |
| Type | Name | Record |
|---|---|---|
1 | UFSD_ACL | A POSIX-draft ACL, as comma-separated text such as user::rwx,group::r-x,mask:r-x,other:r--, with defaultuser: and the like for a folder’s default entries. |
2 | UFSD_DFACL | Reserved. |
3 | ACE_ACL | An NFSv4 ACL, as comma-separated entries such as owner@:rw-p--aARWcCos:-------:allow. |
D, L | DIR_TYPE, LBL_TYPE | Trusted Extensions labels of a directory or a file. |
S, M, P, p, F, C, K | SLD_TYPE, MLD_TYPE, PATH_TYPE or APRIV_TYPE, FPRIV_TYPE, FILE_TYPE or ATTR_FLAG_TYPE, COMP_TYPE, LK_COMP_TYPE | Trusted Solaris records, read for compatibility: directory components, path components, privileges and attribute flags. |
tar(5) describes an ACL member as “a seven-digit octal number followed by a zero
byte”, the entry count plus 01000000 for POSIX.1e or 03000000 for NFSv4, then the
text. That is the first record read as one number: the type character
1 or 3 followed by the six octal digits of the count. The
entries’ letters and fields are listed on
star’s pax page. The
explorer reads every record and spells out each ACL entry.
AIX tar writes its type A member after the file, with
the pathname NFS4 or AIXC for the kind of ACL. tar(5): “The
actual ACL is stored in platform-specific binary format.” IBM says the formats are
defined in its sys/acl.h; no published byte layout was found, so the
explorer names the kind and shows the bytes.
Solaris extended attributes (E)
Solaris tar stores a file’s extended attributes after the file, each as two members of
type E (_XATTR_HDRTYPE). The layout is in
archives.h, the header file illumos publishes, and the numbers’ form is
in its tar.c. The first member, named like
/dev/null/attr.hdr, holds a header; the second, named
/dev/null/attr, holds the attribute’s contents. A program that does not
know this type extracts them under /dev/null, so they are discarded.
The header member’s data starts with struct xattr_hdr, 37 bytes. Numbers
are decimal text padded with leading zeros, ended by a NUL.
| Offset | Size | Name | Meaning |
|---|---|---|---|
0 | 7 | h_version | The format version, 1.0 (XATTR_ARCH_VERS). |
7 | 10 | h_size | The size of this header and the sections after it. |
17 | 10 | h_component_len | The length of the path section that follows. |
27 | 10 | h_link_component_len | The length of the link section, zero when there is none. |
Then a struct xattr_buf, and a second one, the link section, when the
attribute is a hard link to another attribute:
| Offset | Size | Name | Meaning |
|---|---|---|---|
0 | 7 | h_namesz | The length of h_names. |
7 | 1 | h_typeflag | The type flag of the file being archived: what the attribute really is. |
8 | h_namesz | h_names | The file’s path, a NUL, the attribute’s path, a NUL. A further path after another NUL names a system attribute of that attribute. |
h_component_len is h_namesz plus 9, the size of the C
structure with its one-byte array, so one filler byte ends each section. The explorer
shows the header’s fields and paths and opens the second member’s contents as a
file.
E is unrelated to the X header above; Solaris’s ACLs are
type A.
macOS metadata members
The tar that comes with macOS stores most regular files as two members. tar(5): “The
two files have the same name except that the first one has "._" prepended to the last
path element”, and that first member is “an AppleDouble-encoded binary blob” with
the second file’s metadata, ACLs, extended attributes and resources. The members are
of ordinary type 0, so other programs extract them as small files
beginning ._. The explorer opens the first as an
AppleDouble file.