Date: Thu, 22 Feb 2001 21:30:02 -0800 (PST) From: Dima Dorfman <dima@unixfreak.org> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/25273: add fs type feature to vnconfig(8) to allow direct mount of iso images and co. Message-ID: <200102230530.f1N5U2c04134@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/25273; it has been noted by GNATS. From: Dima Dorfman <dima@unixfreak.org> To: Poul-Henning Kamp <phk@critter.freebsd.dk> Cc: freebsd-gnats-submit@freebsd.org Subject: Re: bin/25273: add fs type feature to vnconfig(8) to allow direct mount of iso images and co. Date: Thu, 22 Feb 2001 21:29:33 -0800 > 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); +} To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102230530.f1N5U2c04134>