1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-19 10:53:58 +00:00
freebsd/sbin/mdconfig/mdconfig.c
Poul-Henning Kamp 70d586c091 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.
2000-12-28 20:57:57 +00:00

102 lines
2.5 KiB
C

/*
* ----------------------------------------------------------------------------
* "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);
}