Skip to contentSkip to conversation

text-based mount.nfs: parse option strings into lists

PATCH New Chuck Lever 1 participant 1 message Sep 12, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 5/24 text-based mount.nfs: parse option strings into lists

Adapt a parsing trick used by Python.

Change incoming option strings into an ADT so we don't have to copy and parse the whole option string multiple times while trying to manipulate the options. Just before calling the mount(2) system call, convert the ADT back into a C string.

This initial patch adds helpers for creating and manipulating the ADT.

One major advantage of this approach is that we can copy the final version of the mount options into /etc/mtab when we're done, instead of copying in the mount options that the user specified. Any fallback from NFS v3 to NFS v2 or TCP to UDP that was done by mount.nfs will be reflected in /etc/mtab.

---

 utils/mount/Makefile.am |    4 
 utils/mount/parse_opt.c |  449 +++++++++++++++++++++++++++++++++++++++++++++++
 utils/mount/parse_opt.h |   35 ++++
 3 files changed, 486 insertions(+), 2 deletions(-)
utils/mount/Makefile.am +2 -2
index 23e7ae9..f703047 100644
@@ -9,11 +9,11 @@ man5_MANS	= nfs.man
 
 sbin_PROGRAMS	= mount.nfs
 EXTRA_DIST = nfsmount.x $(man8_MANS) $(man5_MANS)
-mount_nfs_SOURCES = mount.c error.c network.c fstab.c \
+mount_nfs_SOURCES = mount.c error.c network.c fstab.c parse_opt.c \
 		    nfsmount.c nfs4mount.c stropts.c\
 		    nfsumount.c \
 		    mount_constants.h error.h network.h fstab.h \
-		    nfs4_mount.h nfs_mount4.h stropts.h
+		    nfs4_mount.h nfs_mount4.h stropts.h parse_opt.h
 
 mount_nfs_LDADD = ../../support/nfs/libnfs.a \
 		  ../../support/export/libexport.a
utils/mount/parse_opt.c new file +449 -0

449 lines not on this page · raw message

utils/mount/parse_opt.h new file +35 -0
new file mode 100644
index 0000000..b1bae5d
@@ -0,0 +1,35 @@
+/*
+ * parse_opt.h -- mount option string parsing helpers
+ *
+ * Copyright (C) 2007 Oracle.  All rights reserved.
+ * Copyright (C) 2007 Chuck Lever <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ */
+
+struct mount_options;
+
+struct mount_options *	po_split(char *);
+struct mount_options *	po_duplicate(struct mount_options *);
+char *			po_join(struct mount_options *);
+
+int			po_append(struct mount_options *, char *);
+int			po_contains(struct mount_options *, char *);
+char *			po_get(struct mount_options *, char *);
+int			po_rightmost(struct mount_options *, char *, char *);
+int			po_remove_all(struct mount_options *, char *);
+void			po_destroy(struct mount_options *);

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs