xref: /original-bsd/sbin/mount/getmntopts.c (revision e66e06db)
1 /*-
2  * Copyright (c) 1994
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)getmntopts.c	8.1 (Berkeley) 03/27/94";
10 #endif /* not lint */
11 
12 #include <sys/param.h>
13 #include <sys/mount.h>
14 
15 #include <err.h>
16 #include <errno.h>
17 #include <fstab.h>
18 #include <stdlib.h>
19 #include <string.h>
20 
21 #include "mntopts.h"
22 
23 void
24 getmntopts(options, m0, flagp)
25 	const char *options;
26 	const struct mntopt *m0;
27 	int *flagp;
28 {
29 	const struct mntopt *m;
30 	int negative;
31 	char *opt, *optbuf;
32 
33 	/* Copy option string, since it is about to be torn asunder... */
34 	if ((optbuf = strdup(options)) == NULL)
35 		err(1, NULL);
36 
37 	for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
38 		/* Check for "no" prefix. */
39 		if (opt[0] == 'n' && opt[1] == 'o') {
40 			negative = 1;
41 			opt += 2;
42 		} else
43 			negative = 0;
44 
45 		/* Scan option table. */
46 		for (m = m0; m->m_option != NULL; ++m)
47 			if (strcasecmp(opt, m->m_option) == 0)
48 				break;
49 
50 		/* Save flag, or fail if option is not recognised. */
51 		if (m->m_option) {
52 			if (negative == m->m_inverse)
53 				*flagp |= m->m_flag;
54 			else
55 				*flagp &= ~m->m_flag;
56 		} else
57 			errx(1, "-o %s: option not supported", opt);
58 	}
59 
60 	free(optbuf);
61 }
62