Subject: Re: encrypted swap?
To: None <tech-kern@netbsd.org>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-kern
Date: 06/10/2001 13:41:40
Here's a cut at adding -o foo=bar support to getmntopts(), by adding a
MOPT_ASSIGNMENT flag. Two things:
- I've changed the m_inverse member to be a m_flags, that
has options for a negative flag (eg, "nodev") so that
existing code doesn't need to change (but I'll change
all the "1"s to MOPT_NEGATIVE if I take this further).
- There's a comment in getmntopts()
* for options with assignments in them (ie. quotas)
* ignore the assignment as it's handled elsewhere
that I can't see offhand where such a thing is used (I've never used
quotas either). Anyone know how/where this is used?
If there's no problems with this approach I'll polish it up some more
and post some new patches...
Simon.
--
Simon Burge <simonb@wasabisystems.com>
NetBSD CDs, Support and Service: http://www.wasabisystems.com/
Index: mount/getmntopts.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount/getmntopts.c,v
retrieving revision 1.6
diff -d -p -u -r1.6 getmntopts.c
--- mount/getmntopts.c 1999/11/09 15:06:33 1.6
+++ mount/getmntopts.c 2001/06/10 03:32:44
@@ -58,13 +58,13 @@ int getmnt_silent = 0;
void
getmntopts(options, m0, flagp, altflagp)
const char *options;
- const struct mntopt *m0;
+ struct mntopt *m0;
int *flagp;
int *altflagp;
{
- const struct mntopt *m;
+ struct mntopt *m;
int negative;
- char *opt, *optbuf, *p;
+ char *assarg, *opt, *optbuf, *p;
int *thisflagp;
/* Copy option string, since it is about to be torn asunder... */
@@ -83,9 +83,12 @@ getmntopts(options, m0, flagp, altflagp)
* for options with assignments in them (ie. quotas)
* ignore the assignment as it's handled elsewhere
*/
+ assarg = NULL;
p = strchr(opt, '=');
- if (p)
+ if (p) {
*p = '\0';
+ assarg = p + 1;
+ }
/* Scan option table. */
for (m = m0; m->m_option != NULL; ++m)
@@ -95,10 +98,17 @@ getmntopts(options, m0, flagp, altflagp)
/* Save flag, or fail if option is not recognised. */
if (m->m_option) {
thisflagp = m->m_altloc ? altflagp : flagp;
- if (negative == m->m_inverse)
+ if (negative == (m->m_flags & MOPT_NEGATIVE))
*thisflagp |= m->m_flag;
else
*thisflagp &= ~m->m_flag;
+ if (assarg) {
+ if (*assarg)
+ m->m_arg = strdup(assarg);
+ else
+ errx(1, "-o %s: no argument given",
+ opt);
+ }
} else if (!getmnt_silent) {
errx(1, "-o %s: option not supported", opt);
}
Index: mount/mntopts.h
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount/mntopts.h,v
retrieving revision 1.9
diff -d -p -u -r1.9 mntopts.h
--- mount/mntopts.h 2000/06/15 22:36:07 1.9
+++ mount/mntopts.h 2001/06/10 03:32:44
@@ -37,10 +37,14 @@
struct mntopt {
const char *m_option; /* option name */
- int m_inverse; /* if a negative option, eg "dev" */
+ int m_flags; /* if a negative option, eg "dev" */
int m_flag; /* bit to set, eg. MNT_RDONLY */
int m_altloc; /* 1 => set bit in altflags */
+ char *m_arg; /* argument for a "opt=arg" option */
};
+/* m_flags */
+#define MOPT_NEGATIVE 1 /* a negative option, eg "dev" */
+#define MOPT_ASSIGNMENT 2 /* assignment option, eg "port=xx" */
/* User-visible MNT_ flags. */
#define MOPT_ASYNC { "async", 0, MNT_ASYNC, 0 }
@@ -88,5 +92,5 @@ struct mntopt {
MOPT_UNION, \
MOPT_SYMPERM
-void getmntopts __P((const char *, const struct mntopt *, int *, int *));
+void getmntopts __P((const char *, struct mntopt *, int *, int *));
extern int getmnt_silent;
Index: mount_ados/mount_ados.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_ados/mount_ados.c,v
retrieving revision 1.13
diff -d -p -u -r1.13 mount_ados.c
--- mount_ados/mount_ados.c 2001/02/22 21:34:57 1.13
+++ mount_ados/mount_ados.c 2001/06/10 03:32:44
@@ -58,7 +58,7 @@ __RCSID("$NetBSD: mount_ados.c,v 1.13 20
#include <errno.h>
#include <fattr.h>
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
{ NULL }
};
Index: mount_cd9660/mount_cd9660.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_cd9660/mount_cd9660.c,v
retrieving revision 1.14
diff -d -p -u -r1.14 mount_cd9660.c
--- mount_cd9660/mount_cd9660.c 2000/10/30 20:56:58 1.14
+++ mount_cd9660/mount_cd9660.c 2001/06/10 03:32:45
@@ -67,7 +67,7 @@ __RCSID("$NetBSD: mount_cd9660.c,v 1.14
#include "mntopts.h"
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_UPDATE,
{ "extatt", 0, ISOFSMNT_EXTATT, 1 },
Index: mount_ext2fs/mount_ext2fs.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_ext2fs/mount_ext2fs.c,v
retrieving revision 1.8
diff -d -p -u -r1.8 mount_ext2fs.c
--- mount_ext2fs/mount_ext2fs.c 2000/10/30 20:56:58 1.8
+++ mount_ext2fs/mount_ext2fs.c 2001/06/10 03:32:45
@@ -65,7 +65,7 @@ static void ext2fs_usage __P((void));
int main __P((int, char *[]));
int mount_ext2fs __P((int argc, char **argv));
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_ASYNC,
MOPT_SYNC,
Index: mount_fdesc/mount_fdesc.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_fdesc/mount_fdesc.c,v
retrieving revision 1.11
diff -d -p -u -r1.11 mount_fdesc.c
--- mount_fdesc/mount_fdesc.c 2000/10/30 20:56:59 1.11
+++ mount_fdesc/mount_fdesc.c 2001/06/10 03:32:45
@@ -62,7 +62,7 @@ __RCSID("$NetBSD: mount_fdesc.c,v 1.11 2
#include "mntopts.h"
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
{ NULL }
};
Index: mount_ffs/mount_ffs.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_ffs/mount_ffs.c,v
retrieving revision 1.12
diff -d -p -u -r1.12 mount_ffs.c
--- mount_ffs/mount_ffs.c 2000/10/30 20:56:59 1.12
+++ mount_ffs/mount_ffs.c 2001/06/10 03:32:45
@@ -65,7 +65,7 @@ static void ffs_usage __P((void));
int main __P((int, char *[]));
int mount_ffs __P((int argc, char **argv));
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_ASYNC,
MOPT_SYNC,
Index: mount_filecore/mount_filecore.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_filecore/mount_filecore.c,v
retrieving revision 1.4
diff -d -p -u -r1.4 mount_filecore.c
--- mount_filecore/mount_filecore.c 2000/10/30 20:56:59 1.4
+++ mount_filecore/mount_filecore.c 2001/06/10 03:32:45
@@ -64,7 +64,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 19
#include "mntopts.h"
#include <fattr.h>
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_UPDATE,
{ NULL }
Index: mount_kernfs/mount_kernfs.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_kernfs/mount_kernfs.c,v
retrieving revision 1.12
diff -d -p -u -r1.12 mount_kernfs.c
--- mount_kernfs/mount_kernfs.c 2000/10/30 20:56:59 1.12
+++ mount_kernfs/mount_kernfs.c 2001/06/10 03:32:45
@@ -62,7 +62,7 @@ __RCSID("$NetBSD: mount_kernfs.c,v 1.12
#include "mntopts.h"
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
{ NULL }
};
Index: mount_lfs/mount_lfs.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_lfs/mount_lfs.c,v
retrieving revision 1.12
diff -d -p -u -r1.12 mount_lfs.c
--- mount_lfs/mount_lfs.c 2000/11/13 22:12:49 1.12
+++ mount_lfs/mount_lfs.c 2001/06/10 03:32:45
@@ -65,7 +65,7 @@ __RCSID("$NetBSD: mount_lfs.c,v 1.12 200
#include "mntopts.h"
#include "pathnames.h"
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_UPDATE,
{ NULL }
Index: mount_msdos/mount_msdos.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_msdos/mount_msdos.c,v
retrieving revision 1.24
diff -d -p -u -r1.24 mount_msdos.c
--- mount_msdos/mount_msdos.c 2000/10/30 20:57:00 1.24
+++ mount_msdos/mount_msdos.c 2001/06/10 03:32:45
@@ -56,7 +56,7 @@ __RCSID("$NetBSD: mount_msdos.c,v 1.24 2
#include "mntopts.h"
#include <fattr.h>
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_ASYNC,
MOPT_SYNC,
Index: mount_nfs/mount_nfs.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_nfs/mount_nfs.c,v
retrieving revision 1.30
diff -d -p -u -r1.30 mount_nfs.c
--- mount_nfs/mount_nfs.c 2001/01/11 01:33:35 1.30
+++ mount_nfs/mount_nfs.c 2001/06/10 03:32:46
@@ -92,22 +92,25 @@ __RCSID("$NetBSD: mount_nfs.c,v 1.30 200
#include "mntopts.h"
-#define ALTF_BG 0x1
-#define ALTF_CONN 0x2
-#define ALTF_DUMBTIMR 0x4
-#define ALTF_INTR 0x8
-#define ALTF_KERB 0x10
-#define ALTF_NFSV3 0x20
-#define ALTF_RDIRPLUS 0x40
-#define ALTF_MNTUDP 0x80
-#define ALTF_NORESPORT 0x100
-#define ALTF_SEQPACKET 0x200
-#define ALTF_NQNFS 0x400
-#define ALTF_SOFT 0x800
+#define ALTF_BG 0x0001
+#define ALTF_CONN 0x0002
+#define ALTF_DUMBTIMR 0x0004
+#define ALTF_INTR 0x0008
+#define ALTF_KERB 0x0010
+#define ALTF_NFSV3 0x0020
+#define ALTF_RDIRPLUS 0x0040
+#define ALTF_MNTUDP 0x0080
+#define ALTF_NORESPORT 0x0100
+#define ALTF_SEQPACKET 0x0200
+#define ALTF_NQNFS 0x0400
+#define ALTF_SOFT 0x0800
#define ALTF_TCP 0x1000
#define ALTF_NFSV2 0x2000
+#define ALTF_PORT 0x4000
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
+ { "port", MOPT_ASSIGNMENT, ALTF_PORT, 1, NULL },
+#define X_MNTOPT_PORT 0
MOPT_STDOPTS,
MOPT_FORCE,
MOPT_UPDATE,
@@ -169,6 +172,7 @@ int nfsproto = IPPROTO_UDP;
int force2 = 0;
int force3 = 0;
int mnttcp_ok = 1;
+int nfsport = 0;
#ifdef NFSKERB
static char inst[INST_SZ];
@@ -364,6 +368,13 @@ mount_nfs(argc, argv)
nfsargsp->sotype = SOCK_STREAM;
nfsproto = IPPROTO_TCP;
}
+ if (altflags & ALTF_PORT) {
+ nfsport = strtol(mopts[X_MNTOPT_PORT].m_arg,
+ &p, 10);
+ if (*p || nfsport < 0)
+ errx(1, "illegal port -- %s",
+ mopts[X_MNTOPT_PORT].m_arg);
+ }
altflags = 0;
break;
case 'P':
@@ -793,6 +804,11 @@ tryagain:
{
nfsargsp->addr = (struct sockaddr *) nfs_nb.buf;
nfsargsp->addrlen = nfs_nb.len;
+ if (nfsport > 0) {
+ struct sockaddr_in *sin = (struct sockaddr_in *)
+ nfsargsp->addr;
+ sin->sin_port = htons(nfsport);
+ }
}
nfsargsp->fh = nfhret.nfh;
nfsargsp->fhsize = nfhret.fhsize;
Index: mount_ntfs/mount_ntfs.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_ntfs/mount_ntfs.c,v
retrieving revision 1.5
diff -d -p -u -r1.5 mount_ntfs.c
--- mount_ntfs/mount_ntfs.c 2000/10/30 20:57:00 1.5
+++ mount_ntfs/mount_ntfs.c 2001/06/10 03:32:46
@@ -57,7 +57,7 @@ __RCSID("$NetBSD: mount_ntfs.c,v 1.5 200
#include "mntopts.h"
#include <fattr.h>
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
{ NULL }
};
Index: mount_null/mount_null.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_null/mount_null.c,v
retrieving revision 1.8
diff -d -p -u -r1.8 mount_null.c
--- mount_null/mount_null.c 2000/10/30 20:57:00 1.8
+++ mount_null/mount_null.c 2001/06/10 03:32:46
@@ -62,7 +62,7 @@ __RCSID("$NetBSD: mount_null.c,v 1.8 200
#include "mntopts.h"
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
{ NULL }
};
Index: mount_overlay/mount_overlay.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_overlay/mount_overlay.c,v
retrieving revision 1.2
diff -d -p -u -r1.2 mount_overlay.c
--- mount_overlay/mount_overlay.c 2000/10/30 20:57:00 1.2
+++ mount_overlay/mount_overlay.c 2001/06/10 03:32:46
@@ -62,7 +62,7 @@ __RCSID("$NetBSD: mount_overlay.c,v 1.2
#include "mntopts.h"
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
{ NULL }
};
Index: mount_portal/mount_portal.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_portal/mount_portal.c,v
retrieving revision 1.18
diff -d -p -u -r1.18 mount_portal.c
--- mount_portal/mount_portal.c 2001/01/10 03:33:16 1.18
+++ mount_portal/mount_portal.c 2001/06/10 03:32:46
@@ -70,7 +70,7 @@ __RCSID("$NetBSD: mount_portal.c,v 1.18
#include "pathnames.h"
#include "portald.h"
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
{ NULL }
};
Index: mount_procfs/mount_procfs.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_procfs/mount_procfs.c,v
retrieving revision 1.12
diff -d -p -u -r1.12 mount_procfs.c
--- mount_procfs/mount_procfs.c 2001/01/17 00:09:54 1.12
+++ mount_procfs/mount_procfs.c 2001/06/10 03:32:47
@@ -64,7 +64,7 @@ __RCSID("$NetBSD: mount_procfs.c,v 1.12
#include "mntopts.h"
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
{ "linux", 0, PROCFSMNT_LINUXCOMPAT, 1},
{ NULL }
Index: mount_umap/mount_umap.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_umap/mount_umap.c,v
retrieving revision 1.11
diff -d -p -u -r1.11 mount_umap.c
--- mount_umap/mount_umap.c 2000/10/30 20:57:01 1.11
+++ mount_umap/mount_umap.c 2001/06/10 03:32:47
@@ -82,7 +82,7 @@ __RCSID("$NetBSD: mount_umap.c,v 1.11 20
* will, in turn, call the umap version of mount.
*/
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
{ NULL }
};
Index: mount_union/mount_union.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_union/mount_union.c,v
retrieving revision 1.7
diff -d -p -u -r1.7 mount_union.c
--- mount_union/mount_union.c 2000/10/30 20:57:01 1.7
+++ mount_union/mount_union.c 2001/06/10 03:32:47
@@ -63,7 +63,7 @@ __RCSID("$NetBSD: mount_union.c,v 1.7 20
#include "mntopts.h"
-static const struct mntopt mopts[] = {
+static struct mntopt mopts[] = {
MOPT_STDOPTS,
{ NULL }
};