xref: /csrg-svn/sbin/mount/getmntopts.c (revision 68641)
166461Sbostic /*-
266461Sbostic  * Copyright (c) 1994
366461Sbostic  *	The Regents of the University of California.  All rights reserved.
466461Sbostic  *
566461Sbostic  * %sccs.include.redist.c%
666461Sbostic  */
766461Sbostic 
866461Sbostic #ifndef lint
9*68641Smckusick static char sccsid[] = "@(#)getmntopts.c	8.3 (Berkeley) 03/29/95";
1066461Sbostic #endif /* not lint */
1166461Sbostic 
1266461Sbostic #include <sys/param.h>
1366461Sbostic #include <sys/mount.h>
1466461Sbostic 
1566461Sbostic #include <err.h>
1666461Sbostic #include <errno.h>
1766461Sbostic #include <fstab.h>
1866461Sbostic #include <stdlib.h>
1966461Sbostic #include <string.h>
2066461Sbostic 
2166461Sbostic #include "mntopts.h"
2266461Sbostic 
23*68641Smckusick int getmnt_silent = 0;
24*68641Smckusick 
2566461Sbostic void
getmntopts(options,m0,flagp,altflagp)26*68641Smckusick getmntopts(options, m0, flagp, altflagp)
2766461Sbostic 	const char *options;
2866461Sbostic 	const struct mntopt *m0;
2966461Sbostic 	int *flagp;
30*68641Smckusick 	int *altflagp;
3166461Sbostic {
3266461Sbostic 	const struct mntopt *m;
3366461Sbostic 	int negative;
3467442Smckusick 	char *opt, *optbuf, *p;
35*68641Smckusick 	int *thisflagp;
3666461Sbostic 
3766461Sbostic 	/* Copy option string, since it is about to be torn asunder... */
3866461Sbostic 	if ((optbuf = strdup(options)) == NULL)
3966461Sbostic 		err(1, NULL);
4066461Sbostic 
4166461Sbostic 	for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
4266461Sbostic 		/* Check for "no" prefix. */
4366461Sbostic 		if (opt[0] == 'n' && opt[1] == 'o') {
4466461Sbostic 			negative = 1;
4566461Sbostic 			opt += 2;
4666461Sbostic 		} else
4766461Sbostic 			negative = 0;
4866461Sbostic 
4967442Smckusick 		/*
5067442Smckusick 		 * for options with assignments in them (ie. quotas)
5167442Smckusick 		 * ignore the assignment as it's handled elsewhere
5267442Smckusick 		 */
5367442Smckusick 		p = strchr(opt, '=');
5467442Smckusick 		if (p)
5567442Smckusick 			 *p = '\0';
5667442Smckusick 
5766461Sbostic 		/* Scan option table. */
5866461Sbostic 		for (m = m0; m->m_option != NULL; ++m)
5966461Sbostic 			if (strcasecmp(opt, m->m_option) == 0)
6066461Sbostic 				break;
6166461Sbostic 
6266461Sbostic 		/* Save flag, or fail if option is not recognised. */
6366461Sbostic 		if (m->m_option) {
64*68641Smckusick 			thisflagp = m->m_altloc ? altflagp : flagp;
6566461Sbostic 			if (negative == m->m_inverse)
66*68641Smckusick 				*thisflagp |= m->m_flag;
6766461Sbostic 			else
68*68641Smckusick 				*thisflagp &= ~m->m_flag;
69*68641Smckusick 		} else if (!getmnt_silent) {
7066461Sbostic 			errx(1, "-o %s: option not supported", opt);
71*68641Smckusick 		}
7266461Sbostic 	}
7366461Sbostic 
7466461Sbostic 	free(optbuf);
7566461Sbostic }
76