Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


fs/proc/proc_sysctl.c
static struct inode_operations proc_sys_inode_operations = {
.lookup = proc_sys_lookup,
.permission = proc_sys_permission,
.setattr = proc_sys_setattr,
};

Lookup operations are handled byproc_sys_lookup. The following approach is used to dynamically
construct inodes forprocentries:

❑ do_proc_sys_lookuptakes the parentdentryand the name of the file or directory to find the
desired sysctl table entry. This involves mainly iterating over the data structures presented
before.
❑ Given theinodeof the parent directory and the sysctl table,proc_sys_make_inodeis employed
to construct the requiredinodeinstance. Since the new inode’s inode operations are also imple-
mented byproc_sys_inode_operations, it is ensured that the described method also works for
new subdirectories.

The file operations for/proc/sysentries are given as follows:

kernel/sysctl.c
static const struct file_operations proc_sys_file_operations = {
.read = proc_sys_read,
.write = proc_sys_write,
.readdir = proc_sys_readdir,
};

Read and write file operations for all entries are implemented by means of standard operations.

/proc/sysFile Operations


The implementations forproc_sys_readandproc_sys_writeare very similar. Both require three easy
steps:


  1. do_proc_sys_lookupfinds the sysctl table entry that is associated with the file in/proc/sys.

  2. It is not guaranteed that all rights on sysctl entries are granted even to the root user. Some
    entries can, for instance, be only read, but are not allowed to be changed, that is, written to.
    Thus an extra permission check withsysctl_permis required. Whileproc_sys_readneeds
    read permission, write permission is necessary forproc_sys_write.

  3. Calling theprochandler stored in the sysctl table completes the action.


proc_handleris assigned a function pointer when the sysctl tables are defined. Because the various
sysctls are spread over several standard categories(in terms of their parameter and return values), the
kernel provides standard implementations that are normally used in place of the specific function imple-
mentations. Most frequently, the following functions are used:

❑ proc_dointvecreads or writes integer values from or to the kernel [the exact number of values
is specified bytable->maxlen/sizeof(unsigned int)]. Only a single integer may be involved
(and not a vector) ifmaxlenindicates the byte number of a singleunsigned int.
Free download pdf