Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


registers a new subdirectory and returns the associatedproc_dir_entryinstance; its implementation is
of no further interest. The kernel saves these instances in global variables because these data are needed
later when filling the directories with files (i.e., when supplying the real information).

fs/proc_root.c
struct proc_dir_entry *proc_net, *proc_bus, *proc_root_fs, *proc_root_driver;

void __init proc_root_init(void)
{
...
proc_net = proc_mkdir("sysvipc", NULL);
...
proc_root_fs = proc_mkdir("fs", NULL);
proc_root_driver = proc_mkdir("driver", NULL);
...
proc_bus = proc_mkdir("bus", NULL);
}

Further directory initialization is no longer carried out by theproclayer itself but is performed by other
parts of the kernel where the required information is made available. This makes it clear why the kernel
uses global variables to save theproc_dir_entryinstances of these subdirectories. The files inproc/net
are filled, for example, by the network layer, which inserts files at many different points in the code of
card drivers and protocols. Because new files are created when new cards or protocols are initialized, this
can be done during the boot operation (in the case of compiled-in drivers) or while the system is running
(when modules are loaded) — in any case, after initialization of theprocfilesystem byproc_root_init
has completed. If the kernel did not use global variables, it would have to provide functions to register
subsystem-specific entries, and this is neither as clean nor as elegant as using global variables.

The system control mechanism fillsproc_sys_rootwith files that are always generated when a new
sysctl is defined in the kernel. Repeated reference was made to this facility in earlier chapters. A detailed
description of the associated mechanism is provided in Section 10.1.8.

10.1.4 Mounting the Filesystem


Once all kernel-internal data that describe the structure and contents of theprocfilesystem have been
initialized, the next step is to mount the filesystem in the directory tree.

In the view of the system administrator in userspace, mounting/procis almost the same as mounting a
non-virtual filesystem. The only difference is that an arbitrary keyword (usuallyprocornone)isspecified
as the source instead of a device file:

root@meitner #mount -t proc proc /proc

The VFS-internal processes involved in mounting anew filesystem are described in detail in Chapter 8,
but as a reminder are summarized below. When it adds a new filesystem, the kernel uses a linked list
that is scanned to find an instance offile_system_typeassociated with the filesystem. This instance
provides information on how to read in the filesystem superblock. Forproc, the structure is initialized as
follows:

fs/proc/root.c
static struct file_system_type proc_fs_type = {
.name = "proc",
Free download pdf