Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


proc_inode VFS-Inode

PROC_I
Figure 10-1: Connection betweenstruct proc_inode
andstruct inode.

The remaining elements of the structure are only used if the inode represents a process-specific entry
(which is therefore located in theproc/piddirectory). Their meanings are as follows:

❑ pidis a pointer to thepidinstance of a process. Because it is possible to access a large amount of
process-specific information this way, it is clear why a process-specific inode should be directly
associated with this data.
❑ proc_get_linkandproc_read(which are collected in a union because only one at a time makes
sense) are used to get process-specific information or to generate links to process-specific data in
the Virtual Filesystem.
❑ fdholds the filedescriptor for which a file in/proc/<pid>/fd/presents information. With the
help offd, all files in this directory can use the samefile_operations.

The meanings and use of these elements are discussed in detail in Section 10.1.7.

10.1.3 Initialization


Before theprocfilesystem can be used, it must be mounted withmount, and the kernel must set up and
initialize several data structures to describe the filesystem structure in kernel memory. Unfortunately, the
appearance and contents of/procdiffer substantially from platform to platform and from architecture
to architecture, and the code is crammed with#ifdefpre-processor statements that select code sections
according to the particular situation. Although this practice is frowned upon, it simply cannot be avoided.

Because initialization differences relate primarily to creation of the subdirectories that subse-
quently appear in/proc, they are not evident in Figure 10-2, which shows a code flow diagram of
proc_root_initinfs/proc/root.c.

proc_root_init

proc_init_inodecache

register_filesystem

kern_mount_data

proc_misc_init

proc_net_init

Create directories with proc_mkdir
Figure 10-2: Code flow diagram for
proc_root_init.
Free download pdf