getmntopts.c revision 1.1 1 1.1 jdolecek /* $NetBSD: getmntopts.c,v 1.1 2003/03/22 12:44:04 jdolecek Exp $ */
2 1.1 jdolecek
3 1.1 jdolecek /*-
4 1.1 jdolecek * Copyright (c) 1994
5 1.1 jdolecek * The Regents of the University of California. All rights reserved.
6 1.1 jdolecek *
7 1.1 jdolecek * Redistribution and use in source and binary forms, with or without
8 1.1 jdolecek * modification, are permitted provided that the following conditions
9 1.1 jdolecek * are met:
10 1.1 jdolecek * 1. Redistributions of source code must retain the above copyright
11 1.1 jdolecek * notice, this list of conditions and the following disclaimer.
12 1.1 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jdolecek * notice, this list of conditions and the following disclaimer in the
14 1.1 jdolecek * documentation and/or other materials provided with the distribution.
15 1.1 jdolecek * 3. All advertising materials mentioning features or use of this software
16 1.1 jdolecek * must display the following acknowledgement:
17 1.1 jdolecek * This product includes software developed by the University of
18 1.1 jdolecek * California, Berkeley and its contributors.
19 1.1 jdolecek * 4. Neither the name of the University nor the names of its contributors
20 1.1 jdolecek * may be used to endorse or promote products derived from this software
21 1.1 jdolecek * without specific prior written permission.
22 1.1 jdolecek *
23 1.1 jdolecek * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 jdolecek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 jdolecek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 jdolecek * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 jdolecek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 jdolecek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 jdolecek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 jdolecek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 jdolecek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 jdolecek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 jdolecek * SUCH DAMAGE.
34 1.1 jdolecek */
35 1.1 jdolecek
36 1.1 jdolecek #include <sys/cdefs.h>
37 1.1 jdolecek #ifndef lint
38 1.1 jdolecek #if 0
39 1.1 jdolecek static char sccsid[] = "@(#)getmntopts.c 8.3 (Berkeley) 3/29/95";
40 1.1 jdolecek #else
41 1.1 jdolecek __RCSID("$NetBSD: getmntopts.c,v 1.1 2003/03/22 12:44:04 jdolecek Exp $");
42 1.1 jdolecek #endif
43 1.1 jdolecek #endif /* not lint */
44 1.1 jdolecek
45 1.1 jdolecek #include <sys/param.h>
46 1.1 jdolecek #include <sys/mount.h>
47 1.1 jdolecek
48 1.1 jdolecek #include <err.h>
49 1.1 jdolecek #include <errno.h>
50 1.1 jdolecek #include <fstab.h>
51 1.1 jdolecek #include <stdlib.h>
52 1.1 jdolecek #include <string.h>
53 1.1 jdolecek
54 1.1 jdolecek #include <mntopts.h>
55 1.1 jdolecek
56 1.1 jdolecek int getmnt_silent = 0;
57 1.1 jdolecek
58 1.1 jdolecek void
59 1.1 jdolecek getmntopts(options, m0, flagp, altflagp)
60 1.1 jdolecek const char *options;
61 1.1 jdolecek const struct mntopt *m0;
62 1.1 jdolecek int *flagp;
63 1.1 jdolecek int *altflagp;
64 1.1 jdolecek {
65 1.1 jdolecek const struct mntopt *m;
66 1.1 jdolecek int negative;
67 1.1 jdolecek char *opt, *optbuf, *p;
68 1.1 jdolecek int *thisflagp;
69 1.1 jdolecek
70 1.1 jdolecek /* Copy option string, since it is about to be torn asunder... */
71 1.1 jdolecek if ((optbuf = strdup(options)) == NULL)
72 1.1 jdolecek err(1, NULL);
73 1.1 jdolecek
74 1.1 jdolecek for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
75 1.1 jdolecek /* Check for "no" prefix. */
76 1.1 jdolecek if (opt[0] == 'n' && opt[1] == 'o') {
77 1.1 jdolecek negative = 1;
78 1.1 jdolecek opt += 2;
79 1.1 jdolecek } else
80 1.1 jdolecek negative = 0;
81 1.1 jdolecek
82 1.1 jdolecek /*
83 1.1 jdolecek * for options with assignments in them (ie. quotas)
84 1.1 jdolecek * ignore the assignment as it's handled elsewhere
85 1.1 jdolecek */
86 1.1 jdolecek p = strchr(opt, '=');
87 1.1 jdolecek if (p)
88 1.1 jdolecek *p = '\0';
89 1.1 jdolecek
90 1.1 jdolecek /* Scan option table. */
91 1.1 jdolecek for (m = m0; m->m_option != NULL; ++m)
92 1.1 jdolecek if (strcasecmp(opt, m->m_option) == 0)
93 1.1 jdolecek break;
94 1.1 jdolecek
95 1.1 jdolecek /* Save flag, or fail if option is not recognised. */
96 1.1 jdolecek if (m->m_option) {
97 1.1 jdolecek thisflagp = m->m_altloc ? altflagp : flagp;
98 1.1 jdolecek if (negative == m->m_inverse)
99 1.1 jdolecek *thisflagp |= m->m_flag;
100 1.1 jdolecek else
101 1.1 jdolecek *thisflagp &= ~m->m_flag;
102 1.1 jdolecek } else if (!getmnt_silent) {
103 1.1 jdolecek errx(1, "-o %s: option not supported", opt);
104 1.1 jdolecek }
105 1.1 jdolecek }
106 1.1 jdolecek
107 1.1 jdolecek free(optbuf);
108 1.1 jdolecek }
109