Introduction
HFS, the Hierarchical File System, is the file system of the classic Macintosh (System 3 to Mac OS 9): folders inside folders, files with two forks (a data fork and a resource fork), a four-letter file type and creator, and dates counted from 1 January 1904. An HFS volume is a disk of 512-byte blocks: on a 3.5-inch Macintosh floppy 800 KB (1,600 blocks) or 1.44 MB, or a hard disk or its image. The explorer reads one that is a whole-volume image: the 800 KB .po files of Apple II emulators that hold an HFS volume (the Apple II page and ProDOS call a .po a ProDOS-order image, but the HFS volume in it is not ProDOS) and .hfs images. It does not read HFS Plus, the file system that replaced it, nor MFS, the one before it.
This page rests on the structures of Inside Macintosh: Files as the Linux kernel's hfs_common.h reproduces them (read as raw text: samples/po/sources/linux-hfs_common.h), which cites Inside Macintosh: Files for the volume attributes, and on two real volumes. The descriptions are our own words. The Apple PDF itself (File Manager) was fetched but its text could not be read here, so no statement is checked against it directly.
The layout
| Blocks (512 bytes) | What |
|---|---|
| 0 and 1 | Boot blocks: code the Macintosh ROM loads when the volume is a startup disk; the first two bytes are LK on a bootable volume. Not read here. |
| 2 | The Master Directory Block (MDB): the signature BD, dates, the sizes of the volume, the counts, and where the two trees are. |
| 3 (the MDB says) | The volume bitmap: one bit for each allocation block. |
| from the MDB's first allocation block (4 on a floppy) | The allocation blocks: the disk space a file or tree is given, in units of a whole number of 512-byte blocks (512 bytes each on an 800 KB floppy). Every file's forks, the extents tree and the catalog tree are lists of them. |
| second-last | The alternate MDB, a copy kept for repair. |
| last | A reserved block. |
An allocation block is the unit of allocation: block n begins at byte first allocation block × 512 + n × allocation block size. A file's fork is a list of extents, each a start (an allocation block number) and a count. The catalog record holds the first three extents of each fork; a fork in more pieces keeps the rest in the extents tree.
The two B-trees
Both trees are files in the allocation blocks (their extents are in the MDB: the extents tree is file number 3 and the catalog tree number 4) made of 512-byte nodes. Node 0 is a header node (a 14-byte descriptor, the header record, a user record and a map of used nodes), the others are index nodes (type 0) and leaf nodes (type 0xFF), and the leaf nodes of a tree are chained by forward and backward links. Every record is a key and its data. The catalog tree holds every file and folder; the extents tree holds the extents of a fork beyond the first three.
.po: HFS, ProDOS or gettext
A .po file can be a gettext message catalogue (text), a ProDOS volume in ProDOS block order, or an HFS volume. The explorer's .po row lists HFS first with a strict test: whole 512-byte blocks, BD in block 2, and the MDB's sizes (allocation block count and size, first allocation block, bitmap start) fit the image. A text file or a ProDOS volume fails it (a ProDOS volume has its volume directory in block 2, not BD), and goes on to the next entry.
In the explorer
The tree has the boot blocks, the MDB with every field, the volume bitmap, and the allocation blocks cut into runs by what owns them: the catalog tree and the extents tree (each expands into its nodes, each node into its records), every file's data fork and resource fork (a file in several pieces appears in as many nodes), free blocks, and blocks marked in use that nothing owns; then the alternate MDB and the reserved block. The Volume tab gives the name, dates, attributes, space, the trees' depths and a table of every folder and file with its path, type and creator, fork sizes, dates and notes. A file's data fork opens as a file of its own. Problems are listed: the counts in the MDB against the catalogue, the bitmap against what files own, the alternate MDB against the first, a tree that does not read.
What was compared
Two real volumes (800 KB, 512-byte allocation blocks, from CiderPress II's test data, CC BY 4.0; the names suggest the second was made with Linux's HFS driver, which we did not check): hfs-blank-800k.po (no files) and simple-linux.po (9 files, 3 folders, two files of 38 blocks each in 10 extents, which need the extents tree). For both, the counts in the MDB equal the catalogue's, the root folder's count equals its children, the bitmap's used blocks equal the blocks the files and trees own, and every record decodes; the text files read as text. A volume writer in the test, written from the structures with a file of five extents (two in the extents tree) and a resource fork, reads back byte for byte. No other HFS reader was available on this Mac to compare with.
Not described
Known, not yet covered
- Viewer: resource forks are shown as bytes; the resource map and the resources are not read.
- Viewer: the Finder information (the file's Finder flags, icon position, comment; a folder's window rectangle and view) is read only as far as type, creator and the invisible flag; the rest is shown as bytes.
- Viewer: the boot blocks are not disassembled; HFS Plus (a volume with
H+) and MFS are not read, and an HFS volume that embeds an HFS Plus volume (the MDB's embedded signatureH+) is shown as the wrapper only, with a problem saying so. - Viewer: index nodes of the trees are shown as records without their keys decoded; the map records of the header node and the volume's bad-block file are not read; fork extents beyond the first three are followed from the extents tree only when the record chain starts at the right block.
- Viewer: disk images with a header (Disk Copy 4.2
.dc42/.image,.dskwith a header, partitioned hard disk images with an Apple partition map) and 1.44 MB images have not been tried; only a plain volume image whose block 2 is the MDB is read. - Reference: the dates are in local time as the Macintosh kept them; no time zone is stored. The Mac Roman character set is used for names (the table is our own and one character, at 0xDB, is the currency sign of the System 7 era rather than the euro of later systems).
Unknown
- Reference: only two volumes (both 800 KB) were read: a volume with larger allocation blocks, an overflowing catalogue tree of more than two levels, and one made by a real Macintosh, were not seen; the built volume uses 1,024-byte allocation blocks and a two-level catalogue.
Links
Specifications
- Inside Macintosh: Files – File Manager – Apple's description of the volume format (a PDF whose text could not be read here)
- hfs_common.h – the structures in the Linux kernel (GPL-2.0)
Software
- CiderPress II – views and converts disk images, HFS included (Windows, macOS, Linux)
- hfsutils – command-line tools for HFS volumes (Unix)