getmntopts.c revision 1558
1193323Sed/*- 2193323Sed * Copyright (c) 1994 3193323Sed * The Regents of the University of California. All rights reserved. 4193323Sed * 5193323Sed * Redistribution and use in source and binary forms, with or without 6193323Sed * modification, are permitted provided that the following conditions 7193323Sed * are met: 8193323Sed * 1. Redistributions of source code must retain the above copyright 9193323Sed * notice, this list of conditions and the following disclaimer. 10193323Sed * 2. Redistributions in binary form must reproduce the above copyright 11193323Sed * notice, this list of conditions and the following disclaimer in the 12193323Sed * documentation and/or other materials provided with the distribution. 13193323Sed * 3. All advertising materials mentioning features or use of this software 14193323Sed * must display the following acknowledgement: 15193323Sed * This product includes software developed by the University of 16193323Sed * California, Berkeley and its contributors. 17193323Sed * 4. Neither the name of the University nor the names of its contributors 18193323Sed * may be used to endorse or promote products derived from this software 19193323Sed * without specific prior written permission. 20193323Sed * 21193323Sed * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22193323Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23193323Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24193323Sed * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25193323Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26199481Srdivacky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27199481Srdivacky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28199481Srdivacky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29199481Srdivacky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30199481Srdivacky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31193323Sed * SUCH DAMAGE. 32193323Sed */ 33193323Sed 34193323Sed#ifndef lint 35193323Sedstatic char sccsid[] = "@(#)getmntopts.c 8.1 (Berkeley) 3/27/94"; 36193323Sed#endif /* not lint */ 37193323Sed 38193323Sed#include <sys/param.h> 39193323Sed#include <sys/mount.h> 40193323Sed 41193323Sed#include <err.h> 42193323Sed#include <errno.h> 43193323Sed#include <fstab.h> 44205218Srdivacky#include <stdlib.h> 45193323Sed#include <string.h> 46198090Srdivacky 47193323Sed#include "mntopts.h" 48193323Sed 49193323Sedvoid 50198090Srdivackygetmntopts(options, m0, flagp) 51198090Srdivacky const char *options; 52193323Sed const struct mntopt *m0; 53195340Sed int *flagp; 54193323Sed{ 55204642Srdivacky const struct mntopt *m; 56193323Sed int negative; 57193323Sed char *opt, *optbuf; 58193323Sed 59193323Sed /* Copy option string, since it is about to be torn asunder... */ 60193323Sed if ((optbuf = strdup(options)) == NULL) 61193323Sed err(1, NULL); 62193323Sed 63193323Sed for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) { 64193323Sed /* Check for "no" prefix. */ 65193323Sed if (opt[0] == 'n' && opt[1] == 'o') { 66198892Srdivacky negative = 1; 67193323Sed opt += 2; 68198090Srdivacky } else 69193323Sed negative = 0; 70193323Sed 71193323Sed /* Scan option table. */ 72193323Sed for (m = m0; m->m_option != NULL; ++m) 73193323Sed if (strcasecmp(opt, m->m_option) == 0) 74193323Sed break; 75198090Srdivacky 76198090Srdivacky /* Save flag, or fail if option is not recognised. */ 77193323Sed if (m->m_option) { 78193323Sed if (negative == m->m_inverse) 79193323Sed *flagp |= m->m_flag; 80198090Srdivacky else 81198090Srdivacky *flagp &= ~m->m_flag; 82193323Sed } else 83193323Sed errx(1, "-o %s: option not supported", opt); 84193323Sed } 85193323Sed 86193323Sed free(optbuf); 87198090Srdivacky} 88193323Sed