Chapter 10: Filesystems without Persistent Storage
In addition to attribute handling, the directory supports just one more operation β subentry lookup.^2
The task ofproc_tgid_base_lookupis to return an inode instance with suitable inode operations by
reference to a given name (cmdline,maps, etc.). The extended inode operations (proc_inode)mustalso
include a function to output the desired data. Figure 10-5 shows the code flow diagram.
proc_tgid_base_lookup
proc_pident_lookup
Check if name exits in tigd_base_stuff
proc_pident_instantiate
proc_pid_make_inode
Fill in inode and file operations
Figure 10-5: Code flow diagram forproc_tgid_base_lookup.
The work is delegated toproc_pident_lookup, which works not only for TGID files, but is a generic
method for other ID types. The first step is to find out whether the desired entry exists at all. Because the
contents of the PID-specific directory are always the same, a static list of all files together with a few other
bits of information is defined in the kernel sources. The list is calledtgid_base_stuffand is used to find
out easily whether a desired directory entry exists or not. The array contains elements of typepid_entry,
which is defined as follows:
fs/proc/base.c
struct pid_entry {
char *name;
int len;
mode_t mode;
const struct inode_operations *iop;
const struct file_operations *fop;
union proc_op op;
};
nameandlenspecify the filename and the string length of the name, whilemodedenotes the mode bits.
Additionally, there are fields for the inode and file operations associated with the entry, and a copy of
proc_op. Recall that this contains a pointer to theproc_get_linkorproc_read_linkoperation, depend-
ing on the file type.
Some macros are provided to ease the construction of staticpid_entryinstances:
fs/proc/base.c
#define DIR(NAME, MODE, OTYPE) \
NOD(NAME, (S_IFDIR|(MODE)), \
(^2) Aspecialreaddir method is also implemented for proc_tgid_base_operations (an instance of struct
file_operations) to read a list of all files in the directory. Itβs not discussed here simply because every PID-specific directory
always contains the same files, and therefore the same data would always be returned.