Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


❑ proc_symlinkgenerates a symbolic link.
❑ remove_proc_entrydeletes a dynamically generated entry from theprocdirectory.

The kernel sources include a sample file inDocumentation/DocBook/procfs_example.c.Thisdemon-
strates the options described here and can be used as a template for writingprocroutines. Section 10.1.6
includes some sample kernel source routines that are responsible for interaction between the read/write
routines of theprocfilesystem and the kernel subsystems.

FindingEntries


Userspace applications accessprocfiles as if they were normal files in regular filesystems; in other words,
they follow the same path as the VFS routines described in Chapter 8 when searching for entries. As
discussed there, the lookup process (e.g., of theopensystem call) duly arrives atreal_lookup,which
invokes the function saved in thelookupfunction pointer ofinode_operationsto resolve the filename
by reference to its individual path components. In this section, we take a look at the steps performed by
the kernel to find files in theprocfilesystem.

The search for entries starts at the mount point of theprocfilesystem, usually/proc. In Section 10.1.2
you saw that thelookuppointer of thefile_operationsinstance for the root directory of the process
filesystem points to theproc_root_lookupfunction. Figure 10-3 shows the associated code flow diagram.

proc_root_lookup

proc_lookup

proc_pid_lookup

Figure 10-3: Code flow diagram for
proc_root_lookup.

The kernel uses this routine simply to distinguish between two different types ofprocentries before
delegating the real work to specialized routines. Entries may be files in a process-specific directory, as
with/proc/1/maps. Alternatively, entries may be files registered dynamically by a driver or subsystem
(e.g.,/proc/cpuinfoor/proc/net/dev). It is up to the kernel to distinguish between the two.

The kernel first invokesproc_lookupto find regular entries. If the function finds the file it is looking
for (by sequentially scanning the components of thespecified path), everything is OK, and the lookup
operation is terminated.

Ifproc_lookupfails to find an entry, the kernel invokesproc_pid_lookupto look in the list of process-
specific entries.

These functions are not examined in detail here. All we need to know is that an appropriate inode type
is returned (proc_pid_lookupis discussed again in Section 10.1.7, where the creation and structure of
process-specific inodes are discussed).
Free download pdf