Bug 25273

Summary: add fs type feature to vnconfig(8) to allow direct mount of iso images and co.
Product: Base System Reporter: Cyrille Lefevre <clefevre>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.2-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff
none
file.diff none

Description Cyrille Lefevre 2001-02-22 04:00:07 UTC
	currently, it is not possible to mount an iso image
	in one pass using vnconfig such as :

	vnconfig -v -e vn0 /tmp/image.iso mountro=/mnt

	effectively, the -e option mount such image using the
	hard coded fs type which is ufs.

	so, to mount an iso image, you have to do the following
	statement :

	vnconfig -c vn0 /tmp/image.iso
	mount -t cd9660 vn0 /iso

	while it could be possible to do something like :

	vnconfig -v -e vn0 /tmp/image.iso mountro=/mnt type=cd9660

	or

	vnconfig -v -e vn0 /tmp/image.iso mountro=/mnt,cd9660

	using the first syntax, the ignore feature has precedence
	over the swap feature which has precedence over the mount*
	features.

	also, these patches correct two bugs in what_opt (-s none
	was a do nothing statement !) and config (the fclose is
	done too late and prevent the fs to be mounted).

Fix: I provide two patches, the first one provides the first
	proposed syntax and the second one provides the second
	proposed syntax (the one I prefer).

----------==========---------- first patch ----------==========----------

----------==========---------- second patch ----------==========----------
How-To-Repeat: 
	already desbribed above.
Comment 1 Poul-Henning Kamp 2001-02-22 06:26:23 UTC
vnconfig(8) is being phased out.  Please consider if this can be integrated in
mdconfig(8) in current.

--
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.
Comment 2 dima 2001-02-22 08:06:53 UTC
> vnconfig(8) is being phased out.  Please consider if this can be
> integrated in mdconfig(8) in current.

mdconfig(8) can't automatically mount the filesystem it configures.  I
offered to implement this some time ago, but noone seemed interested.

					Dima Dorfman
					dima@unixfreak.org
Comment 3 Poul-Henning Kamp 2001-02-22 08:17:08 UTC
In message <20010222080653.5C9363E09@bazooka.unixfreak.org>, Dima Dorfman writes:
>> vnconfig(8) is being phased out.  Please consider if this can be
>> integrated in mdconfig(8) in current.
>
>mdconfig(8) can't automatically mount the filesystem it configures.  I
>offered to implement this some time ago, but noone seemed interested.

"send patches" doesn't count as interested in your book ?  :-)

--
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.
Comment 4 dima 2001-02-23 05:29:33 UTC
> In message <20010222080653.5C9363E09@bazooka.unixfreak.org>, Dima Dorfman wri
> tes:
> >> vnconfig(8) is being phased out.  Please consider if this can be
> >> integrated in mdconfig(8) in current.
> >
> >mdconfig(8) can't automatically mount the filesystem it configures.  I
> >offered to implement this some time ago, but noone seemed interested.
> 
> "send patches" doesn't count as interested in your book ?  :-)

