The Resource Manager layout
The resource fork of a Macintosh file is a small database: the resources’ data, then a map that says what they are. All numbers are big-endian.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | Data offset | From the start of the fork to the resource data |
| 4 | 4 | Map offset | From the start of the fork to the resource map |
| 8 | 4 | Data length | Bytes of resource data |
| 12 | 4 | Map length | Bytes of resource map |
| 16 | … | Reserved | Zeros to the data offset; Core Audio’s files have the data at 0x100 |
Each resource’s data is a 4-byte length and then the data. The map starts with a copy of the 16-byte header, then:
| Offset in map | Size | Field | Meaning |
|---|---|---|---|
| 16 | 4 | Next map handle | Used in memory only |
| 20 | 2 | File reference number | Used in memory only |
| 22 | 2 | Fork attributes | |
| 24 | 2 | Type list offset | From the start of the map |
| 26 | 2 | Name list offset | From the start of the map |
| 28 | 2 | Number of types less one | Start of the type list |
The type list has an 8-byte item per type: the four-letter type, the number of resources less one and the offset of the reference list from the start of the type list. A reference list has a 12-byte item per resource: the ID (2 bytes), the offset of its name in the name list or FFFF (2), the attributes (1), the offset of its data from the start of the data (3) and a handle used in memory (4). The name list holds Pascal strings.
The explorer shows every one of these fields in the structure tree, with the resource data placed where the references say, and lists any resource that does not fit in the fork as a problem.
The three STR resources
An STR resource is a Pascal string: a length byte, then that many characters. Sound Designer II uses three, found by ID:
| ID | Name | Holds | Example |
|---|---|---|---|
| 1000 | sample-size | Bytes in one sample, an integer string | 2 |
| 1001 | sample-rate | Samples a second a channel, a floating-point string | 44100.0000 |
| 1002 | channels | Number of channels, an integer string | 2 |
The number of frames is not stored; it is the length of the data fork divided by the channels times the sample size.
A file written by Core Audio has a 390-byte resource fork: the header with the data at 0x100 and the map at 0x11B, a 27-byte data area with the strings in the order rate, size, channels, and a 107-byte map with one type, STR , with IDs 1001, 1000 and 1002 and the names sample-rate, sample-size and channels. libsndfile writes the strings in the order 1000, 1001, 1002 with a rate of the form 44100.000000, and a fourth resource of its own. A reader should find a string by its ID.
Sources
- Apple, More Macintosh Toolbox, “Resource File Format” (Figures 1-11 to 1-18).
- Digidesign, Digidesign Developer Documentation 4.0, pages 33 to 36.
- libsndfile,
src/sd2.c. - Files written by
afconvert -f Sd2fon macOS, read byte by byte.