[BACK]Return to getmntopts.3 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libutil

Annotation of src/lib/libutil/getmntopts.3, Revision 1.14

1.14    ! wiz         1: .\"    $NetBSD: getmntopts.3,v 1.13 2017/03/30 19:41:41 abhinav Exp $
1.1       jdolecek    2: .\"
                      3: .\" Copyright (c) 1994
                      4: .\"    The Regents of the University of California.  All rights reserved.
                      5: .\"
                      6: .\" Redistribution and use in source and binary forms, with or without
                      7: .\" modification, are permitted provided that the following conditions
                      8: .\" are met:
                      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.
1.6       agc        14: .\" 3. Neither the name of the University nor the names of its contributors
1.1       jdolecek   15: .\"    may be used to endorse or promote products derived from this software
                     16: .\"    without specific prior written permission.
                     17: .\"
                     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
                     28: .\" SUCH DAMAGE.
                     29: .\"
                     30: .\"    @(#)getmntopts.3        8.3 (Berkeley) 3/30/95
                     31: .\"
1.11      jruoho     32: .Dd May 4, 2010
1.1       jdolecek   33: .Dt GETMNTOPTS 3
                     34: .Os
                     35: .Sh NAME
1.13      abhinav    36: .Nm getmntopts ,
                     37: .Nm getmntoptstr ,
                     38: .Nm getmntoptnum ,
                     39: .Nm freemntopts
1.1       jdolecek   40: .Nd scan mount options
                     41: .Sh LIBRARY
                     42: .Lb libutil
                     43: .Sh SYNOPSIS
1.5       wiz        44: .In mntopts.h
1.3       christos   45: .Ft mntoptparse_t
                     46: .Fn getmntopts "const char *options" "const struct mntopt *mopts" "int *flagp" "int *altflagp"
                     47: .Ft const char *
                     48: .Fn getmntoptstr "mntoptparse_t mp" "const char *opt"
                     49: .Ft long
                     50: .Fn getmntoptnum "mntoptparse_t mp" "const char *opt"
1.1       jdolecek   51: .Ft void
1.3       christos   52: .Fn freemntopts "mntoptparse_t mp"
1.1       jdolecek   53: .Sh DESCRIPTION
                     54: The
1.2       wiz        55: .Fn getmntopts
1.1       jdolecek   56: function takes a comma separated option list and a list
1.12      christos   57: of valid option names, and computes the bitmasks
1.1       jdolecek   58: corresponding to the requested set of options.
                     59: .Pp
                     60: The string
1.2       wiz        61: .Ar options
1.1       jdolecek   62: is broken down into a sequence of comma separated tokens.
                     63: Each token is looked up in the table described by
1.2       wiz        64: .Ar mopts
1.1       jdolecek   65: and the bits in
                     66: the word referenced by either
