Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


the length of the name. Also adopted from the classic filesystem concept is the numbering of all inodes
usinglow_ino.Themeaningofmodeis the same as in normal filesystems because the element reflects the
type of the entry (file, directory, etc.), and the assignment of access rights in accordance with the classic
‘‘owner, group, others‘‘ scheme by means of the appropriate constants in<stat.h>.uidandgidspecify
the user ID and group ID to which the file belongs. Both are usually set to 0, which means that the root
user is the owner of almost allprocfiles.


The usage counter common to most data structures is implemented bycount, which indicates the number
of points at which the instance of a data structure is used in the kernel to ensure that the structure is not
freed inadvertently.


proc_iopsandproc_fopsare pointers to instances of typesinode_operationsandfile_operations
discussed in Chapter 8. They hold operations that can be performed on an inode or file and act as an inter-
face to the virtual filesystem that relies on their presence. The operations used depend on the particular
filetypeandarediscussedinmoredetailbelow.


The file size in bytes is saved in thesizeelement. Becauseprocentries are generated dynamically, the
length of a file is not usually known in advance; in this case, the value 0 is used.


If aprocentry is generated by a dynamically loaded module,modulecontains a reference to the associ-
ated module data structure in memory (if the entry was generated by compiled-in code,moduleholds a
null pointer).


The following three elements are available to control the exchange of information between the virtual
filesystem (and ultimately userspace) and the variousprocentries or individual kernel subsystems.


❑ get_infois a function pointer to the relevant subsystem routine that returns the desired data.
As with normal file access, the offset and length of the desired range can be specified so that it is
not necessary to read the full data set. This is useful, for example, for the automated analysis of
procentries.
❑ read_procandwrite_procpoint to functions to support the reading of data from and the writ-
ing of data to the kernel. The parameters and return values of the two functions are specified by
the following type definition:
<proc_fs.h>
typedef int (read_proc_t)(char *page, char **start, off_t off,
int count, int *eof, void *data);
typedef int (write_proc_t)(struct file *file, const char __user *buffer,
unsigned long count, void *data);
Whereas data are read on the basis of memory pages (of course, an offset and the length of the
data to be read can also be specified), the writing of data is based on afileinstance. Both rou-
tines have an additionaldataargument that is defined when a newprocentry is registered and
is passed as a parameter each time the routine is invoked (thedataelement ofproc_dir_entry
holds the data argument). This means that a single function can be registered as the read/write
routine forseveralprocentries; the code can then distinguish the various cases by reference to
thedataargument (this is not possible withget_infobecause no data argument is passed). This
tactic has already been adopted in preceding chapters to prevent the unnecessary duplication of
code.
Free download pdf