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