Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


Directories use the following structures:

fs/proc/generic.c
static struct file_operations proc_dir_operations = {
.read = generic_read_dir,
.readdir = proc_readdir,
};

fs/proc/generic.c
/* proc directories can do almost nothing... */
static struct inode_operations proc_dir_inode_operations = {
.lookup = proc_lookup,
.getattr = proc_getattr,
.setattr = proc_notify_change,
};

Symbolic links require inode operations but not file operations:

fs/proc/generic.c
static struct inode_operations proc_link_inode_operations = {
.readlink = generic_readlink,
.follow_link = proc_follow_link,
};

Later in this section, I take a closer look at the implementation of some of the routines in the above data
structures.

In addition tocreate_proc_entry, the kernel provides two further auxiliary functions for creating new
procentries. All three are short wrapper routines forcreate_proc_entryand are defined with the
following parameter list:

<proc_fs.h>
static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
mode_t mode, struct proc_dir_entry *base,
read_proc_t *read_proc, void * data) { ... }

static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
mode_t mode, struct proc_dir_entry *base, get_info_t *get_info) { ... }

create_proc_read_entryandcreate_proc_info_entryare used to create a new read entry. Because
this can be done in two different ways (as discussed in Section 10.1.2), there must also be two routines.
Whereascreate_proc_info_entryrequires a procedure pointer of typeget_info_tthat is added to the
get_infoelement ofproc_dir_entry,create_proc_info_entryexpects not only a procedure pointer
of typeread_proc_t, but also a data pointer that enables the same function to be used as a read routine
for variousprocentries distinguished by reference to their data argument.

Although we are not interested in their implementation, I include below a list of other auxiliary functions
used to manageprocentries:

❑ proc_mkdircreates a new directory.
❑ proc_mkdir_modecreates a new directory whose access mode can be explicitely specified.
Free download pdf