Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


the file-specific read routinefile->f_op->reador — if it doesn’t exist — the generic helper function
do_sync_read. After this, the new position within the file is recorded byfile_pos_write—again,the
routine just needs to bringfile->f_posto the current position.

Yes

file_pos_write

No

sys_read

fget_light

file_pos_read

vfs_read

file->f_op->read exists? do_sync_read

file->f_op->read

Figure 8-12: Code flow diagram forsys_read.

Reading data involves a sophisticated system of buffers and caches to increase system performance. I
therefore deal extensively with this topic in Chapter 16. Chapter 9 examines how filesystems implement
the read routine.

Write


The structure of thewritesystem call is just as simple as that of thereadroutine. Both code flow dia-
grams are identical except that thef_op->writeanddo_sync_writefunctions are used instead of their
read equivalents.

From a formal point of view,sys_writerequires the same parameters assys_read— a file descriptor,
a pointer variable, and a length specification (expressed as an integer number). Obviously, their mean-
ings are slightly different. The pointer does not point to a buffer area in which the data to be read are
stored but to the data to be written to the file. The length argument specifies the length of these data
in bytes.

Write operations are likewise directed through the cache system of the kernel (we discuss this topic
extensively in Chapter 16).

8.5 Standard Functions


Useful resources of the VFS layer are the standard functions provided to read and write data. These
operations are more or less identical for all filesystems. If the blocks in which the data reside are known,
the page cache is first consulted. If the data are not held there, a read request is submitted to the rele-
vant block device. Implementing these operations for every single filesystem would result in a massive
duplication of code that must be prevented at all costs.
Free download pdf