Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


❑ check_media_changeis only available for device files and checks whether there has been a
media change since the last access. Prime examples are the block-device files for CD-ROMs and
floppies that can be exchanged by users (hard disks are not usually exchanged).
❑ sendfileexchanges data between two file descriptors by means of thesendfilesystem call. As
sockets (see Chapter 12) are also represented by file descriptors, this function is also used for the
simple, efficient exchange of data over networks.
❑ splice_readandsplice_writeare used to transfer data from a pipe into a file and vice versa.
Since the methods are currently only used by the system callsplice2, I will not discuss them
any further.

An object that uses the structure shown here as an interface need not implement all operations. To
take a concrete example, pipes between processes provide only a few operations because the remain-
ing operations make no sense at all — pipes cannot read directory contents, soreaddiris not available,
for instance.


There are two ways of specifying that a certain method is not available — either by assigning a null
pointer to the function pointer or by invoking a dummy that simply returns an error value.


For example, the followingfile_operationsinstance is provided for block devices (see Chapter 6):


fs/block_dev.c
const struct file_operations def_blk_fops = {
.open = blkdev_open,
.release = blkdev_close,
.llseek = block_llseek,
.read = do_sync_read,
.write = do_sync_write,
.aio_read = generic_file_aio_read,
.aio_write = generic_file_aio_write_nolock,
.mmap = generic_file_mmap,
.fsync = block_fsync,
.unlocked_ioctl = block_ioctl,
.splice_read = generic_file_splice_read,
.splice_write = generic_file_splice_write,
};

The Ext3 filesystem uses a different set of functions.


fs/ext3/file.c
const struct file_operations ext3_file_operations = {
.llseek = generic_file_llseek,
.read = do_sync_read,
.write = do_sync_write,
.aio_read = generic_file_aio_read,
.aio_write = ext3_file_write,
.ioctl = ext3_ioctl,
.mmap = generic_file_mmap,
.open = generic_file_open,
.release = ext3_release_file,
.fsync = ext3_sync_file,
.splice_read = generic_file_splice_read,
.splice_write = generic_file_splice_write,
};
Free download pdf