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