1.2       wiz        67: .Ar flagp
1.1       jdolecek   68: or
1.2       wiz        69: .Ar altflagp
1.1       jdolecek   70: (depending on the
                     71: .Dv m_altloc
                     72: field of the option's table entry)
                     73: are updated.
                     74: The flag words are not initialized by
1.4       wiz        75: .Fn getmntopts .
1.1       jdolecek   76: The table,
1.2       wiz        77: .Ar mopts ,
1.1       jdolecek   78: has the following format:
                     79: .Bd -literal
                     80: struct mntopt {
                     81:        const char *m_option;   /* option name */
1.8       pooka      82:        int m_inverse;          /* negative option, e.g., "dev" */
1.4       wiz        83:        int m_flag;             /* bit to set, e.g., MNT_RDONLY */
1.8       pooka      84:        int m_altloc;           /* use altflagp rather than flagp */
1.1       jdolecek   85: };
                     86: .Ed
                     87: .Pp
                     88: The members of this structure are:
                     89: .Bl -tag -width m_inverse
                     90: .It Fa m_option
                     91: the option name,
                     92: for example
                     93: .Dq suid .
                     94: .It Fa m_inverse
                     95: tells
1.2       wiz        96: .Fn getmntopts
                     97: that the name has the inverse meaning of the bit.
1.1       jdolecek   98: For example,
                     99: .Dq suid
1.2       wiz       100: is the string, whereas the mount flag is
1.1       jdolecek  101: .Dv MNT_NOSUID .
                    102: In this case, the sense of the string and the flag
                    103: are inverted, so the
1.2       wiz       104: .Fa m_inverse
1.1       jdolecek  105: flag should be set.
                    106: .It Fa m_flag
                    107: the value of the bit to be set or cleared in
                    108: the flag word when the option is recognized.
                    109: The bit is set when the option is discovered,
                    110: but cleared if the option name was preceded
                    111: by the letters
                    112: .Dq no .
                    113: The
1.2       wiz       114: .Fa m_inverse
1.1       jdolecek  115: flag causes these two operations to be reversed.
                    116: .It Fa m_altloc
                    117: the bit should be set or cleared in
1.2       wiz       118: .Ar altflagp
1.1       jdolecek  119: rather than
1.2       wiz       120: .Ar flagp .
1.1       jdolecek  121: .El
                    122: .Pp
                    123: Each of the user visible
                    124: .Dv MNT_
                    125: flags has a corresponding
                    126: .Dv MOPT_
                    127: macro which defines an appropriate
                    128: .Li "struct mntopt"
                    129: entry.
                    130: To simplify the program interface and ensure consistency across all
                    131: programs, a general purpose macro,
                    132: .Dv MOPT_STDOPTS ,
1.2       wiz       133: is defined which contains an entry for all the generic VFS options.
1.1       jdolecek  134: In addition, the macros
                    135: .Dv MOPT_FORCE
                    136: and
                    137: .Dv MOPT_UPDATE
                    138: exist to enable the
                    139: .Dv MNT_FORCE
                    140: and
                    141: .Dv MNT_UPDATE
                    142: flags to be set.
1.2       wiz       143: Finally, the table must be terminated by an entry with a
                    144: .Dv NULL
1.1       jdolecek  145: first element.
1.3       christos  146: .Pp
1.12      christos  147: .Fn getmntopts
                    148: returns a
                    149: .Li "mntoptparse_t"
                    150: handle that can be used in subsequent
                    151: .Fn getmntoptstr
                    152: and
                    153: .Fn getmntoptnum
                    154: calls to fetch a value for an option and that must be freed with a call
                    155: to
                    156: .Fn freemntopts .
                    157: If an error occurred, then if the external integer value
                    158: .Va getmnt_silent
                    159: is zero then
                    160: .Fn getmntopts
                    161: prints an error message and exits;
                    162: if
                    163: .Va getmnt_silent
                    164: is non-zero then
                    165: .Fn getmntopts
                    166: returns
                    167: .Dv NULL .
                    168: .Pp
1.3       christos  169: The
                    170: .Fn getmntoptstr
                    171: function returns the string value of the named option, if such a value
1.12      christos  172: was set in the option string.
                    173: If the value was not set, then if the external integer value
                    174: .Va getmnt_silent
                    175: is zero then
                    176: .Fn getmntoptstr
                    177: prints an error message and exits;
                    178: if
                    179: .Va getmnt_silent
                    180: is non-zero then
                    181: .Fn getmntoptstr
                    182: returns
                    183: .Dv NULL .
1.3       christos  184: .Pp
                    185: The
                    186: .Fn getmntoptnum
1.13      abhinav   187: function returns the long value of the named option, if such a value was set in the
1.4       wiz       188: option string.
1.12      christos  189: If the value was not set, or could not be converted from a string to a
                    190: long, then if the external integer value
                    191: .Va getmnt_silent
                    192: is zero then
                    193: .Fn getmntoptnum
                    194: prints an error message and exits;
                    195: if
                    196: .Va getmnt_silent
                    197: is non-zero then
                    198: .Fn getmntoptnum
                    199: returns \-1.
1.3       christos  200: .Pp
                    201: The
                    202: .Fn freemntopts
1.13      abhinav   203: function frees the storage used by
1.3       christos  204: .Fn getmntopts .
1.9       wiz       205: .Sh RETURN VALUES
                    206: .Fn getmntopts
                    207: returns
                    208: .Dv NULL
                    209: if an error occurred.
                    210: Note that some bits may already have been set in
                    211: .Va flagp
                    212: and
                    213: .Va altflagp
                    214: even if
                    215: .Dv NULL
                    216: is returned.
                    217: .Fn getmntoptstr
                    218: returns
                    219: .Dv NULL
1.12      christos  220: if an error occurred.
1.9       wiz       221: .Fn getmntoptnum
                    222: returns \-1 if an error occurred.
1.1       jdolecek  223: .Sh EXAMPLES
                    224: Most commands will use the standard option set.
                    225: Local filesystems which support the
                    226: .Dv MNT_UPDATE
                    227: flag, would also have an
                    228: .Dv MOPT_UPDATE
                    229: entry.
                    230: This can be declared and used as follows:
1.11      jruoho    231: .Bd -literal -offset indent
1.14    ! wiz       232: #include <mntopts.h>
1.1       jdolecek  233:
                    234: static const struct mntopt mopts[] = {
                    235:        MOPT_STDOPTS,
                    236:        MOPT_UPDATE,
                    237:        { NULL }
                    238: };
                    239:
1.10      joerg     240: \&...
1.11      jruoho    241:
1.3       christos  242: long val;
1.11      jruoho    243: mntoptparse_t mp;
1.3       christos  244: mntflags = mntaltflags = 0;
1.11      jruoho    245:
1.10      joerg     246: \&...
1.11      jruoho    247:
1.14    ! wiz       248: mp = getmntopts(options, mopts, &mntflags, &mntaltflags);
1.11      jruoho    249:
                    250: if (mp == NULL)
                    251:        err(EXIT_FAILURE, "getmntopts");
                    252:
1.10      joerg     253: \&...
1.11      jruoho    254:
1.3       christos  255: val = getmntoptnum(mp, "rsize");
                    256: freemntopts(mp);
1.1       jdolecek  257: .Ed
                    258: .Sh DIAGNOSTICS
                    259: If the external integer variable
1.4       wiz       260: .Va getmnt_silent
1.8       pooka     261: is zero then the
1.12      christos  262: .Fn getmntopts ,
                    263: .Fn getmntoptstr ,
                    264: and
                    265: .Fn getmntoptnum
                    266: functions display an error message and exit if an error occurred.
1.1       jdolecek  267: By default
1.4       wiz       268: .Va getmnt_silent
1.1       jdolecek  269: is zero.
                    270: .Sh SEE ALSO
                    271: .Xr err 3 ,
                    272: .Xr mount 8
                    273: .Sh HISTORY
                    274: The
                    275: .Fn getmntopts
                    276: function appeared in
                    277: .Bx 4.4 .
1.3       christos  278: It was moved to the utilities library and enhanced to retrieve option
                    279: values in
1.1       jdolecek  280: .Nx 2.0 .

CVSweb <webmaster@jp.NetBSD.org>