Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


/* Parse the data and perform actions in the subsystem */
return len;
}

Usually, aproc_writeimplementation performs the following actions:


  1. First, the length of the user input (it can be determined using thecountparameter) must be
    checked to ensure that it is not longer than the reserved area.

  2. The data are copied from userspace into the reserved kernel space area.

  3. Information is extracted from the string. This operation is known asparsing,aterm
    borrowed from compiler design. In the above example, this task is delegated to the
    cpufreq_parse_policyfunction.

  4. Manipulations are then performed on the (sub)system in accordance with the user informa-
    tion received.


10.1.7 Task-Related Information


Outputting detailed information on system processes was one of the prime tasks for which theproc
filesystem was originally designed, and this still holds true today. As demonstrated in Section 10.1.7,
proc_pid_lookupis responsible for opening PID-specific files in/proc/<pid>. The associated code flow
diagram is shown in Figure 10-4.

proc_pid_lookup

name == self? Yes Create self incode
No

find_task_by_pid_ns

proc_pid_instantiate

proc_pid_make_inode

Fill in file and inode operations

name_to_int

Figure 10-4: Code flow diagram forproc_pid_lookup.

The goal of the routine is to create an inode that acts as the first object for further PID-specific operations;
this is because the inode represents the/proc/piddirectory containing all files with process-specific
information. Two cases, analyzed below, must be distinguished.

Theselfdirectory


Processes can be selected by explicit reference to their PIDs, but the data of the currently running pro-
cess can be accessed without knowing PID by selecting the/proc/selfdirectory — the kernel then
Free download pdf