2010-08-24 16:05:01 +04:00
|
|
|
.\" $NetBSD: getmntopts.3,v 1.12 2010/08/24 12:05:01 christos Exp $
|
1995-03-18 17:54:19 +03:00
|
|
|
.\"
|
1994-06-08 22:57:30 +04:00
|
|
|
.\" Copyright (c) 1994
|
|
|
|
.\" The Regents of the University of California. All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
2003-08-07 20:42:00 +04:00
|
|
|
.\" 3. Neither the name of the University nor the names of its contributors
|
1994-06-08 22:57:30 +04:00
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
1997-09-16 16:22:39 +04:00
|
|
|
.\" @(#)getmntopts.3 8.3 (Berkeley) 3/30/95
|
1994-06-08 22:57:30 +04:00
|
|
|
.\"
|
2010-05-04 11:58:28 +04:00
|
|
|
.Dd May 4, 2010
|
1994-06-08 22:57:30 +04:00
|
|
|
.Dt GETMNTOPTS 3
|
2001-06-05 15:22:41 +04:00
|
|
|
.Os
|
1994-06-08 22:57:30 +04:00
|
|
|
.Sh NAME
|
|
|
|
.Nm getmntopts
|
|
|
|
.Nd scan mount options
|
2003-03-22 15:43:57 +03:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libutil
|
1994-06-08 22:57:30 +04:00
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In mntopts.h
|
2003-04-11 21:36:57 +04:00
|
|
|
.Ft mntoptparse_t
|
2003-03-22 15:43:57 +03:00
|
|
|
.Fn getmntopts "const char *options" "const struct mntopt *mopts" "int *flagp" "int *altflagp"
|
2003-04-11 21:36:57 +04:00
|
|
|
.Ft const char *
|
|
|
|
.Fn getmntoptstr "mntoptparse_t mp" "const char *opt"
|
|
|
|
.Ft long
|
|
|
|
.Fn getmntoptnum "mntoptparse_t mp" "const char *opt"
|
|
|
|
.Ft void
|
|
|
|
.Fn freemntopts "mntoptparse_t mp"
|
1994-06-08 22:57:30 +04:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
2003-03-22 18:46:47 +03:00
|
|
|
.Fn getmntopts
|
1994-06-08 22:57:30 +04:00
|
|
|
function takes a comma separated option list and a list
|
2010-08-24 16:05:01 +04:00
|
|
|
of valid option names, and computes the bitmasks
|
1994-06-08 22:57:30 +04:00
|
|
|
corresponding to the requested set of options.
|
|
|
|
.Pp
|
|
|
|
The string
|
2003-03-22 18:46:47 +03:00
|
|
|
.Ar options
|
1994-06-08 22:57:30 +04:00
|
|
|
is broken down into a sequence of comma separated tokens.
|
|
|
|
Each token is looked up in the table described by
|
2003-03-22 18:46:47 +03:00
|
|
|
.Ar mopts
|
1994-06-08 22:57:30 +04:00
|
|
|
and the bits in
|
1997-09-16 16:22:39 +04:00
|
|
|
the word referenced by either
|
2003-03-22 18:46:47 +03:00
|
|
|
.Ar flagp
|
1997-09-16 16:22:39 +04:00
|
|
|
or
|
2003-03-22 18:46:47 +03:00
|
|
|
.Ar altflagp
|
1997-09-16 16:22:39 +04:00
|
|
|
(depending on the
|
|
|
|
.Dv m_altloc
|
|
|
|
field of the option's table entry)
|
1994-06-08 22:57:30 +04:00
|
|
|
are updated.
|
1997-09-16 16:22:39 +04:00
|
|
|
The flag words are not initialized by
|
2003-04-16 16:53:37 +04:00
|
|
|
.Fn getmntopts .
|
1994-06-08 22:57:30 +04:00
|
|
|
The table,
|
2003-03-22 18:46:47 +03:00
|
|
|
.Ar mopts ,
|
1994-06-08 22:57:30 +04:00
|
|
|
has the following format:
|
|
|
|
.Bd -literal
|
|
|
|
struct mntopt {
|
2003-03-22 15:43:57 +03:00
|
|
|
const char *m_option; /* option name */
|
2007-08-27 02:53:01 +04:00
|
|
|
int m_inverse; /* negative option, e.g., "dev" */
|
2003-04-16 16:53:37 +04:00
|
|
|
int m_flag; /* bit to set, e.g., MNT_RDONLY */
|
2007-08-27 02:53:01 +04:00
|
|
|
int m_altloc; /* use altflagp rather than flagp */
|
1994-06-08 22:57:30 +04:00
|
|
|
};
|
|
|
|
.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
|
2003-03-22 18:46:47 +03:00
|
|
|
.Fn getmntopts
|
|
|
|
that the name has the inverse meaning of the bit.
|
1994-06-08 22:57:30 +04:00
|
|
|
For example,
|
|
|
|
.Dq suid
|
2003-03-22 18:46:47 +03:00
|
|
|
is the string, whereas the mount flag is
|
1994-06-08 22:57:30 +04:00
|
|
|
.Dv MNT_NOSUID .
|
|
|
|
In this case, the sense of the string and the flag
|
|
|
|
are inverted, so the
|
2003-03-22 18:46:47 +03:00
|
|
|
.Fa m_inverse
|
1994-06-08 22:57:30 +04:00
|
|
|
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
|
2003-03-22 18:46:47 +03:00
|
|
|
.Fa m_inverse
|
1994-06-08 22:57:30 +04:00
|
|
|
flag causes these two operations to be reversed.
|
1997-09-16 16:22:39 +04:00
|
|
|
.It Fa m_altloc
|
|
|
|
the bit should be set or cleared in
|
2003-03-22 18:46:47 +03:00
|
|
|
.Ar altflagp
|
1997-09-16 16:22:39 +04:00
|
|
|
rather than
|
2003-03-22 18:46:47 +03:00
|
|
|
.Ar flagp .
|
1994-06-08 22:57:30 +04:00
|
|
|
.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 ,
|
2003-03-22 18:46:47 +03:00
|
|
|
is defined which contains an entry for all the generic VFS options.
|
1994-06-08 22:57:30 +04:00
|
|
|
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.
|
2003-03-22 18:46:47 +03:00
|
|
|
Finally, the table must be terminated by an entry with a
|
|
|
|
.Dv NULL
|
1994-06-08 22:57:30 +04:00
|
|
|
first element.
|
2003-04-11 21:36:57 +04:00
|
|
|
.Pp
|
2010-08-24 16:05:01 +04:00
|
|
|
.Fn getmntopts
|
|
|
|
returns a
|
|
|
|
.Li "mntoptparse_t"
|
|
|
|
handle that can be used in subsequent
|
|
|
|
.Fn getmntoptstr
|
|
|
|
and
|
|
|
|
.Fn getmntoptnum
|
|
|
|
calls to fetch a value for an option and that must be freed with a call
|
|
|
|
to
|
|
|
|
.Fn freemntopts .
|
|
|
|
If an error occurred, then if the external integer value
|
|
|
|
.Va getmnt_silent
|
|
|
|
is zero then
|
|
|
|
.Fn getmntopts
|
|
|
|
prints an error message and exits;
|
|
|
|
if
|
|
|
|
.Va getmnt_silent
|
|
|
|
is non-zero then
|
|
|
|
.Fn getmntopts
|
|
|
|
returns
|
|
|
|
.Dv NULL .
|
|
|
|
.Pp
|
2003-04-11 21:36:57 +04:00
|
|
|
The
|
|
|
|
.Fn getmntoptstr
|
|
|
|
function returns the string value of the named option, if such a value
|
2010-08-24 16:05:01 +04:00
|
|
|
was set in the option string.
|
|
|
|
If the value was not set, then if the external integer value
|
|
|
|
.Va getmnt_silent
|
|
|
|
is zero then
|
|
|
|
.Fn getmntoptstr
|
|
|
|
prints an error message and exits;
|
|
|
|
if
|
|
|
|
.Va getmnt_silent
|
|
|
|
is non-zero then
|
|
|
|
.Fn getmntoptstr
|
|
|
|
returns
|
|
|
|
.Dv NULL .
|
2003-04-11 21:36:57 +04:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn getmntoptnum
|
2010-08-24 16:05:01 +04:00
|
|
|
returns the long value of the named option, if such a value was set in the
|
2003-04-16 16:53:37 +04:00
|
|
|
option string.
|
2010-08-24 16:05:01 +04:00
|
|
|
If the value was not set, or could not be converted from a string to a
|
|
|
|
long, then if the external integer value
|
|
|
|
.Va getmnt_silent
|
|
|
|
is zero then
|
|
|
|
.Fn getmntoptnum
|
|
|
|
prints an error message and exits;
|
|
|
|
if
|
|
|
|
.Va getmnt_silent
|
|
|
|
is non-zero then
|
|
|
|
.Fn getmntoptnum
|
|
|
|
returns \-1.
|
2003-04-11 21:36:57 +04:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn freemntopts
|
|
|
|
frees the storage used by
|
|
|
|
.Fn getmntopts .
|
2009-05-05 00:43:48 +04:00
|
|
|
.Sh RETURN VALUES
|
|
|
|
.Fn getmntopts
|
|
|
|
returns
|
|
|
|
.Dv NULL
|
|
|
|
if an error occurred.
|
|
|
|
Note that some bits may already have been set in
|
|
|
|
.Va flagp
|
|
|
|
and
|
|
|
|
.Va altflagp
|
|
|
|
even if
|
|
|
|
.Dv NULL
|
|
|
|
is returned.
|
|
|
|
.Fn getmntoptstr
|
|
|
|
returns
|
|
|
|
.Dv NULL
|
2010-08-24 16:05:01 +04:00
|
|
|
if an error occurred.
|
2009-05-05 00:43:48 +04:00
|
|
|
.Fn getmntoptnum
|
|
|
|
returns \-1 if an error occurred.
|
1994-06-08 22:57:30 +04:00
|
|
|
.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:
|
2010-05-04 11:58:28 +04:00
|
|
|
.Bd -literal -offset indent
|
2003-03-22 18:46:47 +03:00
|
|
|
#include \*[Lt]mntopts.h\*[Gt]
|
1994-06-08 22:57:30 +04:00
|
|
|
|
2003-03-22 15:43:57 +03:00
|
|
|
static const struct mntopt mopts[] = {
|
1994-06-08 22:57:30 +04:00
|
|
|
MOPT_STDOPTS,
|
|
|
|
MOPT_UPDATE,
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2009-07-14 22:56:14 +04:00
|
|
|
\&...
|
2010-05-04 11:58:28 +04:00
|
|
|
|
2003-04-11 21:36:57 +04:00
|
|
|
long val;
|
|
|
|
mntoptparse_t mp;
|
2010-05-04 11:58:28 +04:00
|
|
|
mntflags = mntaltflags = 0;
|
|
|
|
|
2009-07-14 22:56:14 +04:00
|
|
|
\&...
|
2010-05-04 11:58:28 +04:00
|
|
|
|
|
|
|
mp = getmntopts(options, mopts, \*[Am]mntflags, \*[Am]mntaltflags);
|
|
|
|
|
|
|
|
if (mp == NULL)
|
|
|
|
err(EXIT_FAILURE, "getmntopts");
|
|
|
|
|
2009-07-14 22:56:14 +04:00
|
|
|
\&...
|
2010-05-04 11:58:28 +04:00
|
|
|
|
2003-04-11 21:36:57 +04:00
|
|
|
val = getmntoptnum(mp, "rsize");
|
|
|
|
freemntopts(mp);
|
1994-06-08 22:57:30 +04:00
|
|
|
.Ed
|
|
|
|
.Sh DIAGNOSTICS
|
1997-09-16 16:22:39 +04:00
|
|
|
If the external integer variable
|
2003-04-16 16:53:37 +04:00
|
|
|
.Va getmnt_silent
|
2007-08-27 02:53:01 +04:00
|
|
|
is zero then the
|
2010-08-24 16:05:01 +04:00
|
|
|
.Fn getmntopts ,
|
|
|
|
.Fn getmntoptstr ,
|
|
|
|
and
|
|
|
|
.Fn getmntoptnum
|
|
|
|
functions display an error message and exit if an error occurred.
|
1997-09-16 16:22:39 +04:00
|
|
|
By default
|
2003-04-16 16:53:37 +04:00
|
|
|
.Va getmnt_silent
|
1997-09-16 16:22:39 +04:00
|
|
|
is zero.
|
1994-06-08 22:57:30 +04:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr err 3 ,
|
|
|
|
.Xr mount 8
|
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Fn getmntopts
|
2001-11-16 13:25:42 +03:00
|
|
|
function appeared in
|
1994-06-08 22:57:30 +04:00
|
|
|
.Bx 4.4 .
|
2003-04-11 21:36:57 +04:00
|
|
|
It was moved to the utilities library and enhanced to retrieve option
|
|
|
|
values in
|
2003-03-22 15:43:57 +03:00
|
|
|
.Nx 2.0 .
|