getmntopts.c revision 37425
11558Srgrimes/*- 21558Srgrimes * Copyright (c) 1994 31558Srgrimes * The Regents of the University of California. All rights reserved. 41558Srgrimes * 51558Srgrimes * Redistribution and use in source and binary forms, with or without 61558Srgrimes * modification, are permitted provided that the following conditions 71558Srgrimes * are met: 81558Srgrimes * 1. Redistributions of source code must retain the above copyright 91558Srgrimes * notice, this list of conditions and the following disclaimer. 101558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111558Srgrimes * notice, this list of conditions and the following disclaimer in the 121558Srgrimes * documentation and/or other materials provided with the distribution. 131558Srgrimes * 3. All advertising materials mentioning features or use of this software 141558Srgrimes * must display the following acknowledgement: 151558Srgrimes * This product includes software developed by the University of 161558Srgrimes * California, Berkeley and its contributors. 171558Srgrimes * 4. Neither the name of the University nor the names of its contributors 181558Srgrimes * may be used to endorse or promote products derived from this software 191558Srgrimes * without specific prior written permission. 201558Srgrimes * 211558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311558Srgrimes * SUCH DAMAGE. 321558Srgrimes */ 331558Srgrimes 341558Srgrimes#ifndef lint 3528671Ssteve#if 0 3623678Speterstatic char sccsid[] = "@(#)getmntopts.c 8.3 (Berkeley) 3/29/95"; 3728671Ssteve#else 3828671Sstevestatic const char rcsid[] = 3937425Scharnier "$Id: getmntopts.c,v 1.6 1997/08/24 21:02:47 steve Exp $"; 4028671Ssteve#endif 411558Srgrimes#endif /* not lint */ 421558Srgrimes 431558Srgrimes#include <sys/param.h> 441558Srgrimes 451558Srgrimes#include <err.h> 461558Srgrimes#include <stdlib.h> 471558Srgrimes#include <string.h> 481558Srgrimes 491558Srgrimes#include "mntopts.h" 501558Srgrimes 514065Swollmanint getmnt_silent = 0; 524065Swollman 531558Srgrimesvoid 544065Swollmangetmntopts(options, m0, flagp, altflagp) 551558Srgrimes const char *options; 561558Srgrimes const struct mntopt *m0; 571558Srgrimes int *flagp; 584065Swollman int *altflagp; 591558Srgrimes{ 601558Srgrimes const struct mntopt *m; 613202Sache int negative, len; 6223678Speter char *opt, *optbuf, *p; 634065Swollman int *thisflagp; 641558Srgrimes 651558Srgrimes /* Copy option string, since it is about to be torn asunder... */ 661558Srgrimes if ((optbuf = strdup(options)) == NULL) 671558Srgrimes err(1, NULL); 681558Srgrimes 691558Srgrimes for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) { 701558Srgrimes /* Check for "no" prefix. */ 711558Srgrimes if (opt[0] == 'n' && opt[1] == 'o') { 721558Srgrimes negative = 1; 731558Srgrimes opt += 2; 741558Srgrimes } else 751558Srgrimes negative = 0; 761558Srgrimes 7723678Speter /* 7823678Speter * for options with assignments in them (ie. quotas) 7923678Speter * ignore the assignment as it's handled elsewhere 8023678Speter */ 8123678Speter p = strchr(opt, '='); 8223678Speter if (p) 8325301Smsmith *++p = '\0'; 8423678Speter 851558Srgrimes /* Scan option table. */ 863202Sache for (m = m0; m->m_option != NULL; ++m) { 873202Sache len = strlen(m->m_option); 883202Sache if (strncasecmp(opt, m->m_option, len) == 0) 893202Sache if ( m->m_option[len] == '\0' 903202Sache || m->m_option[len] == '=' 913202Sache ) 921558Srgrimes break; 933202Sache } 941558Srgrimes 9537425Scharnier /* Save flag, or fail if option is not recognized. */ 961558Srgrimes if (m->m_option) { 974065Swollman thisflagp = m->m_altloc ? altflagp : flagp; 981558Srgrimes if (negative == m->m_inverse) 994065Swollman *thisflagp |= m->m_flag; 1001558Srgrimes else 1014065Swollman *thisflagp &= ~m->m_flag; 10223678Speter } else if (!getmnt_silent) { 1031558Srgrimes errx(1, "-o %s: option not supported", opt); 1044065Swollman } 1051558Srgrimes } 1061558Srgrimes 1071558Srgrimes free(optbuf); 1081558Srgrimes} 109