Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


The next two lines ofproc_fill_supercreate an inode for the root directory and used_alloc_rootto
convertitintoadentrythat is assigned to the superblock instance; here it is used as the starting point for
lookup operations in the mounted filesystem, as described in Chapter 8.


In the main, theproc_get_inodefunction used to create the root inode fills several inode structure values
to define, for example, the owner and the access mode. Of greater interest is the staticproc_dir_entry
instance calledproc_root; when it is initialized, it gives rise to data structures with relevant function
pointers:


fs/proc/root.c
struct proc_dir_entry proc_root = {
.low_ino = PROC_ROOT_INO,
.namelen = 5,
.name = "/proc",
.mode = S_IFDIR | S_IRUGO | S_IXUGO,
.nlink = 2,
.count = ATOMIC_INIT(1),
.proc_iops = &proc_root_inode_operations,
.proc_fops = &proc_root_operations,
.parent = &proc_root,
}

The root inode differs from all other inodes of theprocfile system in that it not only contains ‘‘normal‘‘
files and directories (even though they are generated dynamically), but also manages the process-specific
PID directories that contain detailed information onthe individual system processes, as mentioned above.
The root inode therefore has its own inode and file operations, which are defined as follows:


fs/proc/root.c
/*
* The root /proc directory is special, as it has the
* <pid> directories. Thus we don’t use the generic
* directory handling functions for that..
*/
static struct file_operations proc_root_operations = {
.read = generic_read_dir,
.readdir = proc_root_readdir,
};

/*
* proc root can do almost nothing..
*/
static struct inode_operations proc_root_inode_operations = {
.lookup = proc_root_lookup,
.getattr = proc_root_getattr,

}

generic_read_diris a standard virtual filesystem function that returns-EISDIRas an error code; this
is because directories cannot be handled like normal files in order to get data from them. Section 10.1.5
describes howproc_root_lookupfunctions.

Free download pdf