-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetmntopts.3
296 lines (288 loc) · 6.93 KB
/
getmntopts.3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
.\" $NetBSD: getmntopts.3,v 1.12 2010/08/24 12:05:01 christos Exp $
.\"
.\" 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.
.\" 3. Neither the name of the University nor the names of its contributors
.\" 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.
.\"
.\" @(#)getmntopts.3 8.3 (Berkeley) 3/30/95
.\"
.Dd May 4, 2010
.Dt GETMNTOPTS 3
.Os
.Sh NAME
.Nm getmntopts
.Nd scan mount options
.Sh LIBRARY
.Lb libutil
.Sh SYNOPSIS
.In mntopts.h
.Ft mntoptparse_t
.Fn getmntopts "const char *options" "const struct mntopt *mopts" "int *flagp" "int *altflagp"
.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"
.Sh DESCRIPTION
The
.Fn getmntopts
function takes a comma separated option list and a list
of valid option names, and computes the bitmasks
corresponding to the requested set of options.
.Pp
The string
.Ar options
is broken down into a sequence of comma separated tokens.
Each token is looked up in the table described by
.Ar mopts
and the bits in
the word referenced by either
.Ar flagp
or
.Ar altflagp
(depending on the
.Dv m_altloc
field of the option's table entry)
are updated.
The flag words are not initialized by
.Fn getmntopts .
The table,
.Ar mopts ,
has the following format:
.Bd -literal
struct mntopt {
const char *m_option; /* option name */
int m_inverse; /* negative option, e.g., "dev" */
int m_flag; /* bit to set, e.g., MNT_RDONLY */
int m_altloc; /* 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
.Fn 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
.Fa 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
.Fa m_inverse
flag causes these two operations to be reversed.
.It Fa m_altloc
the bit should be set or cleared in
.Ar altflagp
rather than
.Ar 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:
.Bd -literal -offset indent
MOPT_USERQUOTA,
MOPT_GROUPQUOTA,
MOPT_FSTAB_COMPAT,
MOPT_NODEV,
MOPT_NOEXEC,
MOPT_NOSUID,
MOPT_RDONLY,
MOPT_UNION,
MOPT_BROWSE,
MOPT_AUTOMOUNTED,
MOPT_DEFWRITE,
MOPT_NOATIME,
MOPT_PERMISSIONS,
MOPT_IGNORE_OWNERSHIP,
MOPT_QUARANTINE,
MOPT_CPROTECT
.Ed
.Pp
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
.Dv NULL
first element.
.Pp
.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
The
.Fn getmntoptstr
function returns the string value of the named option, if such a value
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 .
.Pp
The
.Fn getmntoptnum
returns the long value of the named option, if such a value was set in the
option string.
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.
.Pp
The
.Fn freemntopts
frees the storage used by
.Fn getmntopts .
.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
if an error occurred.
.Fn getmntoptnum
returns \-1 if an error occurred.
.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 -offset indent
#include \*[Lt]mntopts.h\*[Gt]
static const struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_UPDATE,
{ NULL }
};
\&...
long val;
mntoptparse_t mp;
mntflags = mntaltflags = 0;
\&...
mp = getmntopts(options, mopts, \*[Am]mntflags, \*[Am]mntaltflags);
if (mp == NULL)
err(EXIT_FAILURE, "getmntopts");
\&...
val = getmntoptnum(mp, "rsize");
freemntopts(mp);
.Ed
.Sh DIAGNOSTICS
If the external integer variable
.Va getmnt_silent
is zero then the
.Fn getmntopts ,
.Fn getmntoptstr ,
and
.Fn getmntoptnum
functions display an error message and exit if an error occurred.
By default
.Va getmnt_silent
is zero.
.Sh SEE ALSO
.Xr err 3 ,
.Xr mount 8
.Sh HISTORY
The
.Fn getmntopts
function appeared in
.Bx 4.4 .
It was moved to the utilities library and enhanced to retrieve option
values in
.Nx 2.0 .