12.1. Analysis ToolsLet us first look at some tools and sources of information that will be useful in understanding the implementation and operation of HFS+. 12.1.1. HFSDebugWe will use hfsdebug, a command-line file system debugger, as a companion program to this chapter.[5] The term debugger is somewhat of a misnomer because a key feature (rather, a limitation) of hfsdebug is that it always operates on an HFS+ volume in read-only mode. It also does not allow for interactive debugging. Nevertheless, it is meant as a useful tool for exploring HFS+ internals, since it allows you to browse, inspect, and analyze various aspects of the file system. It has the following primary features.
hfsdebug supports only the HFS+ volume formatthe older HFS format is not supported. However, it does handle HFS+ variants such as journaled HFS+, embedded HFS+, and case-sensitive HFS+ (HFSX). Since much of the raw information displayed by hfsdebug is not available through a standard programming interface, hfsdebug works by directly accessing the character device associated with a volume. This means several things.
Finally, hfsdebug can also display the contents of the in-memory HFS+-specific mount structure corresponding to a mounted HFS+ volume. This data resides in the kernel as an hfsmount structure [bsd/hfs/hfs.h], a pointer to which is held in the mnt_data field of the mount structure [bsd/sys/mount_internal.h] corresponding to that mount instance. hfsdebug uses the Mach VM interface to retrieve this data. We are interested in the hfsmount structure because some of its relevant constituents have no on-disk counterparts. 12.1.2. Interface for Retrieving File System AttributesHFS+ supports the getattrlist() system call, which allows retrieval of several types of file system attributes. The complementary system call, setattrlist(), allows those attributes that are modifiable to be set programmatically. Note that these two system calls are standard vnode operations in the Mac OS X VFS layerApple-provided file systems typically implement these operations. The attributes accessible through these calls are divided into the following attribute groups:
Besides attributes, getattrlist() can also be used to retrieve volume capabilities, which specify what features and interfaces (from among a predefined list of features and another list of interfaces) a given volume supports. We will see an example of using getattrlist() in Section 12.11. 12.1.3. Mac OS X Command-Line ToolsIn Chapter 11, we came across several file-system-related command-line tools available on Mac OS X. In particular, we used the hdiutil program to manipulate disk images. Besides its typical use, hdiutil can print information about the given HFS+ or HFS volume when used with the hfsanalyze option. $ sudo hdiutil hfsanalyze /dev/rdisk0s3 0x00000000131173B6 (319910838) sectors total 0x131173B0 (319910832) partition blocks native block size: 0200 HFS Plus ... 12.1.4. HFS+ Source and Technical Note TN1150To make the most out of the discussion in this chapter, it would be valuable to have access to the Mac OS X kernel source. The following parts of the kernel source tree are particularly relevant to this chapter:
It is also recommended that you have a copy of Apple's Technical Note TN1150 ("HFS Plus Volume Format"), since it contains information that we refer to (but don't always cover) in this chapter. |