17.5 Ext2 Methods

Many of the VFS methods described in Chapter 12 have a corresponding Ext2 implementation. Since it would take a whole book to describe all of them, we limit ourselves to briefly reviewing the methods implemented in Ext2. Once the disk and the memory data structures are clearly understood, the reader should be able to follow the code of the Ext2 functions that implement them.

17.5.1 Ext2 Superblock Operations

Many VFS superblock operations have a specific implementation in Ext2, namely read_inode, write_inode, put_inode, delete_inode, put_super, write_super, statfs, and remount_fs. The addresses of the superblock methods are stored into the ext2_sops array of pointers.

17.5.2 Ext2 Inode Operations

Some of the VFS inode operations have a specific implementation in Ext2, which depends on the type of the file to which the inode refers.

If the inode refers to a regular file, all inode operations listed in the ext2_file_inode_operations table have a NULL pointer, except for the truncate operation that is implemented by the ext2_truncate( ) function. Recall that the VFS uses its own generic functions when the corresponding Ext2 method is undefined (a NULL pointer).

If the inode refers to a directory, most inode operations listed in the ext2_dir_inode_operations table are implemented by specific Ext2 functions (see Table 17-8).

Table 17-8. Ext2 inode operations for directory files

VFS inode operation

Ext2 directory inode method

create

ext2_create( )

lookup

ext2_lookup( )

link

ext2_link( )

unlink

ext2_unlink( )

symlink

ext2_symlink( )

mkdir

ext2_mkdir( )

rmdir

ext2_rmdir( )

mknod

ext2_mknod( )

rename

ext2_rename( )

If the inode refers to a symbolic link that can be fully stored inside the inode itself, all inode methods are NULL except for readlink and follow_link, which are implemented by ext2_readlink( ) and ext2_follow_link( ), respectively. The addresses of those methods are stored in the ext2_fast_symlink_inode_operations table. On the other hand, if the inode refers to a long symbolic link that has to be stored inside a data block, the readlink and follow_link methods are implemented by the generic page_readlink( ) and page_follow_link( ) functions, whose addresses are stored in the page_symlink_inode_operations table.

If the inode refers to a character device file, to a block device file, or to a named pipe (see Section 19.2), the inode operations do not depend on the filesystem. They are specified in the chrdev_inode_operations, blkdev_inode_operations, and fifo_inode_operations tables, respectively.

17.5.3 Ext2 File Operations

The file operations specific to the Ext2 filesystem are listed in Table 17-9. As you can see, several VFS methods are implemented by generic functions that are common to many filesystems. The addresses of these methods are stored in the ext2_file_operations table.

Table 17-9. Ext2 file operations

VFS file operation

Ext2 method

llseek

generic_file_llseek( )

read

generic_file_read( )

write

generic_file_write( )

ioctl

ext2_ioctl( )

mmap

generic_file_mmap( )

open

generic_file_open( )

release

ext2_release_file( )

fsync

ext2_sync_file( )

Notice that the Ext2's read and write methods are implemented by the generic_file_read( ) and generic_file_write( ) functions, respectively. These are described in Section 15.1.1 and Section 15.1.3.