All Macintosh storage devices except floppy disks are partitioned intoone or more volumes. Volumes can contain four kinds of items: files,directories, directory threads and file threads. Each item is describedby a catalog record which is analogous to a Unix inode. Catalog recordsare organized in the on-disk catalog B-Tree. Directory contents arederived from searching the catalog B-Tree. Only a file can occupy spaceoutside of its catalog record.
A Macintosh "file" contains two components,or forks. The resource fork is an indexed file containing codesegments, menu items, dialog boxes, etc. The data fork has the "stream ofbytes" semantics of a Unix file contents. Each fork is comprised of oneor more extents or contiguous runs of blocks. An extent descriptor encodesan extent's starting block and length into a 32bit quantity. The firstextent record (three extent descriptors) of each fork is a part of thefile's catalog record. Any further extent records are kept in theextents overflow B-Tree.
In addition to file and B-Tree extents a volume also contains two bootblocks, a volume information block, and a free space bitmap. There isa remarkable amount of redundancy in the on diskdata structures whichimproves crash recovery. While not strictly a part of the filesystem,it should be noted that several catalog record fields are reservedfor the exclusive use of Finder, a program which handles user accessto the filesystem and automatically maintains associations betweenapplications and data files. Thus, HFS must also maintain this Finderinfo.
Every file and directory on an HFS volume has an identification number,similar to an inode number in the Unix filesystem. However, a file ordirectory is named by its parent's identification number and the fileor directory's file name, which is a 32 character string that cancontain nulls. This combination is the search key to the volume'scatalog B-Tree. The catalog B-Tree differs from a traditional B-Treestructure in that all the nodes at each level of the B-Tree are linkedtogether to form a doubly linked list and all of the records are inthe leaf nodes. These variations permit accessing many items in thesame directory by traversing the leaves using the linked list. Strictlyspeaking, the HFS B-Trees are a variant of B+-Trees although Apple'stechnical documentation calls them B*-Trees.
Each directory, including the root directory, contains its directorythread, which has the empty filename. The directory thread recordcontains the name of the directory and the id of the parent of the directory.Similarly, filethreads contain the name of a file and the id of thedirectory they are in. While every directory must contain a directorythread, file threads are very uncommon. In fact, both are examples ofHFS redundancy - for undamaged trees, threads are not strictly necessary.Both file and directory records contain 32 bytes of information used byFinder. The first three extent descriptors for the catalog B-Tree are keptin the volume information block. If the catalog B-Tree file grows beyondthree extents, the remaining extent descriptors are kept in the extentsoverfow.
HFS and HFS+ (also called Sequoia) filesystems are well documented. Thebest source of tech. information about HFS can be found in theInsideMacintosh series of books. Look athttp://developer.apple.com/techpubs/mac/Files/Files-99.html.The HFS+ filesystem is described inTechnote 1150,available online athttp://developer.apple.com/technotes/tn/tn1150.html.A lot of information is available also in other technotes. This linksare collected by Paul H. Hargrove:
HFS/2 lets OS/2 users seamlessly read and write fileson diskettes formatted with the Hierarchical File System, thefile system used by Macintosh computers. With HFS/2, Macintoshdiskettes can be used just as if they were regular diskettes.
This program is no longer being developed, because author doesn'tuse OS/2. If you are willing to maintain the program, let him know.
The hfsutils package contains a set of command-line utilitiessuch as hformat, hmount, hdir,hcopy, etc. They allow read-write access of files and directorieson HFS volumes.