1 .\" $NetBSD: getmntopts.3,v 1.12 2010/08/24 12:05:01 christos Exp $
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)getmntopts.3 8.3 (Berkeley) 3/30/95
37 .Nd scan mount options
43 .Fn getmntopts "const char *options" "const struct mntopt *mopts" "int *flagp" "int *altflagp"
45 .Fn getmntoptstr "mntoptparse_t mp" "const char *opt"
47 .Fn getmntoptnum "mntoptparse_t mp" "const char *opt"
49 .Fn freemntopts "mntoptparse_t mp"
53 function takes a comma separated option list and a list
54 of valid option names, and computes the bitmasks
55 corresponding to the requested set of options.
59 is broken down into a sequence of comma separated tokens.
60 Each token is looked up in the table described by
63 the word referenced by either
69 field of the option's table entry)
71 The flag words are not initialized by
75 has the following format:
78 const char *m_option; /* option name */
79 int m_inverse; /* negative option, e.g., "dev" */
80 int m_flag; /* bit to set, e.g., MNT_RDONLY */
81 int m_altloc; /* use altflagp rather than flagp */
85 The members of this structure are:
86 .Bl -tag -width m_inverse
94 that the name has the inverse meaning of the bit.
97 is the string, whereas the mount flag is
99 In this case, the sense of the string and the flag
104 the value of the bit to be set or cleared in
105 the flag word when the option is recognized.
106 The bit is set when the option is discovered,
107 but cleared if the option name was preceded
112 flag causes these two operations to be reversed.
114 the bit should be set or cleared in
120 Each of the user visible
122 flags has a corresponding
124 macro which defines an appropriate
127 To simplify the program interface and ensure consistency across all
128 programs, a general purpose macro,
130 is defined which contains an entry for all the generic VFS options:
131 .Bd -literal -offset indent
145 MOPT_IGNORE_OWNERSHIP,
150 In addition, the macros
159 Finally, the table must be terminated by an entry with a
166 handle that can be used in subsequent
170 calls to fetch a value for an option and that must be freed with a call
173 If an error occurred, then if the external integer value
177 prints an error message and exits;
187 function returns the string value of the named option, if such a value
188 was set in the option string.
189 If the value was not set, then if the external integer value
193 prints an error message and exits;
203 returns the long value of the named option, if such a value was set in the
205 If the value was not set, or could not be converted from a string to a
206 long, then if the external integer value
210 prints an error message and exits;
219 frees the storage used by
225 if an error occurred.
226 Note that some bits may already have been set in
236 if an error occurred.
238 returns \-1 if an error occurred.
240 Most commands will use the standard option set.
241 Local filesystems which support the
243 flag, would also have an
246 This can be declared and used as follows:
247 .Bd -literal -offset indent
248 #include \*[Lt]mntopts.h\*[Gt]
250 static const struct mntopt mopts[] = {
260 mntflags = mntaltflags = 0;
264 mp = getmntopts(options, mopts, \*[Am]mntflags, \*[Am]mntaltflags);
267 err(EXIT_FAILURE, "getmntopts");
271 val = getmntoptnum(mp, "rsize");
275 If the external integer variable
282 functions display an error message and exit if an error occurred.
294 It was moved to the utilities library and enhanced to retrieve option