Fair enough.  See attached.  It implements the 'feature' feature (yes,
it's called 'feature') of vnconfig in mdconfig.  I couldn't think of a
better name, so I also called it 'feature'.

Basically, right now, this allows one to configure and mount a memory
disk all in one shot (assuming that what you configured is a real
filesystem, though; in other words, it only makes sense for vnode).
Theoretically, it can be expanded to do things like automatically
label and create a filesystem.  This also includes the functionality
the originator asked for in this PR (although I don't think his patch
works; see below).

The only real hack in this is the way it deals with different
filesystems having different argument structures (last argument to
mount(2)).  This is also why I don't think the patches provided in
this PR work; vnconfig always uses a ufs_args structure as the last
argument to mount(2); if you're trying to mount a cd9660 filesystem,
it will fail because iso_args is longer than ufs_args, so when the
kernel (or something before it) tries to access one of the iso_args
members, it will be accessing junk.  My patch solves the problem by
defining a union of all the argument structures (okay, not all of
them, just the ones I thought would make sense in this context).
Since all the structures have fspec as the first member, this seems to
work, but is quite ugly.

Comments?  Suggestions?

					Dima Dorfman
					dima@unixfreak.org


Index: mdconfig.8
===================================================================
RCS file: /st/src/FreeBSD/src/sbin/mdconfig/mdconfig.8,v
retrieving revision 1.5
diff -u -r1.5 mdconfig.8
--- mdconfig.8	2001/01/28 20:17:46	1.5
+++ mdconfig.8	2001/02/23 04:37:23
@@ -58,6 +58,7 @@
 .Op Fl s Ar size
 .Op Fl f Ar file
 .Op Fl u Ar unit
+.Op feature ...
 .Nm
 .Fl d
 .Fl u Ar unit
@@ -133,6 +134,25 @@
 .Xr md 4
 device to use a specific unit number.
 .El
+.Pp
+A
+.Ar feature
+argument describes an action to be taken after the device is
+successfully configured.  The valid features follow.
+.Bl -tag
+.It Cm mount=rw|ro,fs_type,mount_point
+Mount the configured memory disk on
+.Pa mount_point .
+Since the device must be a valid filesystem of type
+.Va fs_type
+at the time it is configured, this is only useful for disks of type
+.Li vnode .
+If
+.Va fs_type
+is ommited, the type
+.Li ufs
+is assumed.
+.El
 .Sh EXAMPLES
 To create a 4 megabyte
 .Xr malloc 9
@@ -165,6 +185,20 @@
 mount /dev/md10c /tmp
 chmod 1777 /tmp
 .Ed
+.Pp
+To mount a UFS filesystem contained in the file
+.Pa boot.flp
+on
+.Pa /mnt :
+.Pp
+.Dl mdconfig -a -t vnode -f boot.flp mount=ro,,/mnt
+.Pp
+To mount a CD image contained in the file
+.Pa 4.2-install.iso
+on
+.Pa /mnt :
+.Pp
+.Dl mdconfig -a -t vnode -f 4.2-install.iso mount=ro,cd9600,/mnt
 .Sh SEE ALSO
 .Xr md 4 ,
 .Xr disklabel 8 ,
Index: mdconfig.c
===================================================================
RCS file: /st/src/FreeBSD/src/sbin/mdconfig/mdconfig.c,v
retrieving revision 1.6
diff -u -r1.6 mdconfig.c
--- mdconfig.c	2001/01/31 08:41:18	1.6
+++ mdconfig.c	2001/02/23 04:37:23
@@ -10,16 +10,24 @@
  *
  */
 
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <isofs/cd9660/cd9660_mount.h>
+#include <msdosfs/msdosfsmount.h>
+#include <ufs/ufs/ufsmount.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <string.h>
 #include <err.h>
+#include <paths.h>
 #include <sys/ioctl.h>
-#include <sys/param.h>
 #include <sys/mdioctl.h>
 
+int	 f_mount(const char *);
+
 struct md_ioctl mdio;
 
 enum {UNSET, ATTACH, DETACH} action = UNSET;
@@ -28,7 +36,8 @@
 usage()
 {
 	fprintf(stderr, "Usage:\n");
-	fprintf(stderr, "\tmdconfig -a -t type [-o [no]option]... [ -f file] [-s size] [-u unit]\n");
+	fprintf(stderr, "\tmdconfig -a -t type [-o [no]option]... [ -f file] "
+	    "[-s size] [-u unit]\n\t\t[feature ...]\n");
 	fprintf(stderr, "\tmdconfig -d -u unit\n");
 	fprintf(stderr, "\t\ttype = {malloc, preload, vnode, swap}\n");
 	fprintf(stderr, "\t\toption = {cluster, compress, reserve, autounit}\n");
@@ -138,6 +147,8 @@
 			usage();
 		}
 	}
+	argc -= optind;
+	argv += optind;
 
 	fd = open("/dev/mdctl", O_RDWR, 0);
 	if (fd < 0)
@@ -153,6 +164,64 @@
 		err(1, "ioctl(/dev/mdctl)");
 	if (mdio.md_options & MD_AUTOUNIT)
 		printf("md%d\n", mdio.md_unit);
+
+	/* Process 'features'. */
+	for (; argc > 0; argc++)
+	{
+		if (strncmp(argv[0], "mount=", 6) == 0)
+			if (!f_mount(argv[0] + 6))
+				return (1);
+	}
 	return (0);
 }
 
+/*
+ * Process the 'mount' feature.
+ *
+ * Pre-condition: mdio describes a valid and configured device
+ */
+int
+f_mount(const char *params)
+{
+	char *p, *wparams;
+	char *av[3], **avp;
+	char *mttype, *mtpoint, mtdev[MAXPATHLEN];
+	int mtflags = 0;
+	union {
+	    struct ufs_args u;
+	    struct iso_args i;
+	    struct msdosfs_args m;
+	} args;
+
+	memset(&args, '\0', sizeof(args));
+	if ( (wparams = malloc(strlen(params) + 1)) == NULL)
+		err(1, "malloc");
+	strlcpy(wparams, params, strlen(params) + 1);
+
+	for (p = wparams, avp = av;;) {
+		*avp = strsep(&p, ",");
+		if (++avp >= &av[sizeof(av) / sizeof(*av)])
+			break;
+	}
+
+	if (strncmp(av[0], "rw", 2) == 0)
+		;
+	else if (strncmp(av[0], "ro", 2) == 0)
+		mtflags |= MNT_RDONLY;
+	else
+		errx(1, "bad option to mount feature: %s", av[0]);
+	if (*av[1] == '\0')
+		mttype = "ufs";
+	else
+		mttype = av[1];
+	if (*av[2] == '\0')
+		errx(1, "bad mountpoint");
+	mtpoint = av[2];
+
+	snprintf(mtdev, sizeof(mtdev), "%smd%dc", _PATH_DEV, mdio.md_unit);
+	args.u.fspec = mtdev;
+
+	if (mount(mttype, mtpoint, mtflags, &args) == -1)
+		err(1, "mount");
+	return (0);
+}
Comment 5 Craig Rodrigues freebsd_committer freebsd_triage 2005-09-11 17:31:40 UTC
State Changed
From-To: open->closed

vnconfig has been replaced by mdconfig in FreeBSD 5.x and higher.