HFS (Hierarchical File System)

HFS is the original Macintosh hard-disk file system from 1985 (Mac OS 8.1 replaced it with HFS+ in 1998). It still appears on classic Mac floppies, hard disks, CD-ROMs and old backups.

Overview

HFS stores a Master Directory Block at 1024 bytes, a volume bitmap, and two B*-trees: the catalog file (folders and files by parent ID and name) and the extents overflow file. Data and resource forks are separate, each with three extents recorded in the catalog. All values are big-endian and names are MacRoman up to 31 characters.

History

  • Introduced by Apple in 1985, replacing MFS.
  • Superseded by HFS+ in Mac OS 8.1 (1998).

Structures

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

Collect

OffsetSizeTypeFieldNotes
0x01u8–
IdOffset4u32 BE–

Collect

OffsetSizeTypeFieldNotes
0x01u8–
0x01u8Data Start
IdOffset4u32 BEKey Id
dataStart4u32 BEChild

Hfs Classic B Tree

OffsetSizeTypeFieldNotes
0x81u8–
0x104u32 BERoot Node
0x202u16 BENode Size
0x244u32 BETotal Nodes

Build File

OffsetSizeTypeFieldNotes
0x21u8–
0x44u32 BEType
0x84u32 BECreator
0xC2u16 BE–
0x144u32 BEId
0x1A4u32 BEData Length
0x1E4u32 BEAllocated Size
0x244u32 BEResource Length
0x2C4u32 BECreated
0x304u32 BEModified

Build Folder

OffsetSizeTypeFieldNotes
0x42u16 BE–
0x64u32 BEId
0xA4u32 BECreated
0xE4u32 BEModified
0x1E2u16 BEFlags

Find Root

OffsetSizeTypeFieldNotes
0x01u8–
0x64u32 BE–

Fork Runs

OffsetSizeTypeFieldNotes
0x11u8–
0x62u16 BER

Try Parse

OffsetSizeTypeFieldNotes
0x02u16 BE–
0x24u32 BECreated
0x64u32 BEModified
0xA2u16 BEAttributes
0xE2u16 BEBitmap Start Sector
0x122u16 BEBlocks
0x144u32 BEBlock Size
0x1C2u16 BEFirst Allocation Sector
0x222u16 BEFree Blocks
0x241u8Name Length
0x544u32 BEFile Count
0x584u32 BEFolder Count
0x7C2u16 BEEmbedded Signature
0x824u32 BEExtents File Size
0x924u32 BECatalog File Size

Parse Record

OffsetSizeTypeFieldNotes
offset + i * 4 + 22u16 BE–
offset + i * 42u16 BE–

Other fields read

Read inOffsetSizeTypeFieldNotes
Fork Runs0x62u16 BE–

Constants

Hfs Master Directory Block

NameValueTypeNotes
Signature0x4244ushort“BD”

Hfs Classic Text

NameValueTypeNotes
Epochnew(1904, 1, 1, 0, 0, 0, TimeSpan.Zero)DateTimeOffset
MacRomanEncodingLoadMacRoman()Encoding

Hfs Classic B Tree

NameValueTypeNotes
IdOffset2int

Hfs Classic File System

NameValueTypeNotes
RootFolderId2uint
ExtentsFileId3uint
CatalogFileId4uint
DirectoryRecord1byte
FileRecord2byte
DirectoryThread3byte
DataFork0x00byte
ResourceFork0xFFbyte
FinderInvisible0x4000ushort

Implementation limits

ClassNameValueNotes
Hfs Classic B TreeMaxDepth16
Structures and constants were extracted from the implementation. Prose sections are a summary from public sources; verify details before relying on them.