Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


The illustration shows three different filesystems. The global root directory/uses the Ext2 filesystem (see
Chapter 9),/mnthas a Reiserfs, and/mnt/cdromuses the ISO9660 format commonly used on CD-ROMs.
This scenario can be queried usingmount.

wolfgang@meitner>mount
/dev/hda7 on / type ext2 (rw)
/dev/hda3 on /mnt type reiserfs (rw)
/dev/hdc on /mnt/cdrom type iso9660 (ro,noexec,nosuid,nodev,user=wolfgang)

The/mntand/mnt/cdromdirectories are known asmount pointsbecausethisiswherefilesystemsare
attached (mounted). Each mounted filesystem has a local root directory that contains the system direc-
tories (thesourceandlibsdirectories in the case of a CD-ROM). When a directory is mounted, the
contents of the mount point are replaced with the relative root directory of the mounted filesystem. The
previous directory data disappear until the new directory is unmounted (naturally, the data in the old
filesystem remain unchanged but can no longer be accessed).

Mounts can be nested as in our example. The CD-ROM is mounted in the directory/mnt/cdrom.This
means that the relative root directory of the ISO9660 filesystem is mounted within a Reiser filesystem
and is therefore totally divorced from the Second Extended Filesystem used for the global root directory.

The child–parent relationship common to other parts of the kernel is also used to better describe the
relationship between two filesystems. Ext2 is the parent filesystem of the Reiserfs in/mnt./mnt/cdrom
contains the child filesystem of/mnt, which is unrelated to the Ext2 root filesystem (at least from this
point of view).

The platform for each mounted filesystem is an instance of thevfsmountstructure, which is defined as
follows:

<mount.h>
struct vfsmount {
struct list_head mnt_hash;
struct vfsmount *mnt_parent; /* fs we are mounted on */
struct dentry *mnt_mountpoint; /* dentry of mountpoint */
struct dentry *mnt_root; /* root of the mounted tree */
struct super_block *mnt_sb; /* pointer to superblock */
struct list_head mnt_mounts; /* list of children, anchored here */
struct list_head mnt_child; /* and going through their mnt_child */
int mnt_flags;
/* 4 bytes hole on 64bits arches */
char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */
struct list_head mnt_list;
struct list_head mnt_expire; /* link in fs-specific expiry list */
struct list_head mnt_share; /* circular list of shared mounts */
struct list_head mnt_slave_list;/* list of slave mounts */
struct list_head mnt_slave; /* slave list entry */
struct vfsmount *mnt_master; /* slave is on master->mnt_slave_list */
struct mnt_namespace *mnt_ns; /* containing namespace */
/*
* We put mnt_count & mnt_expiry_mark at the end of struct vfsmount
* to let these frequently modified fields in a separate cache line
* (so that reads of mnt_flags wont ping-pong on SMP machines)
*/
Free download pdf