Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


8.4.2 File Operations


Operations with complete filesystems are an important aspect of the VFS layer but occur comparatively
rarely — because, with the exception of removable devices, filesystems are mounted during the boot
process and are unmounted at shutdown. More usualare frequently repeated operations on files by all
system processes.

To permit universal access to files regardless of the filesystem used, the VFS provides interface functions
for file processing in the form of various system calls as already noted above. This section concentrates
on the most common operations performed by processes when working with files.

FindingInodes


A major operation is the finding of an inode by reference to a given filename. Thisprovidesuswithan
opportunity to examine thelookupmechanism used to find this information.

Thenameidatastructure is used to pass parameters to the lookup function and to hold the lookup result.
We encountered this structure above without actually defining it, so let’s do this now.

<fs.h>
struct nameidata {
struct dentry *dentry;
struct vfsmount *mnt;
struct qstr last;
unsigned int flags;
...
}

❑ dentryandmntcontain the data of the required filesystem entry after completion of lookup.
❑ flagsholds flags to fine-tune the lookup operation. I will come back to these when I describe the
lookup algorithm.
❑ lastcontains the name to be looked up. It is aquick stringthat, as described above, includes not
only the string itself but also the length of the string and a hash value.

The kernel uses thepath_lookupfunction to find any path or filename.

fs/namei.c
int fastcall path_lookup(const char *name, unsigned int flags,
struct nameidata *nd)

In addition to the requirednameand the lookupflags, the function expects a pointer to anameidata
instance that is used as ‘‘working memory‘‘ for interim results.

First, the kernel uses thenameidatainstance to define the starting point for lookup. If the name begins
with/,thedentryandvfsmntinstances of the current root directory are used (note must be taken of
any activechrootcage); otherwise, the current working directory data obtained from the task structure
are used.
Free download pdf