Skip to content

Timestamps and Attributes

This document specifies the format of timestamps and file attributes in 7z archives.

Timestamps

FILETIME Format

7z uses Windows FILETIME format for all timestamps:

  • Size: 64 bits (8 bytes)
  • Unit: 100-nanosecond intervals
  • Epoch: January 1, 1601 00:00:00 UTC
  • Byte order: Little-endian

Time Properties

Property IDNameDescription
0x12CTimeCreation time
0x13ATimeLast access time
0x14MTimeLast modification time

Epoch Conversion

FILETIME to Unix timestamp:

UNIX_EPOCH_FILETIME = 116444736000000000  # 1970-01-01 in FILETIME
unix_seconds = (filetime - UNIX_EPOCH_FILETIME) / 10_000_000
unix_nanos = ((filetime - UNIX_EPOCH_FILETIME) % 10_000_000) * 100

Unix timestamp to FILETIME:

filetime = unix_seconds * 10_000_000 + UNIX_EPOCH_FILETIME
filetime += unix_nanos / 100

Value Ranges

DescriptionFILETIME Value
Minimum0 (1601-01-01)
Unix epoch116444736000000000 (1970-01-01)
Year 2000125911584000000000
Year 2038137919572000000000
Maximum2^63 - 1 (year ~30828)

Note: While FILETIME is an unsigned 64-bit integer (full range 0 to 2^64 - 1), 7-Zip and most implementations treat values >= 2^63 as invalid or interpret them as signed negative values. Writers MUST NOT produce values >= 2^63. Readers encountering such values SHOULD treat them as undefined timestamps.

Example Values

# 2024-01-15 12:00:00 UTC
# Unix: 1705320000
# FILETIME: 1705320000 * 10000000 + 116444736000000000
#         = 133497936000000000
#         = 0x01DA47AA5D872000

Bytes: 00 20 87 5D AA 47 DA 01

Missing Timestamps

When a timestamp is not defined:

  • BooleanList indicates absence
  • Implementations SHOULD use a sensible default:
    • Current time for creation
    • File's actual mtime for modification

Unencodable Timestamps

Some timestamps cannot be represented in FILETIME format:

  • Pre-1601 dates: Dates before January 1, 1601 cannot be encoded. Writers SHOULD either use FILETIME value 0 or mark the timestamp as undefined in the BooleanList.
  • Unknown timestamps: When a file's timestamp is unknown or unavailable, mark it as undefined in the BooleanList rather than storing an arbitrary value.

File Attributes

Storage Format

Attributes are stored as UINT32 (4 bytes, little-endian):

┌────────────────────────────────┐
│ Bits 31-16 │    Bits 15-0     │
│ Unix mode  │ Windows attrs    │
└────────────────────────────────┘

Windows Attributes (Bits 0-15)

BitValueConstantDescription
00x0001READONLYRead-only file
10x0002HIDDENHidden file
20x0004SYSTEMSystem file
3-Reserved-
40x0010DIRECTORYDirectory
50x0020ARCHIVEArchive flag
60x0040DEVICEDevice (reserved)
70x0080NORMALNormal file (no other attrs)
80x0100TEMPORARYTemporary file
90x0200SPARSE_FILESparse file
100x0400REPARSE_POINTSymbolic link/junction
110x0800COMPRESSEDNTFS compressed
120x1000OFFLINEOffline storage
130x2000NOT_CONTENT_INDEXEDNot indexed
140x4000ENCRYPTEDEFS encrypted
150x8000UNIX_EXTENSIONUnix mode in high bits

Unix Mode (Bits 16-31)

When bit 15 (UNIX_EXTENSION) is set, bits 16-31 contain the Unix mode:

Bits 16-18: Other permissions (rwx)
Bits 19-21: Group permissions (rwx)
Bits 22-24: Owner permissions (rwx)
Bit 25:     Sticky bit
Bit 26:     Set GID
Bit 27:     Set UID
Bits 28-31: File type

Unix Permission Bits

BitMaskDescription
160x0001 << 16Other execute
170x0002 << 16Other write
180x0004 << 16Other read
190x0008 << 16Group execute
200x0010 << 16Group write
210x0020 << 16Group read
220x0040 << 16Owner execute
230x0080 << 16Owner write
240x0100 << 16Owner read
250x0200 << 16Sticky (S_ISVTX)
260x0400 << 16Set GID (S_ISGID)
270x0800 << 16Set UID (S_ISUID)

