TAR Archive (.tar)

Unix tape archive container.

Overview

A tar file is a sequence of 512-byte header blocks (name, mode, uid, gid, size, mtime, checksum, type flag, link name, and for ustar a magic ustar plus prefix) each followed by data padded to 512 bytes. The archive ends with two zero blocks. GNU and pax extensions carry long names, large sizes and extended attributes. Tar itself does no compression, so it is usually wrapped in gzip, bzip2, xz or zstd.

Where it is used

  • Software source distribution and Unix backups.
  • Container image layers.

History

  • Introduced in Version 7 Unix (1979); standardized in POSIX.1-1988 (ustar) and POSIX.1-2001 (pax).

Status today

  • Universal on Unix-like systems.

Structures read by the implementation

Offsets are in bytes from the start of the buffer named in each heading. Field names are taken from the implementation and are not an official specification. Fixed-width integers are shown as u/i (unsigned/signed) followed by bit width and byte order.

Header.Parse buffer block · TarFormat.cs

OffsetSizeTypeFieldNotes
0x7C12bytes–
0x8812bytesOdified
0x948bytes–
0x9C1u8Type
0x9D100bytes–
0x1018bytesAgic
0x159155bytesName
0x1591u8–

Other fields read

Read inOffsetSizeTypeFieldNotes
TarStreamScanner.OnHeader0x1E312bytes–

Constants

General TarCarver

NameValueTypeNotes
MetaChunk65536int

General TarFormat

NameValueTypeNotes
BlockSize512int
RecordSize10240intGNU tar / bsdtar / Python default blocking factor 20

General TarArchiveModule

NameValueTypeNotes
Block512int

Implementation limits reader

ClassNameValueNotes
TarStreamScannerMaxEntries100_000
TarStreamScannerMaxMetaData1 << 20
TarSummaryMaxNamesInDetails25
TarArchiveModuleMaxEntries5_000_000

TarFlavor enum

NameValue
Ustar(next)
Pax(next)

Signatures and magic strings referenced

TextWhereContext
ustar \0Header.Parseif (magic.SequenceEqual(“ustar \0″u8))
ustar\0Header.Parseelse if (magic[..6].SequenceEqual(“ustar\0″u8) || magic[..5].SequenceEqual(“ustar”u8))
ustarHeader.Parseelse if (magic[..6].SequenceEqual(“ustar\0″u8) || magic[..5].SequenceEqual(“ustar”u8))
Structures and constants were extracted from: Carving/Plugins/Tar/TarCarver.cs, Carving/Plugins/Tar/TarFormat.cs, Modules/FileSystems/TarArchiveModule.cs. Prose sections are a summary from public sources; verify details before relying on them.