2 . 3
T H E A B S T R A C T I O N S
Figure 2-4 Example directory entries with a name and i-node number.
store user data (simple lists and extents). The basic abstraction of a "file" is
the core of any file system.
Beyond a single file stored as a stream of bytes, a file system must provide a
way to name and organize multiple files. File systems use the term directory
or folder to describe a container that organizes files by name. The primary
purpose of a directory is to manage a list of files and to connect the name in
the directory with the associated file (i.e., i-node).
As we will see, there are several ways to implement a directory, but the
basic concept is the same for each. A directory contains a list of names.
Associated with each name is a handle that refers to the contents of that
name (which may be a file or a directory). Although all file systems differ
on exactly what constitutes a file name, a directory needs to store both the
name and the i-node number of this file.
The name is the key that the directory searches on when looking for a file,
and the i-node number is a reference that allows the file system to access
the contents of the file and other metadata about the file. For example, if
a directory contains three entries named
(i-node 346), then conceptually the contents of the directory can be
thought of as in Figure 2-4.
When a user wishes to open a particular file, the file system must search
the directory to find the requested name. If the name is not present, the file
system can return an error such as
Name not found
. If the file does exist, the
file system uses the i-node number to locate the metadata about the file, load
that information, and then allow access to the contents of the file.
Storing Directory Entries
There are several techniques a directory may use to maintain the list of
names in a directory. The simplest method is to store each name linearly
in an array, as in Figure 2-4. Keeping a directory as an unsorted linear list
is a popular method of storing directory information despite the obvious
Practical File System Design:The Be File System
, Dominic Giampaolo