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.2 (Berkeley) 06/23/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, *p; 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 /* 46 * for options with assignments in them (ie. quotas) 47 * ignore the assignment as it's handled elsewhere 48 */ 49 p = strchr(opt, '='); 50 if (p) 51 *p = '\0'; 52 53 /* Scan option table. */ 54 for (m = m0; m->m_option != NULL; ++m) 55 if (strcasecmp(opt, m->m_option) == 0) 56 break; 57 58 /* Save flag, or fail if option is not recognised. */ 59 if (m->m_option) { 60 if (negative == m->m_inverse) 61 *flagp |= m->m_flag; 62 else 63 *flagp &= ~m->m_flag; 64 } else 65 errx(1, "-o %s: option not supported", opt); 66 } 67 68 free(optbuf); 69 } 70