How 7-Zip Stores File Timestamps and Attributes

This article explains how the 7-Zip archiving tool and its native 7z format record, structure, and preserve file metadata. It covers the specific data structures used for Creation, Modification, and Access timestamps, the precision of these records, and the mechanism used to store standard Windows and POSIX file attributes within the archive headers.

The 7z Header Architecture

The native 7z format organizes metadata using a modular, property-based header stream rather than attaching metadata individually to each file stream. File properties—such as timestamps, sizes, CRC checksums, and attributes—are grouped into dedicated arrays.

To conserve space, 7-Zip typically compresses the entire header block using LZMA or LZMA2. Within this compressed header, metadata types are identified by predefined Property IDs (such as kCTime for Creation Time, kMTime for Modification Time, and kATime for Last Access Time).

Timestamp Format and Precision

Unlike legacy ZIP archives that rely on MS-DOS timestamp formats limited to two-second precision, the 7z format uses high-precision tracking:

  • Format: Timestamps are stored as 64-bit unsigned integers corresponding to the Windows FILETIME structure.
  • Epoch: The values measure the number of 100-nanosecond intervals elapsed since January 1, 1601, in Coordinated Universal Time (UTC).
  • Resolution: 7-Zip natively preserves time down to 100 nanoseconds, matching the native precision of the NTFS file system.
  • Time Zones: Because timestamps are converted to and stored in UTC, they remain immune to daylight saving changes and local time zone shifts across different systems.

Handling Defined and Undefined Timestamps

Not every file within an archive necessarily possesses all three timestamps. 7-Zip handles this using boolean flags and bit vectors:

  1. AllAreDefined Flag: A single byte indicates whether every file in the folder or archive has a valid timestamp for that specific property.
  2. Bitmaps: If some files lack a timestamp (for example, if Last Access tracking is disabled on the host system), 7-Zip includes a bitmask where each bit specifies whether the corresponding file includes the timestamp.
  3. Data Array: Following the definition flags, the 64-bit integer values are stored sequentially only for the files marked as valid.

Storage of File Attributes

File attributes are separated from timestamps and stored under specific attribute property blocks:

  • Windows Attributes (kWinAttrib): 7-Zip records Windows file flags (such as Read-Only, Hidden, System, Archive, and Directory) as 32-bit unsigned integers (DWORD). These match the standard GetFileAttributes definitions from the Windows API.
  • Presence Mapping: Similar to timestamps, a boolean flag or bitmask specifies which entries carry attribute data, followed by an array of 32-bit values.
  • POSIX and Unix Permissions: In cross-platform implementations or specialized builds (like p7zip), Unix-style permissions (read, write, execute permissions and file type bits) are mapped into higher-order bits or handled through custom properties to ensure cross-platform compatibility without corrupting Windows attribute parsing.