Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


link_path_walkis a front end for the__link_path_walkfunction, which works its way through the
directory levels. With approximately 200 lines, this function is one of the longest parts of the kernel.
Figure 8-9 shows its code flow diagram — much simplified because I have ignored minor aspects.

__link_path_walk

Check permissions

Compute hash value of next path component

Handle. and ..

do_lookup

Next entry is a link? do_follow_link
Figure 8-9: Code flow diagram for__link_path_walk.

The function is made up of a large loop to process afilename or pathname component-by-component.
The name is broken down into its individual components (each separated by one or more slashes) inside
the loop. Each component represents a directory name with the exception of the last, which is always a
filename.

Why is the code for__link_path_walkso long? Unfortunately, finding the inode associated with a
given filename is more complicated than it would at first appear and is made more difficult because the
following must be taken into account:

❑ One file can reference another by means of a symbolic link, and the lookup code must cater for
this possibility by being able to recognize and break cyclic link loops.
❑ Mount points must be detected, and the lookup operation must be redirected accordingly.
❑ The access rights of all directories on the path to the target filename must be checked. The pro-
cess must have the appropriate rights, or the operation is aborted with an error message.
❑ Strangely formulated but correct names such as/./usr/bin/../local/././bin//emacs^20 must
be resolved correctly.

Let us take a look at the actions performed in each loop pass until the specified file or directory name
has been fully processed and the matching inode has been found. Themntanddentryvalues of the
nameidatainstance are filled with the values of either the root directory or the working directory and are
the starting point for further actions in which the following steps are carried out:

❑ Checking if the current process is granted permission to enter the directory depends on whether
the inode under inspection defines thepermissionmethod in itsinode_operations.Ifthisisnot
the case,exec_liteis used to make the decision. Depending on the credentials of the process,
the function selects the proper parts of the file’s mode mask and checks if theMAY_EXECbit is set
(certain capabilities are also taken into account, but I omit this here for simplicity).

(^20) This could have been written as/usr/local/bin/emacs.

Free download pdf