Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


registration, which is a prerequisite for these actions). I then introduce the most important and most
interesting functions involving files and all other objects represented via the same interfaces.

We start with the system calls used by the standard library to communicate with the kernel.

8.4.1 Filesystem Operations


Whereas file operations are part of the standard repertoire of all applications, actions on filesystems are
restricted to just a few system programs, namely, themountandumountprograms^13 for mounting and
unmounting filesystems.

A further important aspect must also be taken intoconsideration. Filesystems are implemented in
modular form in the kernel; this means that they can be compiled into the kernel as modules
(see Chapter 7) or can be totally ignored by compiling the kernel without support for a particular
filesystem version — given the fact that there are about 50 filesystems, it would make little sense to keep
the code for all of them in the kernel.

Consequently, each filesystem must register with the kernel before it is used so that Linux has an
overview of the available filesystems and can invoke the required mount functions.

Registering Filesystems


When a filesystem is registered with the kernel, it makes no difference whether the code is compiled as
a module or is permanently compiled into the kernel. The technical approach is the same in both cases,
regardless of the time of registration (permanently compiled filesystems are registered at boot time,
modular filesystems when the relevant module is loaded into the kernel).

register_filesystemfromfs/super.cis used to register a filesystem with the kernel. The structure
of the function is very simple. All filesystems are stored in a (singly) linked list, and the name of each
filesystem is stored as a string in a list object. When a new filesystem is registered with the kernel, this
list is scanned element-by-element until either the end of the list is reached or the required filesystem
is found. In the latter case, an appropriate error message is returned (a filesystem cannot be registered
twice); otherwise, the object describing the new filesystem is placed at the end of the list and is therefore
registered with the kernel.

The structure used to describe a filesystem is defined as follows:

<fs.h>
struct file_system_type {
const char *name;
int fs_flags;
struct super_block *(*get_sb) (struct file_system_type *, int,
const char *, void *, struct vfsmount *);
void (*kill_sb) (struct super_block *);
struct module *owner;
struct file_system_type * next;
struct list_head fs_supers;
};

(^13) In earlierUnixversions, this command was logically calledunmount,butthefirstnhas been lost in the long history of this oper-
ating system.

Free download pdf