Nodes
The catalog tree is the file whose first three extents the MDB gives (drCTExtRec, size drCTFlSize). It is cut into nodes of 512 bytes. A node starts with a 14-byte descriptor:
| Offset | Size | Field | What it holds |
|---|---|---|---|
| 0 | 4 | Forward link | The number of the next node at this level (0: none). |
| 4 | 4 | Backward link | The number of the previous node. |
| 8 | 1 | Type | 0 an index node, 1 the header node, 2 a map node, 0xFF a leaf node. |
| 9 | 1 | Height | The level of the node: 1 for the leaves. |
| 10 | 2 | Record count | How many records the node holds. |
| 12 | 2 | Reserved | Zero. |
The records follow the descriptor, and at the end of the node is a table of 16-bit offsets, one for each record and one for the free space, the last record's offset first (offset i is at byte 512 − 2(i + 1)). Node 0 is the header node; its first record is the B-tree header: depth (2), root node (4), number of leaf records (4), first leaf (4), last leaf (4), node size (2, 512), longest key (2), number of nodes (4) and of free nodes (4), then reserved bytes; the second record is a 128-byte user record and the third a 256-byte map of the used nodes. Reading the tree is walking the leaf chain from the first leaf by the forward links; the index nodes above are for finding a key quickly and are not needed to list a volume. The viewer checks that the header's leaf record count equals the records the leaves hold.
Keys and records
Every leaf record is a key and its data. The catalog key is a length byte (the length of the rest of the key), a reserved byte, the parent folder number (4 bytes) and the name (a length byte and up to 31 Mac Roman characters); the data starts on an even offset after it. Keys are sorted by parent number and then by name (case-insensitive), so all the items of a folder are together. The record data starts with a type byte:
| Type | Record | Key |
|---|---|---|
| 1 | Folder record | the parent folder and the folder's own name |
| 2 | File record | the parent folder and the file's name |
| 3 | Folder thread record: the folder's parent number and name, to find a folder's place from its own number | the folder's own number and an empty name |
| 4 | File thread record (the same for a file; the second real volume has one for each of its files) | the file's number and an empty name |
The root folder is number 2 and its parent is number 1; the numbers below 16 are reserved (3 the extents tree, 4 the catalog tree, 5 the bad blocks file), and the first folder or file created gets 16. The viewer builds a file's path by following the parent numbers up to the root.
Folder record (70 bytes): type (1), reserved (1), flags (2), valence (2, how many items it holds), the folder's own number (4), creation, modification and backup dates (4 each), 16 bytes of Finder information (window rectangle, flags, location, view), 16 bytes more Finder information, 16 reserved.
File record (102 bytes):
| Offset | Size | Field | What it holds |
|---|---|---|---|
| 0 | 1 | Type | 2. |
| 2 | 1 | Flags | Bit 0 locked, bit 1 a thread exists, bits 2 and 3 a fork is open, bit 6 copy protected, bit 7 the record is in use. |
| 3 | 1 | Version | Zero. |
| 4 | 4 | File type | A four-letter code (TEXT, APPL). |
| 8 | 4 | Creator | A four-letter code naming the program that made it. |
| 12 | 2 | Finder flags | Bit 14 ($4000) invisible, bit 12 locked, bit 8 initialised; the other bits are not decoded here. |
| 14 | 6 | Location, folder | The icon's position and the window it is in. |
| 20 | 4 | File number | The catalog node number. |
| 24 | 2 | Obsolete | The data fork's first block, no longer used. |
| 26 | 4 | Data fork length | The logical end of the data fork, in bytes. |
| 30 | 4 | Data fork physical length | The space allocated: a whole number of allocation blocks. |
| 34 | 2 | Obsolete | The resource fork's first block. |
| 36 | 4 | Resource fork length | The logical end of the resource fork. |
| 40 | 4 | Resource fork physical length | Allocated space. |
| 44 | 12 | Dates | Creation, modification and backup, 4 bytes each. |
| 56 | 16 | Finder information | Icon id, comment, put-away folder. Not decoded. |
| 72 | 2 | Clump size | How much to add when the file grows. |
| 74 | 12 | Data fork extents | The first three extents (a start and a count, 16 bits each). |
| 86 | 12 | Resource fork extents | The first three extents of the resource fork. |
| 98 | 4 | Reserved | Zero. |
Thread record (46 bytes): type (1), 9 reserved bytes, the parent folder number (4), the name (a length byte and 31 characters).
Checked on the two real volumes (the blank volume has the root folder and its thread, nothing else; the second has nine files, four folders including the root and 13 thread records, one for each file and folder: 26 leaf records in 8 leaf nodes under a two-level tree): the viewer's list agrees with the counts in the MDB and with the valence of every folder, and the fork lengths agree with the extents. The layout is from the Linux driver's structures and our own reading of two volumes; Inside Macintosh could not be read as text here.