diff options
author | phk <phk@FreeBSD.org> | 2000-12-28 20:57:57 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2000-12-28 20:57:57 +0000 |
commit | 4728b0144a044e15a78b3dda4faed46459a31f63 (patch) | |
tree | 07322ba8b0db97339750f6536752e804b896a461 /sbin/mdconfig | |
parent | dec1690e30cd9ad27fc0877094e0a20dd23a8c82 (diff) | |
download | FreeBSD-src-4728b0144a044e15a78b3dda4faed46459a31f63.zip FreeBSD-src-4728b0144a044e15a78b3dda4faed46459a31f63.tar.gz |
Preliminary scaffolding for the new integrated vn+md device driver.
I decided to work on the md(4) driver and integrate the vn(4)
functionality into it mainly based on the name being more suitable.
Ideally 'vd' as in "virtual disk" would probably be the most logical
but our sound-master pointed out that this would cause uncontrollable
fits of giggles in the brits. Another complication would the needed
changes to the ramdisk boot/root functionality.
The vn driver will stay around for some time after I complete this
merge for transition reasons, and I'll make it whine to people that
they should migrate to the md(4) driver for some time before it
dies.
The kernel part of the new md(4) driver will be committed after more
testing.
Diffstat (limited to 'sbin/mdconfig')
-rw-r--r-- | sbin/mdconfig/Makefile | 9 | ||||
-rw-r--r-- | sbin/mdconfig/mdconfig.c | 101 |
2 files changed, 110 insertions, 0 deletions
diff --git a/sbin/mdconfig/Makefile b/sbin/mdconfig/Makefile new file mode 100644 index 0000000..2232153 --- /dev/null +++ b/sbin/mdconfig/Makefile @@ -0,0 +1,9 @@ +# $FreeBSD$ + +PROG= mdconfig +#MAN8= mdconfig.8 +#CFLAGS+= -g -static -Wall +#MLINKS= mdconfig.8 swapfile.8 mdconfig.8 vnconfig.8 +NOMAN= not_yet + +.include <bsd.prog.mk> diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c new file mode 100644 index 0000000..0186e18 --- /dev/null +++ b/sbin/mdconfig/mdconfig.c @@ -0,0 +1,101 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD$ + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <unistd.h> +#include <string.h> +#include <err.h> +#include <sys/ioctl.h> +#include <sys/param.h> +#include <sys/mdioctl.h> + +struct md_ioctl mdio; + +enum {UNSET, ATTACH, DETACH} action = UNSET; + +int +main(int argc, char **argv) +{ + int ch, fd, i; + + mdio.md_options = MD_CLUSTER | MD_AUTOUNIT; + + for (;;) { + ch = getopt(argc, argv, "adf:o:s:t:u:"); + if (ch == -1) + break; + switch (ch) { + case 'a': + action = ATTACH; + break; + case 'd': + action = DETACH; + break; + case 'f': + strncpy(mdio.md_file, optarg, sizeof(mdio.md_file) - 1); + break; + case 'o': + if (!strcmp(optarg, "cluster")) + mdio.md_options |= MD_CLUSTER; + else if (!strcmp(optarg, "nocluster")) + mdio.md_options &= ~MD_CLUSTER; + else if (!strcmp(optarg, "reserve")) + mdio.md_options |= MD_RESERVE; + else if (!strcmp(optarg, "noreserve")) + mdio.md_options &= ~MD_RESERVE; + else if (!strcmp(optarg, "autounit")) + mdio.md_options |= MD_AUTOUNIT; + else if (!strcmp(optarg, "noautounit")) + mdio.md_options &= ~MD_AUTOUNIT; + else + errx(1, "Unknown option."); + break; + case 's': + mdio.md_size = strtoul(optarg, NULL, 0); + break; + case 't': + if (!strcmp(optarg, "malloc")) + mdio.md_type = MD_MALLOC; + else if (!strcmp(optarg, "preload")) + mdio.md_type = MD_PRELOAD; + else if (!strcmp(optarg, "vnode")) + mdio.md_type = MD_VNODE; + else if (!strcmp(optarg, "swap")) + mdio.md_type = MD_SWAP; + else + errx(1, "Unknown type."); + break; + case 'u': + mdio.md_unit = strtoul(optarg, NULL, 0); + mdio.md_options &= ~MD_AUTOUNIT; + break; + default: + errx(1, "Usage: %s [-ad] [-f file] [-o option] [-s size] [-t type ] [-u unit].", argv[0]); + } + } + + fd = open("/dev/mdctl", O_RDWR, 0); + if (fd < 0) + err(1, "/dev/mdctl"); + if (action == ATTACH) + i = ioctl(fd, MDIOCATTACH, &mdio); + else if (action == DETACH) + i = ioctl(fd, MDIOCDETACH, &mdio); + else + errx(1, "Neither -a(ttach) nor -d(etach) options present."); + if (i < 0) + err(1, "ioctl(/dev/mdctl)"); + return (0); +} + |