Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


page = find_lock_page(mapping, vmf->pgoff);
if (!page)
goto no_cached_page;
}

max_sane_readaheadcomputes a sensible upper bound on the number of pages that are supposed to be
read in in advance. If this number is greater than zero,do_page_cache_readaheadis invoked to allocate
pages in the page cache and read in the data. Since afterward there is sufficient hope the desired page
is in the page cache,find_lock_pageonce again tries to locate it there. Should this again fail, the kernel
jumps tono_cached_pageas described before.

If the page is by now contained in the page cache, it is necessary to ensure that the page is up-to-date. If it
is not, it is re-read using thereadpagemethod of the mapping, and retries the page access again starting
from the call tofind_lock_pagefurther above. Otherwise, it suffices to callmark_page_accessedto mark
the page as active.

8.5.3 Permission-Checking


vfs_permissionis the VFS layer’s standard function to check if access to a given inode is allowed for
a certain right. This right can beMAY_READ,MAY_WRITE,orMAY_EXEC.vfs_permissionisjustawrapper
function for parameter conversion; the real work is delegated topermission. First of all, the function
ensures that Write access to Read Only filesystems and immutable files is forbidden:

fs/namei.c
int permission(struct inode *inode, int mask, struct nameidata *nd)
{
int retval, submask;

if (mask & MAY_WRITE) {
umode_t mode = inode->i_mode;

/* Nobody gets write access to a read-only fs. */
if (IS_RDONLY(inode) &&
(S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
return -EROFS;

/* Nobody gets write access to an immutable file. */
if (IS_IMMUTABLE(inode))
return -EACCES;
}
...

After this, the real work is either delegated to a filesystem-specific permission-checking routine if one
exists, or togeneric_permission:

fs/namei.c
...
/* Ordinary permission routines do not understand MAY_APPEND. */
submask = mask & ~MAY_APPEND;
if (inode->i_op && inode->i_op->permission)
retval = inode->i_op->permission(inode, submask, nd);
else
Free download pdf