]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Add missing 'continue' in Grow_restart.
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 080decc222a970bf36a9e2329c6eb7b27f307678..f646bb9284bf16516d3841386298b85e1dda5482 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1,7 +1,7 @@
 /*
  * mdadm - manage Linux "md" devices aka RAID arrays.
  *
- * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
  *
  *
  *    This program is free software; you can redistribute it and/or modify
  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  *    Author: Neil Brown
- *    Email: <neilb@cse.unsw.edu.au>
- *    Paper: Neil Brown
- *           School of Computer Science and Engineering
- *           The University of New South Wales
- *           Sydney, 2052
- *           Australia
+ *    Email: <neilb@suse.de>
  */
 
 #include       "mdadm.h"
@@ -185,6 +180,40 @@ long long parse_size(char *size)
        return s;
 }
 
+int parse_layout_10(char *layout)
+{
+       int copies, rv;
+       char *cp;
+       /* Parse the layout string for raid10 */
+       /* 'f', 'o' or 'n' followed by a number <= raid_disks */
+       if ((layout[0] !=  'n' && layout[0] != 'f' && layout[0] != 'o') ||
+           (copies = strtoul(layout+1, &cp, 10)) < 1 ||
+           copies > 200 ||
+           *cp)
+               return -1;
+       if (layout[0] == 'n')
+               rv = 256 + copies;
+       else if (layout[0] == 'o')
+               rv = 0x10000 + (copies<<8) + 1;
+       else
+               rv = 1 + (copies<<8);
+       return rv;
+}
+
+int parse_layout_faulty(char *layout)
+{
+       /* Parse the layout string for 'faulty' */
+       int ln = strcspn(layout, "0123456789");
+       char *m = strdup(layout);
+       int mode;
+       m[ln] = 0;
+       mode = map_name(faultylayout, m);
+       if (mode == UnSet)
+               return -1;
+
+       return mode | (atoi(layout+ln)<< ModeShift);
+}
+
 void remove_partitions(int fd)
 {
        /* remove partitions from this block devices.
@@ -899,6 +928,8 @@ void wait_for(char *dev, int fd)
                        return;
                usleep(200000);
        }
+       if (i == 25)
+               dprintf("%s: timeout waiting for %s\n", __func__, dev);
 }
 
 struct superswitch *superlist[] = { &super0, &super1, &super_ddf, &super_imsm, NULL };
@@ -1334,6 +1365,17 @@ int check_env(char *name)
        return 0;
 }
 
+__u32 random32(void)
+{
+       __u32 rv;
+       int rfd = open("/dev/urandom", O_RDONLY);
+       if (rfd < 0 || read(rfd, &rv, 4) != 4)
+               rv = random();
+       if (rfd >= 0)
+               close(rfd);
+       return rv;
+}
+
 #ifndef MDASSEMBLE
 int flush_metadata_updates(struct supertype *st)
 {