Introduction
A Macintosh file can carry more than its contents: a resource fork, the Finder’s type and creator codes and flags, a comment, and on macOS extended attributes such as the quarantine flag set on downloads. Most other file systems have nowhere to keep them. AppleDouble and AppleSingle are Apple’s two ways of carrying them anyway, and Apple published both in a developer note, AppleSingle/AppleDouble Formats for Foreign Files. Version 2 is the one in use.
- AppleDouble splits a file in two: the contents stay in an ordinary
file, and everything else goes into a “header file” beside it. When macOS copies a file
to a FAT or exFAT drive or to a network share that cannot store these parts, it writes
that header file under the same name with
._in front:photo.jpggets._photo.jpg. The Finder’s Compress command does the same inside ZIP files, in a__MACOSXfolder, and macOS’starwrites them as members just before each file. - AppleSingle keeps the contents and the rest together in one file.
On a Mac, dot_clean merges ._ files back into the files they
belong to. Other systems show them as small extra files, usually 4,096 bytes, that can
be deleted if the Mac information is not needed. RFC 1740 uses both formats to send Mac
files by email, as application/applefile.
Structure
Both formats have the same layout: a 26-byte header, a table of entries, then the entries themselves, in any order. Numbers are big-endian. Only the magic number tells them apart.
0Magic number00 05 16 07AppleDouble,00 05 16 00AppleSingle4 bytes4Version00 02 00 00for version 24 bytes8Filler zeros; macOS writes “Mac OS X” and spaces16 bytes24Number of entries2 bytes26Entry descriptors ID, offset and length of each entry12 bytes each…Entries wherever the descriptors sayvaries
In version 1 the filler named the file system the file came from, such as
Macintosh or ProDOS, padded with spaces, and entry 7 held the
file information in that system’s own layout.
Entries
Each descriptor gives an entry’s ID, its offset from the start of the file and its length. The IDs the developer note defines are:
| ID | Entry | What it holds |
|---|---|---|
| 1 | Data fork | The file’s contents (AppleSingle only) |
| 2 | Resource fork | The resource fork, in the Resource Manager’s layout |
| 3 | Real name | The file’s name on the Mac |
| 4 | Comment | The Finder comment |
| 5 | Black-and-white icon | A 32 × 32 icon |
| 6 | Colour icon | A colour icon |
| 8 | File dates | Created, modified, backed up and accessed, in seconds from 1 January 2000 UTC |
| 9 | Finder info | The Finder’s 32 bytes |
| 10 | Macintosh file info | The locked and protected bits |
| 11 | ProDOS file info | Access, file type and auxiliary type |
| 12 | MS-DOS file info | The MS-DOS attributes |
| 13 | Short name | The name an AFP server gave the file |
| 14 | AFP file info | The AFP attributes |
| 15 | Directory ID | The AFP ID of the file’s folder |
A ._ file from macOS has just two entries: Finder info (9) and the
resource fork (2), which is 286 bytes for a file that has no resources of its own.
Finder info
The first 16 bytes are the file type and creator (four characters each, such as
TEXT and ttxt), the Finder flags (invisible, custom icon, alias,
the colour label), the icon’s position in its window and its folder. The next 16 hold the
icon ID, the script of the name, more flags, the comment ID and the folder the file is put
back in.
Extended attributes
macOS makes the Finder info entry longer than 32 bytes and keeps the file’s extended
attributes in it, after two bytes of padding. An attribute header starts with
ATTR and gives the total size, where the values are and how many attributes
there are. One entry per attribute follows (the value’s offset and length, flags, and the
name in UTF-8 with its length), padded to a multiple of 4 bytes, then the values. The
rest of the entry is zeros, left free so attributes can be added. Common ones are
com.apple.quarantine, the download’s app and time, and Spotlight’s
com.apple.metadata: attributes, such as the address a file was downloaded
from, which are binary property lists.
Resource fork
The resource fork has a 16-byte header giving the offsets and lengths of the resource
data and the resource map, usually followed by 240 reserved bytes. Each resource’s data is
a 4-byte length and the bytes. The map lists the types, such as icns for a
custom icon, then for each resource its ID, name, attributes and where its data is, and
ends with the names.
Links
Software
- Finder – writes
._files on drives and shares, and in the__MACOSXfolder of ZIP files it makes (macOS) dot_clean– merges._files back into the files beside them (macOS)- Netatalk – AFP file server that stores Mac metadata as AppleDouble (Linux, BSD)
Reference
- RFC 1740 – MIME encapsulation of Macintosh files, which describes both formats
- vfs_xattr.c – the macOS kernel’s code that reads and writes
._files with their extended attributes