The pax format, from POSIX.1-2001, keeps the ustar header and adds extended headers that hold any number of key and value records. They lift the old limits: paths of any length, files of any size, times with fractions of a second, Unicode names and extended attributes. A reader that does not know them extracts them as small regular files and reads the rest of the archive as plain ustar.
Extended headers
An extended header is an ordinary 512-byte
header with type flag
x, followed by data blocks holding the records. Its own
size is the length of the records. It applies to the member straight after
it: POSIX’s order is the optional x header and its data, then the ustar
header the records apply to, then that member’s data. Its records replace the matching
fields of the member’s header.
0Extended header type flagx512 bytes512Records padded with zeros to a multiple of 512size rounded up…Member header the ustar header the records apply to512 bytes…Member datasize rounded up
The extended header’s own name is not used for anything. POSIX’s default is
%d/PaxHeaders.%p/%f: the member’s folder, PaxHeaders. and the
process ID, then its file name. So a program that does not understand pax extracts it as
a small, recognisable file. GNU tar writes names in this form; Go writes
PaxHeaders.0/ and the name.
Solaris tar wrote extended headers with type X. Readers such as
libarchive, and the explorer, treat them as x.
A worked example, from Go’s test archive pax.tar: the x
header is named a/PaxHeaders.6887/123456789101112…, its size is
00000000446 (294 bytes) and its type flag at 0x9C is
78. Its data starts at the next block:
00000200 32 30 34 20 70 61 74 68 3D 61 2F 31 32 33 34 35 204 path=a/12345
path record for a long path.Global headers
A header with type flag g holds records in the same form, but they apply
to every member that follows, until another g header changes them. A
g header can appear anywhere in the archive, and there may be several. Its
records give defaults: a record in a member’s own x header takes priority
over a global one.
POSIX’s default name for a global header is
$TMPDIR/GlobalHead.%p.%n: the temporary folder, the process ID and a
sequence number. Go writes GlobalHead.0.0.
Records
Each record is a line of text, in the form "%d %s=%s\n":
30 mtime=1730851200.123456789
51 path=a/very/long/directory/name/report-2024.pdf
The line is a decimal length, a space, the keyword, =, the value and a
line feed. The length counts the whole record in bytes, including the digits of the
length itself, the space and the line feed. In the first record above,
mtime=1730851200.123456789 is 26 bytes; with the two digits of
30, the space and the line feed, the whole record is 30 bytes. Because of
the length, a value can contain any byte, line feeds included.
To read the records:
- Read decimal digits up to a space: the length n.
- The record is the n bytes from the first digit. Its last byte must be a line feed.
- After the space, the keyword runs to the first
=; keywords are UTF-8 and cannot contain=. - The value is everything after the
=up to the final line feed. - Move on n bytes and repeat, until the header’s
sizeis used up.
Keywords are UTF-8. Values are UTF-8 unless a hdrcharset record says
otherwise. Numbers are decimal text of any length, and times are seconds since 1970
with an optional fraction, which may be negative. A record with an empty value deletes
the field, or the value an earlier record set; an empty size leaves
nothing else to say how much data follows, so a reader still skips by the header’s
own size, and the explorer does the same.
Keys
The keywords POSIX defines:
| Keyword | Meaning |
|---|---|
path | The member’s full path, replacing name and prefix. |
linkpath | The full link target, replacing linkname. |
size | The size of the data, for files of 8 GiB or more. |
uid, gid | The numeric owner and group, for values too large for the header. |
uname, gname | The owner and group names, of any length. |
mtime | The modification time, in seconds with an optional fraction. |
atime | The access time, in the same form. |
comment | Free text, ignored when extracting. |
charset | The character set of the file’s contents, for information only (see below). |
hdrcharset | The character set of the path, linkpath, uname and gname values (see below). The default is UTF-8. |
realtime.… | Reserved by POSIX for future standardisation. |
security.… | Reserved by POSIX for future standardisation. |
ctime, the status change time, is not in POSIX’s list, but GNU tar and Go
write it and libarchive reads it.
POSIX reserves every keyword made only of lower-case letters, digits and periods for
future standardisation. Other names are extensions; star(5) gives the convention for
them as VENDOR.keyword, with the vendor’s name in capitals.
charset values
POSIX lists these values for charset. The value describes the file’s
data and does not change it: pax does not translate the data.
| Value | Standard |
|---|---|
ISO-IR 646 1990 | ISO/IEC 646:1990 |
ISO-IR 8859 1 1998 | ISO/IEC 8859-1:1998 |
ISO-IR 8859 2 1999 | ISO/IEC 8859-2:1999 |
ISO-IR 8859 3 1999 | ISO/IEC 8859-3:1999 |
ISO-IR 8859 4 1998 | ISO/IEC 8859-4:1998 |
ISO-IR 8859 5 1999 | ISO/IEC 8859-5:1999 |
ISO-IR 8859 6 1999 | ISO/IEC 8859-6:1999 |
ISO-IR 8859 7 1987 | ISO/IEC 8859-7:1987 |
ISO-IR 8859 8 1999 | ISO/IEC 8859-8:1999 |
ISO-IR 8859 9 1999 | ISO/IEC 8859-9:1999 |
ISO-IR 8859 10 1998 | ISO/IEC 8859-10:1998 |
ISO-IR 8859 13 1998 | ISO/IEC 8859-13:1998 |
ISO-IR 8859 14 1998 | ISO/IEC 8859-14:1998 |
ISO-IR 8859 15 1999 | ISO/IEC 8859-15:1999 |
ISO-IR 10646 2000 | ISO/IEC 10646:2000 |
ISO-IR 10646 2000 UTF-8 | ISO/IEC 10646, UTF-8 encoding |
BINARY | Unencoded binary data |
hdrcharset values
| Value | Meaning |
|---|---|
ISO-IR 10646 2000 UTF-8 | The name fields are UTF-8. This is the default when there is no hdrcharset record. |
BINARY | The name fields are unencoded binary data from the system that wrote the archive. |
The explorer shows every value as UTF-8 when it is valid and as Latin-1 when not, so
no byte is lost, and notes a BINARY value for the four name fields it
applies to.
When the same value is set in several places, POSIX gives this order for reading and listing; the first that applies wins:
- a
-o delete=option of thepaxcommand; - a
-o keyword:=option; - a
-o keyword:=valueoption; - a record in the member’s
xheader (the last one, if the keyword appears twice); - a
-o keyword=valueoption; - a record in a
gheader (again the last one); - the ustar header itself.
Sparse files
GNU tar writes sparse files in pax archives with GNU.sparse. records. The
GNU manual describes three versions, by the release of GNU tar that wrote them:
| Version | GNU tar | Records | Where the map is |
|---|---|---|---|
| 0.0 | 1.14 to 1.15.1 | GNU.sparse.size, GNU.sparse.numblocks, then repeated GNU.sparse.offset and GNU.sparse.numbytes | in the records, one pair per stretch of data |
| 0.1 | 1.15.2 | GNU.sparse.size, GNU.sparse.numblocks, GNU.sparse.map, GNU.sparse.name | in one record: a comma-separated list of offset and size |
| 1.0 | 1.15.92 | GNU.sparse.major=1, GNU.sparse.minor=0, GNU.sparse.name, GNU.sparse.realsize | at the start of the member’s data |
In versions 0.1 and 1.0 the member’s own header gets a name in the pattern
%d/GNUSparseFile.%p/%f, the folder, a GNUSparseFile. folder
with the process ID, then the file name, and GNU.sparse.name holds the real
one, so that a program that knows nothing of sparse files extracts the data somewhere
harmless. The version 0.0 records have no GNU.sparse.name.
The records GNU.sparse.size (0.0 and 0.1) and
GNU.sparse.realsize (1.0) give the file’s full size with the holes put
back. GNU.sparse.numblocks counts the stretches in versions 0.0 and 0.1.
In version 0.0 each GNU.sparse.offset fills the next map entry, and the
GNU.sparse.numbytes after it completes that entry and moves on.
In version 1.0 the member’s data starts with the map: numbers, each ended by a line feed, first the number of entries, then the offset and size of each stretch of data, padded with zeros to a whole block. The stored stretches follow. The GNU manual says these numbers are octal, but Go notes that “the GNU tar utility itself outputs these values in decimal”, and the explorer reads them as decimal.
The explorer lists each map’s entries and each stretch of stored data, and can open the rebuilt file, with its holes back, in any of the three versions and in GNU’s header form.
An example from Go’s test archive sparse-formats.tar. The extended
header’s records start with the version:
00003400 32 32 20 47 4E 55 2E 73 70 61 72 73 65 2E 6D 61 22 GNU.sparse.ma
00003410 6A 6F 72 3D 31 0A 32 32 20 47 4E 55 2E 73 70 61 jor=1.22 GNU.spa
22 GNU.sparse.major=1 and a line feed: 2 + 1 + 16 + 1 + 1 + 1 = 22 bytes.and the member’s data starts with the map:
00003800 39 35 0A 31 0A 31 0A 33 0A 95.1.1.3.
GNU tar’s own format stores sparse files differently, in the header; see GNU sparse files.
Vendor keys
Programs add their own keywords, written as VENDOR.keyword with the
vendor’s name in capitals (a convention in star(5); POSIX reserves only the all
lower-case names). A reader skips keywords it does not know.
| Prefix | From | Keys |
|---|---|---|
SCHILY. | star | See the full list on star’s pax page, with its flag names, file types, directory lists and volume keys. |
LIBARCHIVE. | libarchive | creationtime; xattr. followed by a namespace and a URL-encoded attribute name, with a base-64 value; symlinktype, file or dir, saying which a symbolic link points to. |
SUN. | Solaris tar | SUN.devmajor and SUN.devminor, device numbers without the header’s limit; SUN.holesdata, a sparse file’s data and hole offsets in turn, after a leading space. The stored contents hold both the data and the holes, so nothing has to be rebuilt. |
GNU. | GNU tar | See the table below. |
RHT. | GNU tar | RHT.security.selinux: the file’s SELinux security context as text, which GNU tar’s xheader.c keeps out of the raw SCHILY.xattr. keys. |
| GNU keyword | Meaning |
|---|---|
GNU.sparse.… | The sparse file keys. |
GNU.dumpdir | An incremental backup’s list of a folder’s names (see dumpdir). |
GNU.volume.label | The volume label. May appear only in global headers. |
GNU.volume.filename | The name of the file continued on this volume; the same job as a GNUTYPE_MULTIVOL header. |
GNU.volume.size | How much of the file is left, otherwise kept in the size field of a multi-volume header. |
GNU.volume.offset | Where this volume’s part starts in the file, otherwise kept in the GNU header’s offset. |
A multi-volume pax archive writes the parts of a split member under the name pattern
%d/GNUFileParts.%p/%f.%n: the folder, a GNUFileParts. folder
with the process ID, the file name and the part’s number. The first part keeps the
original name. The keywords and pattern above are from GNU tar’s manual and its
xheader.c. The explorer shows a member named this way as a continuation
of the real file, with its part number and, from the GNU.volume. records,
its offset.