summaryrefslogtreecommitdiff
path: root/sbin/mount/getmntopts.c
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2004-05-18 10:54:09 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2004-05-18 10:54:09 +0000
commitfb3389aa6c32e957b970a221c7bd4db26b90768a (patch)
tree6e7a2fe863e0b248eb2ac3f699a5ad8a92709a15 /sbin/mount/getmntopts.c
parenta174387f1484dd95a23635469066fe0a046f5d95 (diff)
Trailers are really wonders of the past. Remove them from man page and
usage. ok millert@
Diffstat (limited to 'sbin/mount/getmntopts.c')
-rw-r--r--sbin/mount/getmntopts.c103
1 files changed, 69 insertions, 34 deletions
diff --git a/sbin/mount/getmntopts.c b/sbin/mount/getmntopts.c
index 0e92408499c..134d5e4d8f9 100644
--- a/sbin/mount/getmntopts.c
+++ b/sbin/mount/getmntopts.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getmntopts.c,v 1.5 2003/06/11 06:22:13 deraadt Exp $ */
+/* $OpenBSD: getmntopts.c,v 1.6 2004/05/18 10:54:08 otto Exp $ */
/* $NetBSD: getmntopts.c,v 1.3 1995/03/18 14:56:58 cgd Exp $ */
/*-
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)getmntopts.c 8.1 (Berkeley) 3/27/94";
#else
-static char rcsid[] = "$OpenBSD: getmntopts.c,v 1.5 2003/06/11 06:22:13 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: getmntopts.c,v 1.6 2004/05/18 10:54:08 otto Exp $";
#endif
#endif /* not lint */
@@ -49,47 +49,82 @@ static char rcsid[] = "$OpenBSD: getmntopts.c,v 1.5 2003/06/11 06:22:13 deraadt
#include "mntopts.h"
-void
-getmntopts(const char *options, const struct mntopt *m0, int *flagp)
+int
+getmntopts(const char *optionp, const struct mntopt *m0, int *flagp)
{
- const struct mntopt *m;
- int negative;
- char *opt, *optbuf, *p;
+ char *p, *q;
+ union mntval val;
+ int ret = 0;
- /* Copy option string, since it is about to be torn asunder... */
- if ((optbuf = strdup(options)) == NULL)
+ p = q = strdup(optionp);
+ if (p == NULL)
err(1, NULL);
+ while (p != NULL) {
+ ret |= getmntopt(&p, &val, m0, flagp);
+ }
+ free(q);
+ return (ret);
+}
- for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
- /* Check for "no" prefix. */
- if (opt[0] == 'n' && opt[1] == 'o') {
- negative = 1;
- opt += 2;
- } else
- negative = 0;
+int
+getmntopt(char **optionp, union mntval *valuep, const struct mntopt *m0,
+ int *flagp)
+{
+ const struct mntopt *m;
+ char *opt, *value, *endp;
+ long l;
+ int negative, needval;
- /*
- * for options with assignments in them (ie. quotas)
- * ignore the assignment as it's handled elsewhere
- */
- p = strchr(opt, '=');
- if (p != NULL)
- *p = '\0';
+ /* Pull out the next option. */
+ do {
+ opt = strsep(optionp, ",");
+ } while (opt == NULL || *opt == '\0');
+ if (opt == NULL)
+ return (0);
- /* Scan option table. */
- for (m = m0; m->m_option != NULL; ++m)
- if (strcasecmp(opt, m->m_option) == 0)
- break;
+ /* Check for "no" prefix. */
+ if (opt[0] == 'n' && opt[1] == 'o') {
+ negative = 1;
+ opt += 2;
+ } else
+ negative = 0;
- /* Save flag, or fail if option is not recognised. */
- if (m->m_option) {
- if (negative == m->m_inverse)
+ /* Stash the value for options with assignments in them. */
+ if ((value = strchr(opt, '=')) != NULL)
+ *value++ = '\0';
+
+ /* Scan option table. */
+ for (m = m0; m->m_option != NULL; ++m)
+ if (strcasecmp(opt, m->m_option) == 0)
+ break;
+
+ /* Save flag, or fail if option is not recognised. */
+ if (m->m_option) {
+ needval = (m->m_oflags & (MFLAG_INTVAL|MFLAG_STRVAL)) != 0;
+ if (needval != (value != NULL))
+ errx(1, "-o %s: option %s a value", opt,
+ needval ? "needs" : "does not need");
+ if (m->m_oflags & MFLAG_SET) {
+ if (negative == (m->m_oflags & MFLAG_INVERSE) ? 1 : 0)
*flagp |= m->m_flag;
else
*flagp &= ~m->m_flag;
- } else
- errx(1, "-o %s: option not supported", opt);
- }
+ }
+ } else
+ errx(1, "-o %s: option not supported", opt);
- free(optbuf);
+ /* Store the value for options with assignments in them. */
+ if (value != NULL) {
+ if (m->m_oflags & MFLAG_INTVAL) {
+ l = strtol(value, &endp, 10);
+ if (endp == value || l < 0 || l > INT_MAX ||
+ (l == LONG_MAX && errno == ERANGE))
+ errx(1, "%s: illegal value '%s'",
+ opt, value);
+ valuep->ival = (int)l;
+ } else
+ valuep->strval = value;
+ } else
+ memset(valuep, 0, sizeof(*valuep));
+ return ((m->m_oflags & MFLAG_SET) ? 0 : (negative ? 0 : m->m_flag));
}