What About Directories?

Let's look at how directory reads and writes take place in LFS.

Thus far, we’ve simplified our discussion a bit by only considering inodes and data blocks. However, to access a file in a file system (such as /home/remzi/foo, one of our favorite fake file names), some directories must be accessed too.

How does LFS store directory data

Fortunately, the directory structure is basically identical to classic UNIX file systems, in that a directory is just a collection of (name, inode number) mappings. For example, when creating a file on disk, LFS must both write a new inode, some data, as well as the directory data and its inode that refer to this file. Remember that LFS will do so sequentially on the disk (after buffering the updates for some time). Thus, creating a file foo in a directory would lead to the following new structures on disk:

The piece of the inode map contains the information for the location of both the directory file dirdir as well as the newly-created file ff. Thus, when accessing file foo (with inode number kk), you would first look in the inode map (usually cached in memory) to find the location of the inode of directory dirdir (A3A3). You then read the directory inode, which gives you the location of the directory data (A2A2); reading this data block gives you the name-to-inode-number mapping of (foo, kk). You then consult the inode map again to find the location of inode number kk (A1A1), and finally read the desired data block at address A0A0.

Recursive update problem

There is one other serious problem in LFS that the inode map solves, known as the recursive update problem“De-indirection for Flash-based SSDs with Nameless Writes” by Yiying Zhang, Leo Prasath Arulraj, Andrea C. Arpaci-Dusseau, Remzi H. Arpaci-Dusseau. FAST ’13, San Jose, California, February 2013. Our paper on a new way to build flash-based storage devices, to avoid redundant mappings in the file system and FTL. The idea is for the device to pick the physical location of a write, and return the address to the file system, which stores the mapping.. The problem arises in any file system that never updates in place (such as LFS), but rather moves updates to new locations on the disk.

Specifically, whenever an inode is updated, its location on disk changes. If we hadn’t been careful, this would have also entailed an update to the directory that points to this file, which then would have mandated a change to the parent of that directory, and so on, all the way up the file system tree.

LFS cleverly avoids this problem with the inode map. Even though the location of an inode may change, the change is never reflected in the directory itself. Rather, the imap structure is updated while the directory holds the same name-to-inode-number mapping. Thus, through indirection, LFS avoids the recursive update problem.

Get hands-on with 1400+ tech skills courses.