HFS+ (HFS Plus)

HFS+ (Mac OS Extended) was the standard Mac file system from 1998 to macOS 10.12 and remains on older Macs, Time Machine backups and many external drives. It adds Unicode names, journaling (10.2.2) and large volumes, and was replaced by APFS.

Overview

HFS+ keeps a volume header at 1024 bytes (with a backup near the end) and five special files: allocation, extents overflow, catalog, attributes and startup. All are B-trees except the allocation file. Names are UTF-16 (Unicode decomposed form), block numbers are 32-bit, and optional journaling and HFSX case sensitivity exist. Transparent compression (decmpfs) stores data in an extended attribute or the resource fork.

History

  • Introduced in Mac OS 8.1 (1998).
  • Journaling arrived in Mac OS X 10.2.2 and case-sensitive HFSX in 10.3.
  • Replaced by APFS for flash in macOS 10.13 (2017).

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.

Decode Zlib Resource Fork

OffsetSizeTypeFieldNotes
0x04u32 BEData Offset
(int)tableBase4u32 LECount
entry4u32 LEOffset
entry + 44u32 LELength

Try Parse Header

OffsetSizeTypeFieldNotes
0x04u32 LE–
0x44u32 LEEthod
0x88u64 LEUncompressed Size

Collect

OffsetSizeTypeFieldNotes
0x02u16 BEKey End
_idOffset4u32 BEKey Id
dataStart4u32 BEChild

Hfs B Tree

OffsetSizeTypeFieldNotes
0x81u8–
h2u16 BEDepth
h + 24u32 BERoot Node
h + 182u16 BENode Size
h + 202u16 BEMax Key Length
h + 224u32 BETotal Nodes
h + 371u8Key Compare Type
h + 384u32 BEAttributes

Parse

OffsetSizeTypeFieldNotes
0x81u8Kind
0x91u8Height
0xA2u16 BECount
data.Length – 2 * (i + 1)2u16 BEOffset

Build File

OffsetSizeTypeFieldNotes
0x22u16 BEFlags
0x84u32 BEId
0x2C4u32 BELink Reference
0x304u32 BEFile Type
0x344u32 BECreator

Build File Content

OffsetSizeTypeFieldNotes
0x22u16 BEFlags
0x84u32 BEContent Id
0xC4u32 BECreated
0x104u32 BEModified
0x144u32 BEChanged
0x184u32 BEAccessed
0x291u8Owner Flags
0x2A2u16 BEOde
0x304u32 BEFile Type
0x344u32 BECreator

Build Folder

OffsetSizeTypeFieldNotes
0x22u16 BEFlags
0x44u32 BE–
0x84u32 BEId
0xC4u32 BECreated
0x104u32 BEModified
0x144u32 BEChanged
0x184u32 BEAccessed

Common Details

OffsetSizeTypeFieldNotes
0x204u32 BE–
0x244u32 BE–
0x2A2u16 BEOde

Fork Runs

OffsetSizeTypeFieldNotes
0x21u8–
0x84u32 BER

Hfs Plus File System

OffsetSizeTypeFieldNotes
VhAttributes4u32 BEIs Journaled
VhAttributes4u32 BEWas Cleanly Unmounted
VhFreeBlocks4u32 BEFree Bytes
VhFinderInfo + 248u64 BEId

Hfs Plus File System

OffsetSizeTypeFieldNotes
VhBlockSize4u32 BEBlock Size
VhSignature2u16 BEIs Hfsx
VhTotalBlocks4u32 BETotal Blocks

Load Attributes

OffsetSizeTypeFieldNotes
0x04u32 BERecord Type
0xC4u32 BESize

Volume Details

OffsetSizeTypeFieldNotes
VhFileCount4u32 BE–
VhFolderCount4u32 BE–
VhModifyDate4u32 BE–

Is Volume Header

OffsetSizeTypeFieldNotes
VhBlockSize4u32 BEBlock Size
VhSignature2u16 BESignature
VhTotalBlocks4u32 BE–
VhVersion2u16 BEVersion

Locate Embedded Volume

OffsetSizeTypeFieldNotes
MdbAllocationBlockSize4u32 BEBlock Size
MdbEmbedCount2u16 BELength
MdbEmbedSignature2u16 BE–
MdbEmbedStart2u16 BEStart
MdbFirstAllocationBlock2u16 BEStart

Probe

OffsetSizeTypeFieldNotes
0x02u16 BESignature
VhBlockSize4u32 BELength
VhTotalBlocks4u32 BELength

Probe Wrapper

OffsetSizeTypeFieldNotes
MdbAllocationBlockSize4u32 BE–
MdbEmbedSignature2u16 BE–
MdbFirstAllocationBlock2u16 BEWrapper Length
MdbTotalBlocks2u16 BE–

Parse

OffsetSizeTypeFieldNotes
0x08u64 BELogical Size
0xC4u32 BETotal Blocks

Parse Extents

