Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


fd_install

sys_open

force_o_largefile

do_sys_open

get_unused_fd_flags

do_flip_open

open_namei

nameidata_to_filp

Figure 8-11: Code flow diagram forsys_open.

do_filp_openfinds the file inode with the support of two helper functions.


  1. open_nameiinvokes thepath_lookupfunction to find the inode and performs several
    additional checks (e.g., to ascertain whether the application is trying to open a directory
    as if it were a regular file). If a new filesystem entry needs to be created, the function also
    applies the current default settings for the permission bits as stored in the process’s umask
    (current->fs->umask).

  2. nameidata_to_filpinitializes the readahead structure, places the newly generatedfile
    instance on thes_fileslist of the superblock (see Section 8.4.1), and invokes theopenfunc-
    tion in thefile_operationsstructure of the underlying filesystem.


fd_installmust then install thefileinstance infiles->fdfrom the task structure of the process before
control is transferred back to the user process to which the file descriptor is returned.

Reading andWriting


Once a file has been successfully opened, a process either reads or modifies the data it contains using the
readandwritesystem calls provided by the kernel. As usual, the entry routines are calledsys_readand
sys_write, and both are implemented infs/read_write.c.

Read


Thereadfunction requires three parameters — the file descriptor, a buffer to hold data, and a length
argument to specify the number of characters to be read. The parameters are passed directly to the kernel.

For the VFS layer, reading from a file is not particularly difficult, as Figure 8-12 illustrates.

By reference to the file descriptor number, the kernel (using thefget_lightfunction from
fs/file_table.c)isabletofindthefileinstance associated with the task structure of the process.

After finding the current position in the file withfile_pos_read(the routine just needs to return the
value offile->f_pos), the read operation itself is delegated tovfs_read. This routine invokes either
Free download pdf