Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


An empty filesystem is not very interesting, so we need a way of filling the sample filesystem with data.
This is done by mounting the filesystem using the loopback interface, as shown in the following example:

wolfgang@meitner>mount -t ext2 -o loop=/dev/loop0 img.1440 /mnt

The filesystem can then be manipulated in such a way as to give the impression that it is located on a
regular partition of a block device. All changes are transferred toimg.1440and can be examined there.

9.2.4 Filesystem Actions


As demonstrated in Chapter 8, the association between the virtual filesystem and specific implemen-
tations is established in the main by three structures that include a series of function pointers; this
association must be implemented by all filesystems.

❑ Operations for manipulating the contents of a file are stored infile_operations.
❑ Operations for processing the file objects themselves are held ininode_operations
❑ Operations with generalized address spaces are stored inaddress_space_operations.

The Ext2 filesystem features various instances offile_operationsfor different file types. Naturally, the
most frequently used variant is for regular files and is defined as follows:

fs/ext2/file.c
struct file_operations ext2_file_operations = {
.llseek = generic_file_llseek,
.read = do_sync_read,
.write = do_sync_write,
.aio_read = generic_file_aio_read,
.aio_write = generic_file_aio_write,
.ioctl = ext2_ioctl,
.mmap = generic_file_mmap,
.open = generic_file_open,
.release = ext2_release_file,
.fsync = ext2_sync_file,
.readv = generic_file_readv,
.splice_read = generic_file_splice_read,
.splice_write = generic_file_splice_write,
};

Most entries hold pointers to the standard functions of VFS discussed in Chapter 8.

Directories also have their ownfile_operationsinstance — which is much shorter because many file
operations make no sense if applied to directories.

fs/ext2/dir.c
struct file_operations ext2_dir_operations = {
.llseek = generic_file_llseek,
.read = generic_read_dir,
.readdir = ext2_readdir,
.ioctl = ext2_ioctl,
.fsync = ext2_sync_file,
};
Free download pdf