Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


Reading andGenerating Dataand IndirectionBlocks


Once the filesystem has been mounted, user processes can invoke the functions in Chapter 8 to access file
contents. The required system calls are first forwarded to the VFS layer, which, depending on file type,
invokes the appropriate routine of the underlying filesystem.

As mentioned at the beginning of this section, a large number of low-level functions are available for
this purpose. Not all variants are discussed in detail here but only the central basic actions that make
up the major part of the code in user applications — generating, opening, reading, closing, and deleting
files and directory objects. Both file-specific and inode-specific operations are used to this end. Often
the virtual filesystem provides default actions (such asgeneric_file_readandgeneric_file_mmap);
these use only a few elementary functions of the low-level filesystem to perform higher abstracted tasks.
This discussion is restricted to the required interfaces of the Ext2 file system ‘‘upward‘‘ to the virtual
filesystem; these include primarily the reading and writing of data blocks associated with a specific
position in a file. From the VFS perspective, the purpose of a filesystem is to establish the link between
file contents and the corresponding blocks on the associated storage medium.

Finding Data Blocks


ext2_get_blockis the key function for associating the Ext2 implementation with the default functions
of the virtual filesystem. It should be remembered that all filesystems wishing to use the VFS standard
functions must define a function of typeget_block_twith the following signature:

<fs.h>
typedef int (get_block_t)(struct inode *inode, sector_t iblock,
struct buffer_head *bh_result, int create);

This function not only reads blocks (as its name suggests), but alsowritesblocks from memory to a block
medium. When it does the latter, it may under certain circumstances also be necessary to generate new
blocks, and this behavior is controlled by thecreateparameter.

The function used by ext2 isext2_get_block. It is a front end to the more universalext2_get_blocks
that performs the important task of finding blocks. Its code flow diagram is shown in Figure 9-9, where
the actions needed to create blocks (create==true) are initially ignored.

ext2_get_blocks

ext2_get_block_to_path

ext2_get_branch

Figure 9-9: Code flow diagram for
ext2_get_block(reading a block).

The operation is split into three small steps. The first auxiliary function invoked isext2_block_to_path,
which concerns itself with finding the ‘‘path’’ to a data block by reference to its position in the file. As
explained in Section 9.2.1, the Ext2 filesystem usesup to three levels of indirection to manage file data
blocks.
Free download pdf