xref: /csrg-svn/sbin/mount/getmntopts.c (revision 67442)
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*67442Smckusick static char sccsid[] = "@(#)getmntopts.c	8.2 (Berkeley) 06/23/94";
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 
2366461Sbostic void
2466461Sbostic getmntopts(options, m0, flagp)
2566461Sbostic 	const char *options;
2666461Sbostic 	const struct mntopt *m0;
2766461Sbostic 	int *flagp;
2866461Sbostic {
2966461Sbostic 	const struct mntopt *m;
3066461Sbostic 	int negative;
31*67442Smckusick 	char *opt, *optbuf, *p;
3266461Sbostic 
3366461Sbostic 	/* Copy option string, since it is about to be torn asunder... */
3466461Sbostic 	if ((optbuf = strdup(options)) == NULL)
3566461Sbostic 		err(1, NULL);
3666461Sbostic 
3766461Sbostic 	for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
3866461Sbostic 		/* Check for "no" prefix. */
3966461Sbostic 		if (opt[0] == 'n' && opt[1] == 'o') {
4066461Sbostic 			negative = 1;
4166461Sbostic 			opt += 2;
4266461Sbostic 		} else
4366461Sbostic 			negative = 0;
4466461Sbostic 
45*67442Smckusick 		/*
46*67442Smckusick 		 * for options with assignments in them (ie. quotas)
47*67442Smckusick 		 * ignore the assignment as it's handled elsewhere
48*67442Smckusick 		 */
49*67442Smckusick 		p = strchr(opt, '=');
50*67442Smckusick 		if (p)
51*67442Smckusick 			 *p = '\0';
52*67442Smckusick 
5366461Sbostic 		/* Scan option table. */
5466461Sbostic 		for (m = m0; m->m_option != NULL; ++m)
5566461Sbostic 			if (strcasecmp(opt, m->m_option) == 0)
5666461Sbostic 				break;
5766461Sbostic 
5866461Sbostic 		/* Save flag, or fail if option is not recognised. */
5966461Sbostic 		if (m->m_option) {
6066461Sbostic 			if (negative == m->m_inverse)
6166461Sbostic 				*flagp |= m->m_flag;
6266461Sbostic 			else
6366461Sbostic 				*flagp &= ~m->m_flag;
6466461Sbostic 		} else
6566461Sbostic 			errx(1, "-o %s: option not supported", opt);
6666461Sbostic 	}
6766461Sbostic 
6866461Sbostic 	free(optbuf);
6966461Sbostic }
70