Every member of a star archive starts with a header of exactly 512 bytes. This page is
the xstar header of star(5), struct xstar_header, which GNU tar’s
tar.h gives in the same form as star_header. The xustar and
exustar forms use the same layout without the signature at byte 508. Sparse files have a
header of their own, described at the end of this page.
Fields
Offsets and sizes are in bytes, in decimal. The field names are star(5)’s; bytes 0 to 344 hold the same fields as a ustar header.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
0 | 100 | text | t_name | The member’s name, or the last part of its path when t_prefix holds the rest. |
100 | 8 | octal | t_mode | Permission bits: 4000 setuid, 2000 setgid, 1000 reserved, then read, write and execute for owner, group and others. See mode bits. |
108 | 8 | octal or base-256 | t_uid | The owner’s numeric user ID. |
116 | 8 | octal or base-256 | t_gid | The owner’s numeric group ID. |
124 | 12 | octal or base-256 | t_size | The number of bytes of data after the header. |
136 | 12 | octal or base-256 | t_mtime | The modification time, in seconds since 1 January 1970 UTC. |
148 | 8 | octal | t_chksum | The header’s checksum. |
156 | 1 | character | t_typeflag | What the member is: see type flags. |
157 | 100 | text | t_linkname | The target of a hard or symbolic link. |
257 | 6 | characters | t_magic | ustar and a NUL, as in POSIX. See magic and signature. |
263 | 2 | characters | t_version | 00. |
265 | 32 | text | t_uname | The owner’s user name. |
297 | 32 | text | t_gname | The owner’s group name. |
329 | 8 | octal or base-256 | t_devmajor | The major device number, for character and block devices. |
337 | 8 | octal or base-256 | t_devminor | The minor device number. |
345 | 131 | text | t_prefix | The folder part of a long path, at most 130 characters. See names and the prefix. |
476 | 12 | octal | t_atime | The access time. See star’s fields. |
488 | 12 | octal | t_ctime | The status change time. |
500 | 8 | filler | t_mfill | Zeros. |
508 | 4 | characters | t_xmagic | tar and a NUL in xstar; zeros in xustar and exustar. |
Names and the prefix
Text fields are padded with NUL bytes, and a value that fills its field has no NUL.
A path longer than 100 characters is split at a /: the part before goes in
t_prefix, the part after in t_name. When the prefix is not
empty the path is the prefix, a slash, then the name.
The prefix field is 131 bytes, where ustar’s is 155, and star keeps the prefix to at
most 130 characters, so byte 475 always stays NUL. star(5) says this is so that ustar
implementations do not fail: a ustar reader stops the prefix at that NUL and gets the
right path, without reading the times after it. A path that will not fit the name and
the prefix goes in a path record in a
pax header.
Writers end a folder’s name with /. The explorer shows names as UTF-8 when
they are valid UTF-8, and as Latin-1 when not.
Numbers
Numbers are octal digits as ASCII text, with leading zeros, ended by a space or a NUL. With 7 digits, 8-byte fields reach 2,097,151; with 11 digits, 12-byte fields reach 8,589,934,591, 8 GiB less one byte (star(5) gives the same limits).
Larger values are written in base-256, which star(5) allows for
t_uid, t_gid, t_size, t_mtime,
t_devmajor and t_devminor; it does not allow it for
t_mode, which holds only 12 bits. star(5): the first byte is 128 (80) for a positive number and 255
(FF) for a negative one, and the rest of the field is the number in
big-endian two’s complement, 56 bits in an 8-byte field and 88 bits in a 12-byte one.
Readers take bit 7 of the first byte as the mark and bit 6 as the sign. For example, a
size of 600 is 80 00 00 00 00 00 00 00 00 00 02 58.
The explorer reads octal numbers as GNU tar does: one leading NUL and any spaces skipped, octal digits, then a space or a NUL. That description of GNU tar is from memory of its source and is not confirmed.
Mode bits
The 12 bits of t_mode, with the names tar.h and POSIX’s
<sys/stat.h> give them. POSIX calls 01000 reserved; tar.h
names it TSVTX and it is the sticky bit on many systems.
| Bit | tar.h | POSIX | Meaning |
|---|---|---|---|
04000 | TSUID | S_ISUID | Set user ID on execution |
02000 | TSGID | S_ISGID | Set group ID on execution |
01000 | TSVTX | reserved | Reserved; the sticky bit on many systems |
00400, 00200, 00100 | TUREAD, TUWRITE, TUEXEC | S_IRUSR, S_IWUSR, S_IXUSR | Owner: read, write, execute |
00040, 00020, 00010 | TGREAD, TGWRITE, TGEXEC | S_IRGRP, S_IWGRP, S_IXGRP | Group: read, write, execute |
00004, 00002, 00001 | TOREAD, TOWRITE, TOEXEC | S_IROTH, S_IWOTH, S_IXOTH | Others: read, write, execute |
Some old writers leave the file-type bits of st_mode above these, such as
0100644; the explorer shows them with their meaning.
Checksum
As in ustar, the checksum is the sum of all 512 bytes of the header, each read as an
unsigned number, with the eight bytes of t_chksum counted as spaces.
- Take the 512 bytes. Replace bytes 148 to 155 with eight spaces (
20), which add 256. - Add up the bytes as unsigned numbers, 0 to 255. Readers such as Go and libarchive also accept the sum of the bytes read as signed numbers, which old writers used.
- Read the stored field as octal. The header is valid if it equals the sum.
- A block of zeros is not a header; readers test for it before checking the sum.
In Go’s star test archive the field is seven digits and a space,
30 30 31 36 37 33 30 20: 0016730, which is 7,640. GNU tar and
libarchive write six digits, a NUL and a space instead; a reader should accept
both.
Magic and signature
A star header has the POSIX magic and version at 257 to 264,
75 73 74 61 72 00 30 30, so the magic alone does not tell it from ustar.
The three forms of the header:
| Form | Bytes 508 to 511 | What star(5) says |
|---|---|---|
| xstar | 74 61 72 00, tar and a NUL | The header “defined in 1994”. |
| xustar | zeros | “‘xstar’ format without "tar" signature at header offset 508”. |
| exustar | zeros | “‘xustar’ format variant that always includes x-headers and g-headers”. |
star(5) says setting t_xmagic to tar “should be avoided in
the future”, and that t_mfill and t_xmagic “need to be zero for
a 100% ustar compliant implementation”.
Without the signature, a reader tells a star header by its times. star’s own test
(isxmagic in its header.c), which the explorer follows: byte
475 is NUL, and t_atime and t_ctime are each 11 octal digits
then a space or NUL, or are in base-256. star(5) as published online gives a similar
test but says byte 475 should be a space; star’s source and Go’s star test archive
have a NUL there.
star’s fields
Bytes 476 to 511, which ustar reads as the end of the prefix and unused bytes:
| Offset | Size | Name | Meaning |
|---|---|---|---|
476 | 12 | t_atime | The last access time, in octal, ending in a space. |
488 | 12 | t_ctime | The last status change time, in the same form. |
500 | 8 | t_mfill | Filler, zeros. |
508 | 4 | t_xmagic | “tar” in xstar; Go’s trailerSTAR is "tar\x00", so in practice a NUL follows. |
The end of the header of small.txt, a 5-byte file in Go’s test archive
star.tar. Rows shown as … are left out. The marked bytes are
the two times and the signature.
00000100 00 75 73 74 61 72 00 30 30 64 73 79 6D 6F 6E 64 .ustar.00dsymond
…
000001D0 00 00 00 00 00 00 00 00 00 00 00 00 31 31 32 31 ............1121
000001E0 33 35 37 35 32 31 37 20 31 31 32 31 33 35 37 35 3575217 11213575
000001F0 32 31 37 20 00 00 00 00 00 00 00 00 74 61 72 00 217 ........tar.
0x1DC, ctime at 0x1E8, filler, and tar\0 at 0x1FC.Both times are 11213575217 and a space: octal 11213575217 is
1,244,592,783 seconds, which is 10 June 2009, 00:13:03 UTC. Byte 475
(0x1DB), the prefix’s last, is NUL, as the time test expects.
The sparse header
For a sparse file, type S, star’s header has yet another layout. It is
not in star(5); the table below is xstar_in_header in star’s own
star.h, the same as star_in_header in GNU tar’s
tar.h, which the explorer decodes. It has not been checked against a
sparse file written by star.
Current star does not put map entries in this header. Its source
(hole.c and props.c) keeps entries in the header only for
GNU tar’s format; in all of star’s own formats the header holds no entries and no
isextended flag, only t_realsize at 452 (and
t_offset at 464 for a continuation), and the whole map is in extension
blocks after it, at least one. The prefix may then run from 345 up to 452. star tells
the old form, with four entries in the header, by an empty first prefix byte and a
filled-in first entry offset (byte 366), and warns “Archive uses old sparse format”.
The explorer makes the same test and reads both forms.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
0 | 345 | – | fill | The ordinary header fields, name to devminor. |
345 | 1 | text | prefix | The prefix, cut to one byte. |
346 | 1 | filler | fill2 | Filler. |
347 | 8 | filler | fill3 | Filler. |
355 | 1 | flag | isextended | Non-zero when extension blocks follow the header. |
356 | 96 | 4 × 24 bytes | sp | Four sparse map entries, each a 12-byte octal offset and a 12-byte octal length. |
452 | 12 | octal | realsize | The file’s full size, holes included. |
464 | 12 | octal | offset | For a multi-volume continuation, where this part starts in the whole file. |
476 | 12 | octal | atime | The access time, as in the ordinary header. |
488 | 12 | octal | ctime | The status change time. |
500 | 8 | filler | mfill | Zeros. |
508 | 4 | characters | xmagic | tar and a NUL. |
When isextended is set, or always in the current form, extension blocks
follow the header, before the data (star_ext_header in
tar.h, xstar_ext_header in star.h):
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
0 | 504 | 21 × 24 bytes | sp | 21 more map entries. |
504 | 1 | flag | isextended | Non-zero when another extension block follows. |
505 | 7 | padding | – | Zeros. |
Go’s reader notes that “the STAR format also has a sparse header format that uses the
same type flag but has a completely different layout” from GNU tar’s
sparse header. star(5) says that in
star’s formats t_size holds “the sum of the sparse hole descriptors plus
the size of the compacted file data”: unlike GNU tar’s, it counts the extension blocks,
so a reader skipping the member lands on the next header. The explorer takes the
data as what remains of t_size after the extension blocks, and can open
the rebuilt file with the holes put back. star(5) also says the real size and the
offset are now kept in the pax records SCHILY.realsize and
SCHILY.offset; see
pax extensions.
The multi-volume offset
A continuation, type M, starts a volume with the rest of a file. star’s
header.c writes where that part starts in the file into
xstar_in_dbuf.t_offset, 12 bytes of octal or base-256 at byte 464, unless
an extended header carries it. Bytes 345 to 463 then hold whatever prefix fits before
it, so the offset’s last character, a space, takes byte 475; this is the check star
makes (isxmagic), and the explorer reads the header in this layout when
that byte is a space or the field is in base-256, and as an ordinary header
otherwise.
The 1985 header
Before POSIX.1-1988, star used a header of its own, which star calls the “old star
format from 1985”. It is struct star_header in star’s
star.h. It has no ustar magic; it is recognised by the
signature tar and a NUL at byte 508, and a version character at byte 257.
The first 257 bytes are the historic tar fields, as in the table above.
| Offset | Size | Name | Description |
|---|---|---|---|
257 | 1 | t_vers | The star header version, a character: 1. A value below 1 means an older tar, which star reads as a plain tar header. |
258 | 8 | t_filetype | star’s coarse file type, in octal: 0 anything not listed (F_SPEC), 1 a regular file (F_FILE), 2 a symbolic link (F_SLINK), 3 a directory (F_DIR). |
266 | 12 | t_type | The file type bits of st_mode, in octal: 010000 a FIFO, 020000 a character device, 040000 a directory, 060000 a block device, 0100000 a regular file, 0120000 a symbolic link, 0140000 a socket. |
278 | 11 | t_rdev | The device numbers of a special file, major and minor together, in octal, or base-256 for large values. |
289 | 1 | t_devminorbits | A character: @ plus the number of bits of t_rdev that hold the minor number; @ alone when star used the local system’s split. star reads a value below @ as 8 bits. |
290 | 12 | t_atime | The access time, in octal or base-256. |
302 | 12 | t_ctime | The status change time, in the same form. |
314 | 16 | t_uname | The owner’s user name. |
330 | 15 | t_gname | The owner’s group name. |
345 | 155 | t_prefix | The folder part of a long path. |
500 | 8 | t_mfill | Filler. |
508 | 4 | t_magic | tar and a NUL. |
Sparse files (S) and continuations (M) keep their extra
fields in the same places as in the sparse header above, overlying the prefix, and a
sparse file’s map is in extension blocks in the current form; the explorer shows
those layouts when it finds them. Its type flag is
t_linkflag at byte 156, as in every other tar header.