aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sbin/mdconfig/Makefile9
-rw-r--r--sbin/mdconfig/mdconfig.c101
2 files changed, 110 insertions, 0 deletions
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 <bsd.prog.mk>
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):
+ * <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);
+}
+