Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


8.2.1 Inodes


How can directory hierarchies be represented by data structures? As already noted, inodes are central
to file implementation, but are also used to implement directories. In other words, directories are just a
special kind of file and must be interpreted correctly.

The elements of an inode can be grouped into two classes:


  1. Metadata to describe the file status; for example, access permissions or date of last change

  2. A data segment (or a pointer to data) in which the actual file contents are held; text in the
    case of a text file


To demonstrate how inodes are used to structure the directory hierarchy of the filesystem, let’s look at
how the kernel goes about finding the inode of/usr/bin/emacs.

Lookup starts at the root inode, which represents the root directory/and must always be known to the
system. The directory is represented by an inode whose data segment does not contain normal data but
only the root directory entries. These entries may stand for files or other directories. Each entry consists
of two elements.


  1. The number of the inode in which the data of the next entry are located

  2. The name of the file or directory


All inodes of the system have a specific number by which they are uniquely identified. The association
between filename and inode is established by this number.

The first step in the lookup operation is to find the inode of the subdirectoryusr. The data field of the
root inode are scanned until an entry namedusris found (if lookup fails, a ‘‘File not found‘‘ error is
returned). The associated inode can be localized by reference to the inode number.

The above step is repeated, but this time a search is made for a data entry with the namebinso that
the inode can be identified by its inode number. The name sought in its data entry isemacs.Again,this
returns the number of an inode — which, in this case, represents a file and not a directory. Figure 8-2
shows the situation at the end of the lookup process (the path taken is indicated by pointers between the
objects).

The file contents of the last inode differ from those of the three previous inodes. Each of the first three
represents a directory and therefore contains a list of its subdirectories and files. The inode associated
with theemacsfile stores the contents of the file in the data segment.

Although the basic idea of a step-by-step file lookup process is the same in the actual implementation of
the VFS, there are a few differences in detail. For example, caches are used to speed the lookup operations
because frequent opening of files is a slow process. In addition, the VFS layer must communicate with
the underlying filesystems that supply the actual information.

8.2.2 Links


Linksare used to establish connections between filesystem objects that do not fit into the classic tree
model. There are two types of link —symbolicandhard.
Free download pdf