4bf8e4da3a703fb2446a98cc539b184faa789b5e
[unix-history] / usr / src / sbin / mount / getmntopts.3
.\" Copyright (c) 1994
.\" The Regents of the University of California. All rights reserved.
.\"
.\" %sccs.include.redist.roff%
.\"
.\" @(#)getmntopts.3 8.2 (Berkeley) %G%
.\"
.Dd
.Dt GETMNTOPTS 3
.Os BSD 4.4
.Sh NAME
.Nm getmntopts
.Nd scan mount options
.Sh SYNOPSIS
.Fd #include <mntopts.h>
.Ft void
.Fn getmntopts "char *options" "struct mntopt *mopts" "int *flagp" "int *altflagp"
.Sh DESCRIPTION
The
.Nm getmntopts
function takes a comma separated option list and a list
of valid option names, and computes the bitmask
corresponding to the requested set of options.
.Pp
The string
.Dv options
is broken down into a sequence of comma separated tokens.
Each token is looked up in the table described by
.Dv mopts
and the bits in
the word referenced by either
.Dv flagp
or
.Dv altflagp
(depending on the
.Dv m_altloc
field of the option's table entry)
are updated.
The flag word is not initialized by
.Nm getmntopt .
The table,
.Dv mopts ,
has the following format:
.Bd -literal
struct mntopt {
char *m_option; /* option name */
int m_inverse; /* is this a negative option, eg "dev" */
int m_flag; /* bit to set, eg MNT_RDONLY */
int m_altloc; /* non-zero to use altflagp rather than flagp */
};
.Ed
.Pp
The members of this structure are:
.Bl -tag -width m_inverse
.It Fa m_option
the option name,
for example
.Dq suid .
.It Fa m_inverse
tells
.Nm getmntopts
that the name has the inverse meaning of the
bit.
For example,
.Dq suid
is the string, whereas the
mount flag is
.Dv MNT_NOSUID .
In this case, the sense of the string and the flag
are inverted, so the
.Dv m_inverse
flag should be set.
.It Fa m_flag
the value of the bit to be set or cleared in
the flag word when the option is recognized.
The bit is set when the option is discovered,
but cleared if the option name was preceded
by the letters
.Dq no .
The
.Dv m_inverse
flag causes these two operations to be reversed.
.It Fa m_altloc
the bit should be set or cleared in
.Dv altflagp
rather than
.Dv flagp .
.El
.Pp
Each of the user visible
.Dv MNT_
flags has a corresponding
.Dv MOPT_
macro which defines an appropriate
.Li "struct mntopt"
entry.
To simplify the program interface and ensure consistency across all
programs, a general purpose macro,
.Dv MOPT_STDOPTS ,
is defined which
contains an entry for all the generic VFS options.
In addition, the macros
.Dv MOPT_FORCE
and
.Dv MOPT_UPDATE
exist to enable the
.Dv MNT_FORCE
and
.Dv MNT_UPDATE
flags to be set.
Finally, the table must be terminated by an entry with a NULL
first element.
.Sh EXAMPLES
Most commands will use the standard option set.
Local filesystems which support the
.Dv MNT_UPDATE
flag, would also have an
.Dv MOPT_UPDATE
entry.
This can be declared and used as follows:
.Bd -literal
#include "mntopts.h"
struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_UPDATE,
{ NULL }
};
...
mntflags = 0;
...
getmntopts(options, mopts, &mntflags)
...
.Ed
.Sh DIAGNOSTICS
The
.Nm getmntopts
function displays an error message and exits if an
unrecognized option is encountered.
.Sh SEE ALSO
.Xr err 3 ,
.Xr mount 8
.Sh HISTORY
The
.Fn getmntopts
function appeared in
.Bx 4.4 .