Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


If the inode defines a specificpermissionmethod, thenexec_permission_lighttells this
to the callee by returning_EAGAIN.Inthiscase,vfs_permissionis used to decide whether
the process has the rights needed to switch to the specified directory.vfs_permissionjust
calls thepermissionfunction, and this, in turn, invokes thepermissionmethod stored
in theinode_operationsstructure. Section 8.5.3 discusses permission-checking in further
detail.
❑ The name is scanned character-by-character until the kernel arrives at one (or more) slashes
(/). These are skipped because only the name itself is of interest. If, for example, the name of
the file is/home/wolfgang/test.txt, only thehome,wolfgang,andtest.txtcomponents are
relevant — the slashes simply separate the components from each other. One name component
is processed in each loop pass.
Each character of a component is used by thepartial_name_hashfunction to calculate an incre-
mental hash sum. This sum is translated into the final hash value when all characters of a path
component are known and is then stored in aqstrinstance.
❑ Adot(.) as a path component indicates the current directory and is very easy to process. The
kernel simply skips to the next cycle of the lookup loop because the position in the directory
hierarchy has not changed.
❑ Dot dot (..) is a little more difficult to handle, so this task is delegated to thefollow_dotdot
function. When the lookup operation is in the root directory of the process, it has no effect
because there is no parent directory to which it could switch.
Otherwise, two options are available. If the current directory isnotthe root directory of a mount
point, thed_parententry of the currentdentryobject can be used as a new directory because it
always represents the parent directory. If, however, the current directory is the root directory of
a mounted filesystem, the information held inmnt_mountpointandmnt_parentis used to define
the newdentryandvfsmountobject.follow_mountandlookup_mntare used to retrieve the
required information.
❑ If the directory component is a normal file, the kernel can find the correspondingdentryinstance
(and therefore the corresponding inode) in one of two ways. Either the desired information
is in the dentry cache and can be accessed with minimum delay, or it must be found by the
low-level implementation of the filesystem, and the appropriate data structures must be con-
structed.do_lookupis responsible for distinguishing between these two situations (discussed
shortly) and returns the desireddentryinstance. Note that mount points are also detected in
this step.
❑ The last step in the processing of a path component is the kernel check to determine whether the
component is a symbolic link.
How does the kernel establish whether adentrystructure is a symbolic link? Only inodes used
to represent symbolic links^21 include thelookupfunction in the inode operations. Otherwise, the
field is assigned a null pointer.
do_follow_linkis used as a VFS layer front-end to follow the link, as discussed below.

The loop is repeated until the end of the filename isreached — the kernel recognizes this by the fact
that the pathname contains no further/. Using the means described above, the last component is also
resolved into adentryentry that is returned as the result of thelink_path_walkoperation.


(^21) Hard links require no special treatment in lookup code because they are indistinguishable from normal files.

Free download pdf