Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


Although different pointers are assigned to the two objects, they share some common
features — functions whose name begins withgeneric_. These are general helper functions of
the VFS layer, a few of which are discussed in Section 8.5.

Process-Specific Information


Other process-specific data must be managed in addition to the list of open file descriptors. Every
task_structinstance therefore includes a pointer to a further structure of typefs_struct.

<fs_struct.h>
struct fs_struct {
atomic_t count;
int umask;
struct dentry * root, * pwd, * altroot;
struct vfsmount * rootmnt, * pwdmnt, * altrootmnt;
};

umaskrepresents the standard mask used to set permissions for a new file. Its value can be read or set
using theumaskcommand. The system call of the same name does this internally.

Thedentryelements of the structure point to the name of a directory, andvfsmountrepresents a
mounted filesystem (the exact definition of the data structures is given below).

There are three dentry and three VFS mount elements with similar names. In fact, the entries are linked
in pairs.

❑ rootandrootmntspecify the root directory and the filesystem of the relevant process. Normally
these are the/directory and the root filesystem of the system. This situation is, of course, dif-
ferent for processes locked into a certain subdirectory bychroot(and implicitly by the system
call of the same name). A subdirectory is then used instead of the global root directory, and the
process sees this subdirectory as its own new root directory.
❑ pwdandpwdmntspecify thepresent working directoryand the VFS mount structure of the filesys-
tem. Both change dynamically when the process changes its present directory; this happens
frequently (cdcommand) when working with a shell. Whereas the value ofpwdchanges with
eachchdirsystem call,^9 pwdmntis only modified when the territory of a new mount point is
entered. Let us look at an example where a floppy disk drive is mounted at/mnt/floppy.Auser
starts working with the shell in the root directory (/) and switches to the appropriate directory
by successively entering thecd /mntandcd floppycommands. Both commands change the data
infs_struct.

❑ cd /mntchanges thepwdentry but leaves thepwdmntentry unchanged — we are still in root
directory territory.
❑ cd floppychanges the value ofpwdand ofpwdmntbecause a switch has been made to a new
directory and the territory of a new filesystem has been entered.

❑ Thealtrootandaltrootmntelements are used when implementingpersonalities;theypermit
the creation of an emulation environment for binary programs so that they have the impres-
sion they are working with an operating systemother than Linux. For example, this method is

(^9) The only exception is a switch to the.directory.

Free download pdf