summaryrefslogtreecommitdiff
path: root/sbin/mount
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2004-05-18 11:07:55 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2004-05-18 11:07:55 +0000
commit4ac4e54d7aeca8f95a01bdd8c492e789c7000d7c (patch)
tree63c27ae76e822716f1a41227dc1190679883bab3 /sbin/mount
parentfb3389aa6c32e957b970a221c7bd4db26b90768a (diff)
Backout changes accidentally committed in prvious commit.
Diffstat (limited to 'sbin/mount')
-rw-r--r--sbin/mount/getmntopts.c103
-rw-r--r--sbin/mount/mntopts.h55
2 files changed, 55 insertions, 103 deletions
diff --git a/sbin/mount/getmntopts.c b/sbin/mount/getmntopts.c
index 134d5e4d8f9..2712fa29c17 100644
--- a/sbin/mount/getmntopts.c
+++ b/sbin/mount/getmntopts.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getmntopts.c,v 1.6 2004/05/18 10:54:08 otto Exp $ */
+/* $OpenBSD: getmntopts.c,v 1.7 2004/05/18 11:07:53 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.6 2004/05/18 10:54:08 otto Exp $";
+static char rcsid[] = "$OpenBSD: getmntopts.c,v 1.7 2004/05/18 11:07:53 otto Exp $";
#endif
#endif /* not lint */
@@ -49,82 +49,47 @@ static char rcsid[] = "$OpenBSD: getmntopts.c,v 1.6 2004/05/18 10:54:08 otto Exp
#include "mntopts.h"
-int
-getmntopts(const char *optionp, const struct mntopt *m0, int *flagp)
-{
- char *p, *q;
- union mntval val;
- int ret = 0;
-
- p = q = strdup(optionp);
- if (p == NULL)
- err(1, NULL);
- while (p != NULL) {
- ret |= getmntopt(&p, &val, m0, flagp);
- }
- free(q);
- return (ret);
-}
-
-int
-getmntopt(char **optionp, union mntval *valuep, const struct mntopt *m0,
- int *flagp)
+void
+getmntopts(const char *options, const struct mntopt *m0, int *flagp)
{
const struct mntopt *m;
- char *opt, *value, *endp;
- long l;
- int negative, needval;
+ int negative;
+ char *opt, *optbuf, *p;
- /* Pull out the next option. */
- do {
- opt = strsep(optionp, ",");
- } while (opt == NULL || *opt == '\0');
- if (opt == NULL)
- return (0);
+ /* Copy option string, since it is about to be torn asunder... */
+ if ((optbuf = strdup(options)) == NULL)
+ err(1, NULL);
- /* Check for "no" prefix. */
- if (opt[0] == 'n' && opt[1] == 'o') {
- negative = 1;
- opt += 2;
- } else
- negative = 0;
+ 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;
- /* Stash the value for options with assignments in them. */
- if ((value = strchr(opt, '=')) != NULL)
- *value++ = '\0';
+ /*
+ * for options with assignments in them (ie. quotas)
+ * ignore the assignment as it's handled elsewhere
+ */
+ p = strchr(opt, '=');
+ if (p != NULL)
+ *p = '\0';
- /* Scan option table. */
- for (m = m0; m->m_option != NULL; ++m)
- if (strcasecmp(opt, m->m_option) == 0)
- break;
+ /* 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)
+ /* Save flag, or fail if option is not recognised. */
+ if (m->m_option) {
+ if (negative == m->m_inverse)
*flagp |= m->m_flag;
else
*flagp &= ~m->m_flag;
- }
- } else
- errx(1, "-o %s: option not supported", opt);
-
- /* 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));
+ errx(1, "-o %s: option not supported", opt);
+ }
+
+ free(optbuf);
}
diff --git a/sbin/mount/mntopts.h b/sbin/mount/mntopts.h
index 65de81b0ba9..094580ec1ca 100644
--- a/sbin/mount/mntopts.h
+++ b/sbin/mount/mntopts.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mntopts.h,v 1.11 2004/05/18 10:54:08 otto Exp $ */
+/* $OpenBSD: mntopts.h,v 1.12 2004/05/18 11:07:53 otto Exp $ */
/* $NetBSD: mntopts.h,v 1.3 1995/03/18 14:56:59 cgd Exp $ */
/*-
@@ -32,49 +32,37 @@
* @(#)mntopts.h 8.3 (Berkeley) 3/27/94
*/
-#define MFLAG_INVERSE 0x01 /* if a negative option, eg "dev" */
-#define MFLAG_SET 0x02 /* 1 => set bit in mntflags,
- 0 => return flag */
-#define MFLAG_STRVAL 0x04 /* option needs a string value */
-#define MFLAG_INTVAL 0x08 /* option needs as int value */
-
struct mntopt {
const char *m_option; /* option name */
+ int m_inverse; /* if a negative option, eg "dev" */
int m_flag; /* bit to set, eg. MNT_RDONLY */
- int m_oflags;
-};
-
-union mntval {
- char *strval;
- int ival;
};
/* User-visible MNT_ flags. */
-#define MOPT_ASYNC { "async", MNT_ASYNC, MFLAG_SET }
-#define MOPT_NOACCESSTIME { "accesstime", MNT_NOATIME, \
- MFLAG_INVERSE | MFLAG_SET }
-#define MOPT_NOATIME { "atime", MNT_NOATIME, MFLAG_INVERSE | MFLAG_SET }
-#define MOPT_NODEV { "dev", MNT_NODEV, MFLAG_INVERSE | MFLAG_SET }
-#define MOPT_NOEXEC { "exec", MNT_NOEXEC, MFLAG_INVERSE | MFLAG_SET }
-#define MOPT_NOSUID { "suid", MNT_NOSUID, MFLAG_INVERSE | MFLAG_SET }
-#define MOPT_RDONLY { "rdonly", MNT_RDONLY, MFLAG_SET }
-#define MOPT_SYNC { "sync", MNT_SYNCHRONOUS, MFLAG_SET }
-#define MOPT_UNION { "union", MNT_UNION, MFLAG_SET }
-#define MOPT_USERQUOTA { "userquota", 0, MFLAG_SET }
-#define MOPT_GROUPQUOTA { "groupquota", 0, MFLAG_SET }
-#define MOPT_SOFTDEP { "softdep", MNT_SOFTDEP, MFLAG_SET }
+#define MOPT_ASYNC { "async", 0, MNT_ASYNC }
+#define MOPT_NOACCESSTIME { "accesstime", 1, MNT_NOATIME }
+#define MOPT_NOATIME { "atime", 1, MNT_NOATIME }
+#define MOPT_NODEV { "dev", 1, MNT_NODEV }
+#define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC }
+#define MOPT_NOSUID { "suid", 1, MNT_NOSUID }
+#define MOPT_RDONLY { "rdonly", 0, MNT_RDONLY }
+#define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS }
+#define MOPT_UNION { "union", 0, MNT_UNION }
+#define MOPT_USERQUOTA { "userquota", 0, 0 }
+#define MOPT_GROUPQUOTA { "groupquota", 0, 0 }
+#define MOPT_SOFTDEP { "softdep", 0, MNT_SOFTDEP }
/* Control flags. */
-#define MOPT_FORCE { "force", MNT_FORCE, MFLAG_SET }
-#define MOPT_UPDATE { "update", MNT_UPDATE, MFLAG_SET }
-#define MOPT_RELOAD { "reload", MNT_RELOAD, MFLAG_SET }
+#define MOPT_FORCE { "force", 0, MNT_FORCE }
+#define MOPT_UPDATE { "update", 0, MNT_UPDATE }
+#define MOPT_RELOAD { "reload", 0, MNT_RELOAD }
/* Support for old-style "ro", "rw" flags. */
-#define MOPT_RO { "ro", MNT_RDONLY, MFLAG_SET }
-#define MOPT_RW { "rw", MNT_RDONLY, MFLAG_INVERSE | MFLAG_SET }
+#define MOPT_RO { "ro", 0, MNT_RDONLY }
+#define MOPT_RW { "rw", 1, MNT_RDONLY }
/* This is parsed by mount(8), but is ignored by specific mount_*(8)s. */
-#define MOPT_AUTO { "auto", 0, MFLAG_SET }
+#define MOPT_AUTO { "auto", 0, 0 }
#define MOPT_FSTAB_COMPAT \
MOPT_RO, \
@@ -94,5 +82,4 @@ union mntval {
MOPT_RDONLY, \
MOPT_UNION
-int getmntopts(const char *, const struct mntopt *, int *);
-int getmntopt(char **, union mntval *, const struct mntopt *, int *);
+void getmntopts(const char *, const struct mntopt *, int *);