Unix File Types (Bits 28-31)

ValueMaskType
0x1S_IFIFOFIFO (named pipe)
0x2S_IFCHRCharacter device
0x4S_IFDIRDirectory
0x6S_IFBLKBlock device
0x8S_IFREGRegular file
0xAS_IFLNKSymbolic link
0xCS_IFSOCKSocket

Attribute Extraction

function parse_attributes(attr: u32):
    windows_attrs = attr & 0xFFFF
    has_unix = (attr & 0x8000) != 0

    if has_unix:
        unix_mode = (attr >> 16) & 0xFFFF
        unix_type = (attr >> 28) & 0x0F
        unix_perms = (attr >> 16) & 0x0FFF
    else:
        unix_mode = None

    return (windows_attrs, unix_mode)

Storage

Symbolic links are stored as:

  1. File with data (target path)
  2. Special attributes indicating symlink type

Attributes: UNIX_EXTENSION | (S_IFLNK << 16) | permissions

Example: 0x8000 | 0xA0000000 | 0x01FF0000 = 0xA1FF8000

Data content: UTF-8 encoded target path (no null terminator)

Windows Reparse Points

Attributes: REPARSE_POINT (0x0400)

Data content: Target path in UTF-8

Target Path Format

  • Relative paths: ../other/file.txt
  • Absolute paths: /usr/local/bin/tool (Unix) or C:\Windows\... (Windows)

Directory Handling

Detection

A directory is identified by:

  • EmptyStream = true AND EmptyFile = false
  • OR DIRECTORY attribute (0x0010) set

Attributes

Directories typically have:

  • Windows: DIRECTORY (0x0010)
  • Unix: S_IFDIR (0x4) in type bits + permissions

Path Format

Directory paths SHOULD end with /:

  • src/ - directory
  • src - could be file or directory (check attributes)

Special Files (Unix)

Device Files

Stored with appropriate type bits:

  • Character device: S_IFCHR (0x2)
  • Block device: S_IFBLK (0x6)

Data content: Major/minor device numbers (implementation-defined)

FIFO and Sockets

Stored with type bits:

  • FIFO: S_IFIFO (0x1)
  • Socket: S_IFSOCK (0xC)

Typically stored as empty files with type attributes.

Cross-Platform Considerations

Windows → Unix

Windows AttributeUnix Handling
READONLYClear write bits
HIDDENPrefix with . (convention)
DIRECTORYSet S_IFDIR
ARCHIVEIgnore

Unix → Windows

Unix FeatureWindows Handling
SymlinkREPARSE_POINT
Execute bitIgnore (use extension)
PermissionsMap to READONLY if no write
Device filesCannot represent

Example Attributes

Regular File (644)

Unix: rw-r--r-- (0644)
Attribute: 0x81A48020
  Windows: 0x0020 (ARCHIVE)
  Unix ext: 0x8000
  Mode: 0x81A4 << 16
    Type: 0x8 (S_IFREG)
    Perms: 0x1A4 (rw-r--r--)

Executable (755)

Unix: rwxr-xr-x (0755)
Attribute: 0x81ED8020
  Windows: 0x0020 (ARCHIVE)
  Unix ext: 0x8000
  Mode: 0x81ED << 16
    Type: 0x8 (S_IFREG)
    Perms: 0x1ED (rwxr-xr-x)

Directory (755)

Unix: drwxr-xr-x
Attribute: 0x41ED8010
  Windows: 0x0010 (DIRECTORY)
  Unix ext: 0x8000
  Mode: 0x41ED << 16
    Type: 0x4 (S_IFDIR)
    Perms: 0x1ED (rwxr-xr-x)
Unix: lrwxrwxrwx
Attribute: 0xA1FF8000
  Windows: 0x0000 (or 0x0400 for reparse)
  Unix ext: 0x8000
  Mode: 0xA1FF << 16
    Type: 0xA (S_IFLNK)
    Perms: 0x1FF (rwxrwxrwx)

See Also

Released under MIT OR Apache-2.0 License