/etc/mail: Install 4 sample mailer.conf files
[dragonfly.git] / lib / libutil / getmntopts.3
1 .\" Copyright (c) 1994
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)getmntopts.3        8.3 (Berkeley) 3/30/95
29 .\" $FreeBSD: src/sbin/mount/getmntopts.3,v 1.6.2.4 2003/02/23 20:17:15 trhodes Exp $
30 .\"
31 .Dd June 8, 2012
32 .Dt GETMNTOPTS 3
33 .Os
34 .Sh NAME
35 .Nm getmntopts
36 .Nd scan mount options
37 .Sh LIBRARY
38 .Lb libutil
39 .Sh SYNOPSIS
40 .In mntopts.h
41 .Ft void
42 .Fn getmntopts "const char *options" "const struct mntopt *mopts" "int *flagp" "int *altflagp"
43 .Sh DESCRIPTION
44 The
45 .Fn getmntopts
46 function takes a comma separated option list and a list
47 of valid option names, and computes the bitmask
48 corresponding to the requested set of options.
49 .Pp
50 The string
51 .Fa options
52 is broken down into a sequence of comma separated tokens.
53 Each token is looked up in the table described by
54 .Fa mopts
55 and the bits in
56 the word referenced by either
57 .Fa flagp
58 or
59 .Fa altflagp
60 (depending on the
61 .Va m_altloc
62 field of the option's table entry)
63 are updated.
64 The flag words are not initialized by
65 .Fn getmntopts .
66 The table,
67 .Fa mopts ,
68 has the following format:
69 .Bd -literal
70 struct mntopt {
71         char *m_option;         /* option name */
72         int m_inverse;          /* is this a negative option, e.g. "dev" */
73         int m_flag;             /* bit to set, e.g. MNT_RDONLY */
74         int m_altloc;           /* non-zero to use altflagp rather than flagp */
75 };
76 .Ed
77 .Pp
78 The members of this structure are:
79 .Bl -tag -width m_inverse
80 .It Va m_option
81 the option name,
82 for example
83 .Dq Li suid .
84 .It Va m_inverse
85 tells
86 .Fn getmntopts
87 that the name has the inverse meaning of the
88 bit.
89 For example,
90 .Dq Li suid
91 is the string, whereas the
92 mount flag is
93 .Dv MNT_NOSUID .
94 In this case, the sense of the string and the flag
95 are inverted, so the
96 .Va m_inverse
97 flag should be set.
98 .It Va m_flag
99 the value of the bit to be set or cleared in
100 the flag word when the option is recognized.
101 The bit is set when the option is discovered,
102 but cleared if the option name was preceded
103 by the letters
104 .Dq Li no .
105 The
106 .Va m_inverse
107 flag causes these two operations to be reversed.
108 .It Va m_altloc
109 the bit should be set or cleared in
110 .Fa altflagp
111 rather than
112 .Fa flagp .
113 .El
114 .Pp
115 Each of the user visible
116 .Dv MNT_
117 flags has a corresponding
118 .Dv MOPT_
119 macro which defines an appropriate
120 .Vt "struct mntopt"
121 entry.
122 To simplify the program interface and ensure consistency across all
123 programs, a general purpose macro,
124 .Dv MOPT_STDOPTS ,
125 is defined which
126 contains an entry for all the generic VFS options.
127 In addition, the macros
128 .Dv MOPT_FORCE
129 and
130 .Dv MOPT_UPDATE
131 exist to enable the
132 .Dv MNT_FORCE
133 and
134 .Dv MNT_UPDATE
135 flags to be set.
136 Finally, the table must be terminated by an entry with a
137 .Dv NULL
138 first element.
139 .Sh EXAMPLES
140 Most commands will use the standard option set.
141 Local file systems which support the
142 .Dv MNT_UPDATE
143 flag, would also have an
144 .Dv MOPT_UPDATE
145 entry.
146 This can be declared and used as follows:
147 .Bd -literal
148 #include <mntopts.h>
149
150 struct mntopt mopts[] = {
151         MOPT_STDOPTS,
152         MOPT_UPDATE,
153         { NULL }
154 };
155
156         ...
157         mntflags = mntaltflags = 0;
158         ...
159         getmntopts(options, mopts, &mntflags, &mntaltflags);
160         ...
161 .Ed
162 .Sh DIAGNOSTICS
163 If the external integer variable
164 .Va getmnt_silent
165 is non-zero then the
166 .Fn getmntopts
167 function displays an error message and exits if an
168 unrecognized option is encountered.
169 By default
170 .Va getmnt_silent
171 is zero.
172 .Sh SEE ALSO
173 .Xr err 3 ,
174 .Xr mount 8
175 .Sh HISTORY
176 The
177 .Fn getmntopts
178 function appeared in
179 .Bx 4.4 .