From 70d586c091f4e0f2c27e1b183310da49bbbc185b Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Thu, 28 Dec 2000 20:57:57 +0000 Subject: [PATCH] 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. --- sbin/mdconfig/Makefile | 9 ++++ sbin/mdconfig/mdconfig.c | 101 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 sbin/mdconfig/Makefile create mode 100644 sbin/mdconfig/mdconfig.c diff --git a/sbin/mdconfig/Makefile b/sbin/mdconfig/Makefile new file mode 100644 index 000000000000..2232153b75bd --- /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 diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c new file mode 100644 index 000000000000..0186e187fd1e --- /dev/null +++ b/sbin/mdconfig/mdconfig.c @@ -0,0 +1,101 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +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); +} +