Chapter 22. Mount Table

The mount table records the filesystems that are actually active. These can be seen as being analogous to mount points in Unix systems.

There are two sources of mount table entries. Filesystems (or other components) may export static entries to the table using the MTAB_ENTRY() macro. Alternatively, new entries may be installed at run time using the mount() function. Both types of entry may be unmounted with the umount() function.

A mount table entry has the following structure:

struct cyg_mtab_entry
    const char          *name;          // name of mount point
    const char          *fsname;        // name of implementing filesystem
    const char          *devname;       // name of hardware device
    const char          *options;       // mount option string
    CYG_ADDRWORD        data;           // private data value
    cyg_bool            valid;          // Valid entry?
    cyg_fstab_entry     *fs;            // pointer to fstab entry
    cyg_dir             root;           // root directory pointer

The name field identifies the mount point. This is used to direct rooted filenames (filenames that begin with "/") to the correct filesystem. When a file name that begins with "/" is submitted, it is matched against the name fields of all valid mount table entries. The entry that yields the longest match terminating before a "/", or end of string, wins and the appropriate function from the filesystem table entry is then passed the remainder of the file name together with a pointer to the table entry and the value of the root field as the directory pointer.

For example, consider a mount table that contains the following entries:

{ "/",    "fatfs", "/dev/hd0", … }
{ "/fd",  "fatfs", "/dev/fd0", … }
{ "/rom", "romfs", "", … }
{ "/tmp", "ramfs", "", … }
{ "/dev", "devfs", "", … }

An attempt to open "/tmp/foo" would be directed to the RAM filesystem while an open of "/bar/bundy" would be directed to the hard disc FATFS filesystem. Opening "/dev/tty0" would be directed to the device management filesystem for lookup in the device table.

Unrooted file names (those that do not begin with a '/') are passed straight to the filesystem that contains the current directory. The current directory is represented by a pair consisting of a mount table entry and a directory pointer.

The fsname field points to a string that should match the name field of the implementing filesystem. During initialization the mount table is scanned and the fsname entries looked up in the filesystem table. For each match, the filesystem's _mount_ function is called and if successful the mount table entry is marked as valid and the fs pointer installed.

The devname field contains the name of the device that this filesystem is to use. This may match an entry in the device table (see later) or may be a string that is specific to the filesystem if it has its own internal device drivers.

The data field is a private data value. This may be installed either statically when the table entry is defined, or may be installed during the mount() operation.

The valid field indicates whether this mount point has actually been mounted successfully. Entries with a false valid field are ignored when searching for a name match.

The fs field is installed after a successful mount() operation to point to the implementing filesystem.

The root field contains a directory pointer value that the filesystem can interpret as the root of its directory tree. This is passed as the dir argument of filesystem functions that operate on rooted filenames. This field must be initialized by the filesystem's mount() function.