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 44The 45.Fn getmntopts 46function takes a comma separated option list and a list 47of valid option names, and computes the bitmask 48corresponding to the requested set of options. 49.Pp 50The string 51.Fa options 52is broken down into a sequence of comma separated tokens. 53Each token is looked up in the table described by 54.Fa mopts 55and the bits in 56the word referenced by either 57.Fa flagp 58or 59.Fa altflagp 60(depending on the 61.Va m_altloc 62field of the option's table entry) 63are updated. 64The flag words are not initialized by 65.Fn getmntopts . 66The table, 67.Fa mopts , 68has the following format: 69.Bd -literal 70struct 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 78The members of this structure are: 79.Bl -tag -width m_inverse 80.It Va m_option 81the option name, 82for example 83.Dq Li suid . 84.It Va m_inverse 85tells 86.Fn getmntopts 87that the name has the inverse meaning of the 88bit. 89For example, 90.Dq Li suid 91is the string, whereas the 92mount flag is 93.Dv MNT_NOSUID . 94In this case, the sense of the string and the flag 95are inverted, so the 96.Va m_inverse 97flag should be set. 98.It Va m_flag 99the value of the bit to be set or cleared in 100the flag word when the option is recognized. 101The bit is set when the option is discovered, 102but cleared if the option name was preceded 103by the letters 104.Dq Li no . 105The 106.Va m_inverse 107flag causes these two operations to be reversed. 108.It Va m_altloc 109the bit should be set or cleared in 110.Fa altflagp 111rather than 112.Fa flagp . 113.El 114.Pp 115Each of the user visible 116.Dv MNT_ 117flags has a corresponding 118.Dv MOPT_ 119macro which defines an appropriate 120.Vt "struct mntopt" 121entry. 122To simplify the program interface and ensure consistency across all 123programs, a general purpose macro, 124.Dv MOPT_STDOPTS , 125is defined which 126contains an entry for all the generic VFS options. 127In addition, the macros 128.Dv MOPT_FORCE 129and 130.Dv MOPT_UPDATE 131exist to enable the 132.Dv MNT_FORCE 133and 134.Dv MNT_UPDATE 135flags to be set. 136Finally, the table must be terminated by an entry with a 137.Dv NULL 138first element. 139.Sh EXAMPLES 140Most commands will use the standard option set. 141Local file systems which support the 142.Dv MNT_UPDATE 143flag, would also have an 144.Dv MOPT_UPDATE 145entry. 146This can be declared and used as follows: 147.Bd -literal 148#include <mntopts.h> 149 150struct 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 163If the external integer variable 164.Va getmnt_silent 165is non-zero then the 166.Fn getmntopts 167function displays an error message and exits if an 168unrecognized option is encountered. 169By default 170.Va getmnt_silent 171is zero. 172.Sh SEE ALSO 173.Xr err 3 , 174.Xr mount 8 175.Sh HISTORY 176The 177.Fn getmntopts 178function appeared in 179.Bx 4.4 . 180