OffsetSizeTypeFieldNotes
offset + i * 8 + 44u32 BE–
offset + i * 84u32 BE–

Other fields read

Read inOffsetSizeTypeFieldNotes
Index Data Start0x02u16 BE–
Next Key Id_idOffset4u32 BEMax Value
Build EntryCatalogKeyIdOffset4u32 BEParent Id
Find By Cnid0x84u32 BE–
Find By Cnid0x44u32 BEParent Id
Find Private0x84u32 BE–
Finder Flags0x382u16 BE–
Fork Runs0x84u32 BE–
Load Attributes0x84u32 BEStart Block
Mount0x02u16 BE–
Uni Stroffset2u16 BECount

Constants

Decmpfs

NameValueTypeNotes
AttributeName“com.apple.decmpfs”string
Magic0x636D7066uint“fpmc” on disk
HeaderSize16int

Hfs B Tree

NameValueTypeNotes
hNodeDescriptorSizeint

Hfs Const

NameValueTypeNotes
VolumeHeaderOffset1024int
VolumeHeaderSize512int
SignatureHfsPlus0x482Bushort“H+”
SignatureHfsx0x4858ushort“HX”
SignatureHfs0x4244ushort“BD” (HFS wrapper / plain HFS)
VersionHfsPlus4ushort
VersionHfsx5ushort

HFSPlusVolumeHeader

NameValueTypeNotes
VhSignature0int
VhVersion2int
VhAttributes4int
VhJournalInfoBlock12int
VhCreateDate16int
VhModifyDate20int
VhFileCount32int
VhFolderCount36int
VhBlockSize40int
VhTotalBlocks44int
VhFreeBlocks48int
VhFinderInfo80int
VhAllocationFile112int
VhExtentsFile192int
VhCatalogFile272int
VhAttributesFile352int
VolumeUnmounted1u << 8uint
VolumeJournaled1u << 13uint

HFS Master Directory Block (wrapper)

NameValueTypeNotes
MdbTotalBlocks18int
MdbAllocationBlockSize20int
MdbFirstAllocationBlock28int
MdbEmbedSignature124int
MdbEmbedStart126int
MdbEmbedCount128int

Special catalog node ids

NameValueTypeNotes
RootParentId1uint
RootFolderId2uint
ExtentsFileId3uint
CatalogFileId4uint
AllocationFileId6uint
AttributesFileId8uint

Catalog record types

NameValueTypeNotes
FolderRecord1short
FileRecord2short
FolderThreadRecord3short
FileThreadRecord4short
FolderRecordSize88int
FileRecordSize248int

Catalog record flags

NameValueTypeNotes
FlagFileLocked0x1ushort
FlagHasAttributes0x4ushort
FlagHasLinkChain0x20ushort

B-tree

NameValueTypeNotes
NodeDescriptorSize14int
IndexNode0sbyte
HeaderNode1sbyte
LeafNode-1sbyte
VariableIndexKeys0x4uint
KeyCompareBinary0xBCbyte

Offsets of the CNID inside each tree’s keys (after the 2-byte key length)

NameValueTypeNotes
CatalogKeyIdOffset2int
ExtentsKeyIdOffset4int
AttributesKeyIdOffset4int
DataFork0x00byte
ResourceFork0xFFbyte
ResourceForkStreamName“rsrc”string

Attribute record types

NameValueTypeNotes
AttrInlineData0x10uint
AttrForkData0x20uint
AttrExtents0x30uint

Finder info / BSD info

NameValueTypeNotes
TypeHardLink0x686C6E6Buint‘hlnk’
CreatorHfsPlus0x6866732Buint‘hfs+’
TypeFolderLink0x66647270uint‘fdrp’
CreatorMacs0x4D414353uint‘MACS’
TypeSymlink0x736C6E6Buint‘slnk’
CreatorRhapsody0x72686170uint‘rhap’
FinderInvisible0x4000ushort
OwnerImmutable0x02byte
OwnerCompressed0x20byte
ModeTypeMask0xF000ushort
ModeDirectory0x4000ushort
ModeSymlink0xA000ushort
PrivateDataFolder“\0\0\0\0HFS+ Private Data”string
PrivateDirectoryFolder“.HFS+ Private Directory Data\r”string

Be

NameValueTypeNotes
HfsEpochnew(1904, 1, 1, 0, 0, 0, TimeSpan.Zero)DateTimeOffset

Hfs Fork

NameValueTypeNotes
Size80int

Implementation limits

ClassNameValueNotes
DecmpfsMaxInMemoryint.MaxValuedecompressed content is buffered in memory
DecmpfsChunkSize64 * 1024
Hfs B TreeMaxDepth16
Hfs B TreeMaxCachedNodes4096
Hfs Plus File SystemMaxAllocationBitmap512L * 1024 * 1024
Hfs Plus File SystemMaxSymlinkLength4096
Structures and constants were extracted from the implementation. Prose sections are a summary from public sources; verify details before relying on them.