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.3 (Berkeley) 03/29/95"; 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 int getmnt_silent = 0; 24 25 void 26 getmntopts(options, m0, flagp, altflagp) 27 const char *options; 28 const struct mntopt *m0; 29 int *flagp; 30 int *altflagp; 31 { 32 const struct mntopt *m; 33 int negative; 34 char *opt, *optbuf, *p; 35 int *thisflagp; 36 37 /* Copy option string, since it is about to be torn asunder... */ 38 if ((optbuf = strdup(options)) == NULL) 39 err(1, NULL); 40 41 for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) { 42 /* Check for "no" prefix. */ 43 if (opt[0] == 'n' && opt[1] == 'o') { 44 negative = 1; 45 opt += 2; 46 } else 47 negative = 0; 48 49 /* 50 * for options with assignments in them (ie. quotas) 51 * ignore the assignment as it's handled elsewhere 52 */ 53 p = strchr(opt, '='); 54 if (p) 55 *p = '\0'; 56 57 /* Scan option table. */ 58 for (m = m0; m->m_option != NULL; ++m) 59 if (strcasecmp(opt, m->m_option) == 0) 60 break; 61 62 /* Save flag, or fail if option is not recognised. */ 63 if (m->m_option) { 64 thisflagp = m->m_altloc ? altflagp : flagp; 65 if (negative == m->m_inverse) 66 *thisflagp |= m->m_flag; 67 else 68 *thisflagp &= ~m->m_flag; 69 } else if (!getmnt_silent) { 70 errx(1, "-o %s: option not supported", opt); 71 } 72 } 73 74 free(optbuf); 75 } 76