How 7-Zip Displays CPIO Archive File Trees

This article explains how the 7-Zip file archiver processes, reconstructs, and displays the internal filesystem trees of CPIO (Copy In, Copy Out) archives. It covers the sequential nature of the CPIO format, the mechanism 7-Zip uses to convert flat relative pathnames into an interactive hierarchical tree, and how file metadata is represented within the 7-Zip interface.

The Sequential Nature of CPIO Archives

Unlike container formats such as ZIP or 7z, which maintain a central directory index at the end or beginning of the file, standard CPIO archives are purely stream-oriented. A CPIO file consists of consecutive blocks containing a header, a filename, and the corresponding file data, terminating with a special marker entry (commonly named TRAILER!!!). Because CPIO lacks a separate hierarchical index, the archive does not store a pre-built directory tree structure.

Reading and Parsing Path Strings

When opening a CPIO archive, 7-Zip scans the file sequentially to parse each header (supporting various formats such as Binary, ODC, New ASCII/SVR4, and CRC).

Each valid entry includes the complete path of the item as a single string (for example, usr/local/bin/sample_app). 7-Zip extracts these path strings along with the associated metadata, such as file sizes, POSIX permissions, modification timestamps, and file types.

Virtual Directory Tree Reconstruction

Because the CPIO format provides only raw path strings, 7-Zip creates an in-memory virtual filesystem tree using the following process:

  1. Path Delimiter Splitting: 7-Zip normalizes the path strings and splits them using forward slashes (/) or backslashes (\).
  2. Implicit Folder Generation: If an archive contains a file entry like etc/network/interfaces without an explicit directory entry for etc or network, 7-Zip automatically synthesizes virtual parent folders.
  3. Node Hierarchy Mapping: 7-Zip populates internal directory nodes with their respective child entries (files, directories, and symlinks), mapping the flat list into a navigable parent-child relationship.

Presentation in the 7-Zip GUI

Once the virtual tree is constructed, 7-Zip displays the CPIO archive within its standard File Manager interface:

  • Folder Navigation: Users can double-click through directories and navigate up and down the hierarchy exactly as they would in an operating system's native file explorer.
  • Metadata Columns: 7-Zip translates the POSIX attributes stored in the CPIO headers into visible columns, including "Attributes," "Modified," and "Size."
  • Special File Types: Symbolic links, hard links, and zero-byte directory entries stored in the archive are identified and assigned appropriate icons and size listings.

Through this parsing and synthesis process, 7-Zip allows users to inspect and extract deeply nested directories from stream-oriented CPIO files without requiring complete extraction to the local disk.