summaryrefslogtreecommitdiff
path: root/sbin/bioctl
diff options
context:
space:
mode:
authorMarco Peereboom <marco@cvs.openbsd.org>2007-05-28 21:54:27 +0000
committerMarco Peereboom <marco@cvs.openbsd.org>2007-05-28 21:54:27 +0000
commitf9d5dd59fac138e2871d535e050b26f89aed3b78 (patch)
treee64d707e4b4a2d1d1b6396317d5e38d0be8e8fb6 /sbin/bioctl
parent3561557542a91f2763cb6350bae4709e565c845c (diff)
Make disk assembly smarter and add two qualifiers to it:
1) noautoassemble; when set the softraid volume will not be assembled during autoconf. 2) force; when set it will overwrite metadata on disk While writing this I ran into 3 bugs that were fixed along the way 1) bcopy in sr_read_meta was copying data to the wrong pointer 2) in sr_read_meta the wrong metadata was coppied into the chunk 3) sr_free_discipline was freing a pointer that wasn't malloc'd ok dlg
Diffstat (limited to 'sbin/bioctl')
-rw-r--r--sbin/bioctl/bioctl.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/sbin/bioctl/bioctl.c b/sbin/bioctl/bioctl.c
index c14bbb97158..01a4b02215c 100644
--- a/sbin/bioctl/bioctl.c
+++ b/sbin/bioctl/bioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bioctl.c,v 1.54 2007/05/23 21:27:13 marco Exp $ */
+/* $OpenBSD: bioctl.c,v 1.55 2007/05/28 21:54:26 marco Exp $ */
/*
* Copyright (c) 2004, 2005 Marco Peereboom
@@ -64,10 +64,12 @@ void bio_setstate(char *);
void bio_setblink(char *, char *, int);
void bio_blink(char *, int, int);
void bio_createraid(u_int16_t, char *);
+u_int32_t bio_createflags(char *);
int devh = -1;
int human;
int verbose;
+u_int32_t cflags = 0;
struct bio_locate bl;
@@ -86,7 +88,7 @@ main(int argc, char *argv[])
if (argc < 2)
usage();
- while ((ch = getopt(argc, argv, "b:c:l:u:H:ha:iv")) != -1) {
+ while ((ch = getopt(argc, argv, "b:C:c:l:u:H:ha:iv")) != -1) {
switch (ch) {
case 'a': /* alarm */
func |= BIOC_ALARM;
@@ -97,6 +99,9 @@ main(int argc, char *argv[])
blink = BIOC_SBBLINK;
bl_arg = optarg;
break;
+ case 'C': /* creation flags */
+ cflags = bio_createflags(optarg);
+ break;
case 'c': /* create */
func |= BIOC_CREATERAID;
cr_level = atoi(optarg);
@@ -609,9 +614,8 @@ bio_createraid(u_int16_t level, char *dev_list)
create.bc_level = level;
create.bc_dev_list_len = no_dev * sizeof(dev_t);
create.bc_dev_list = dt;
- create.bc_flags = BIOC_SCDEVT;
+ create.bc_flags = BIOC_SCDEVT | cflags;
- printf("ioctl\n");
rv = ioctl(devh, BIOCCREATERAID, &create);
if (rv == -1) {
warn("BIOCCREATERAID");
@@ -660,3 +664,39 @@ bio_parse_devlist(char *lst, dev_t *dt)
return (no_dev);
}
+
+u_int32_t
+bio_createflags(char *lst)
+{
+ char *s, *e, fs[32];
+ u_int32_t sz = 0;
+ u_int32_t flags = 0;
+
+ if (!lst)
+ errx(1, "invalid flags list");
+
+ s = e = lst;
+ /* make sure we have a valid flags list like force,noassemeble */
+ while (*e != '\0') {
+ if (*e == ',')
+ s = e + 1;
+ else if (*(e + 1) == '\0' || *(e + 1) == ',') {
+ /* got one */
+ sz = e - s + 1;
+ switch (s[0]) {
+ case 'f':
+ flags |= BIOC_SCFORCE;
+ break;
+ case 'n':
+ flags |= BIOC_SCNOAUTOASSEMBLE;
+ break;
+ default:
+ strlcpy(fs, s, sz + 1);
+ errx(1, "invalid flag %s", fs);
+ }
+ }
+ e++;
+ }
+
+ return (flags);
+}