Section 14.4. File System Modules


14.4. File System Modules

A file system is implemented as a dynamically loadable kernel module. Each file system declares the standard module _init, _info, and _fini enTRy points, which are used to install and remove the file system within the running kernel instance.

The primary descriptive entry for each file system is provided by a static declaration of a vfsdef_t, which includes the following:

  • The version of the vfs interface used at module compile time (by specification of VFSDEF_VERSION).

  • The name of the file system (a string).

  • The global initialization function to be called when the file system module is loaded. Although a file system module is typically loaded on the first mount, a module can be loaded modload(1M) without mounting a file system.

  • A set of options that can be set at mount time.

static mntopt_t tmpfs_options[] = {         /* Option name          Cancel Opt      Arg     Flags           Data */         { MNTOPT_XATTR,         xattr_cancel,   NULL,   MO_DEFAULT,     NULL},         { MNTOPT_NOXATTR,       noxattr_cancel, NULL,   NULL,           NULL},         { "size",               NULL,           "0",    MO_HASVALUE,    NULL} }; static mntopts_t tmpfs_proto_opttbl = {         sizeof (tmpfs_options) / sizeof (mntopt_t),         tmpfs_options }; static vfsdef_t vfw = {         VFSDEF_VERSION,         "tmpfs",         tmpfsinit,         VSW_HASPROTO,         &tmpfs_proto_opttbl };                                            See usr/src/uts/common/fs/tmpfs/tmp_vfsops.c 


14.4.1. Interfaces for Mount Options

The options template is used to accept and validate options at mount time. A standard set is defined in sys/vfs.h, but you can add your own by simply supplying a string (as tmpfs does for size).

The mntopts_t struct (usually called the mount options table) consists of a count of the number of options and an array of options structures of length count. Each file system should define a prototype mount options table that will be used by the vfs_initopttbl() function to initialize the working mount options table for each mount instance. The text below describes the initialization of the prototype mount options table. The vfs_initopttbl() function should be used to initialize working mount options tables from the prototype mount options table.

typedef struct mntopts {         int             mo_count;       /* number of entries in table */         mntopt_t        *mo_list;       /* list of mount options */ } mntopts_t;                                                        See usr/src/uts/common/sys/vfs.h 


Each mount option contains fields to drive the parser and fields to accept the results of the parser's execution. Here is the structure that defines an individual option in the mount options table.

typedef struct mntopt {         char    *mo_name;       /* option name */         char    **mo_cancel;    /* list of options cancelled by this one */         char    *mo_arg;        /* argument string for this option */         int     mo_flags;       /* flags for this mount option */         void    *mo_data;       /* file system specific data */ } mntopt_t;                                                        See usr/src/uts/common/sys/vfs.h 


Each option must have a string that gives the name of the option. Additionally, if an option is one that invalidates other options, the mo_cancel field points to a NULL-terminated list of names of options to turn off if this option is recognized. If an option accepts an argument (that is, it is of the form opt=arg), then the mo_arg field should be initialized with the string that is the default for the argument (if it has a default value; otherwise NULL). During option parsing, the parser will then replace the string in the working mount options table with the string provided by the user if the option is recognized during option parsing. The following flags are recognized by or set by the parser during option parsing.

  • MO_NODISPLAY. Option will not be listed in mounted file system table.

  • MO_HASVALUE. Option is expected to have an argument (that is, of form opt = arg)

  • MO_IGNORE. Option is ignored by the parser and will not be set even if seen in the options string. (Can be set manually with vfs_setmntopt function.)

  • MO_DEFAULT. Option is set on by default and will show in mnttab even if not seen by parser in options string.

The mo_data field is for use by a file system to hold any option-specific data it may wish to make use of.

14.4.2. Module Initialization

A standard file system module will provide a module _init function and register an initialization function to be called back by the file system module-loader facility. The following example shows the initialization linkage between the module declaration and the file-system-specific initialization function.

static vfsdef_t vfw = {         VFSDEF_VERSION,         "tmpfs",         tmpfsinit,         VSW_HASPROTO,         &tmpfs_proto_opttbl }; /*  * Module linkage information  */ static struct modlfs modlfs = {         &mod_fsops, "filesystem for tmpfs", &vfw }; static struct modlinkage modlinkage = {         MODREV_1, &modlfs, NULL }; int _init() {         return (mod_install(&modlinkage)); } /*  * initialize global tmpfs locks and such  * called when loading tmpfs module  */ static int tmpfsinit(int fstype, char *name) { ... }                                            See usr/src/uts/common/fs/tmpfs/tmp_vfsops.c 


The module is automatically loaded by the first invocation of mount(2) (typically from a mount command). Upon module load, the _init() function of the file system is called; this function completes its self-install with mod_install(), which subsequently calls the file system init function (tmpfsinit() in this example) defined in the vfsdef_t.

Note that file systems no longer need to create and install a vfs switch entry; this is done automatically by the module loading using the information supplied in the vfsdef_t.




SolarisT Internals. Solaris 10 and OpenSolaris Kernel Architecture
Solaris Internals: Solaris 10 and OpenSolaris Kernel Architecture (2nd Edition)
ISBN: 0131482092
EAN: 2147483647
Year: 2004
Pages: 244

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net