]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
imsm: fix family number handling
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 35bb91bb0d0b51c7a7541f8cba49197d14b87080..2543971026656ac8afca07c30d3d2f983a4a55a0 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"
@@ -511,14 +506,13 @@ int nftw(const char *path, int (*han)(const char *name, const struct stat *stb,
 /*
  * Find a block device with the right major/minor number.
  * If we find multiple names, choose the shortest.
- * If we find a non-standard name, it is probably there
- * deliberately so prefer it over a standard name.
+ * If we find a name in /dev/md/, we prefer that.
  * This applies only to names for MD devices.
  */
 char *map_dev(int major, int minor, int create)
 {
        struct devmap *p;
-       char *std = NULL, *nonstd=NULL;
+       char *regular = NULL, *preferred=NULL;
        int did_check = 0;
 
        if (major == 0 && minor == 0)
@@ -545,27 +539,27 @@ char *map_dev(int major, int minor, int create)
        for (p=devlist; p; p=p->next)
                if (p->major == major &&
                    p->minor == minor) {
-                       if (is_standard(p->name, NULL)) {
-                               if (std == NULL ||
-                                   strlen(p->name) < strlen(std))
-                                       std = p->name;
+                       if (strncmp(p->name, "/dev/md/",8) == 0) {
+                               if (preferred == NULL ||
+                                   strlen(p->name) < strlen(preferred))
+                                       preferred = p->name;
                        } else {
-                               if (nonstd == NULL ||
-                                   strlen(p->name) < strlen(nonstd))
-                                       nonstd = p->name;
+                               if (regular == NULL ||
+                                   strlen(p->name) < strlen(regular))
+                                       regular = p->name;
                        }
                }
-       if (!std && !nonstd && !did_check) {
+       if (!regular && !preferred && !did_check) {
                devlist_ready = 0;
                goto retry;
        }
-       if (create && !std && !nonstd) {
+       if (create && !regular && !preferred) {
                static char buf[30];
                snprintf(buf, sizeof(buf), "%d:%d", major, minor);
-               nonstd = buf;
+               regular = buf;
        }
 
-       return nonstd ? nonstd : std;
+       return preferred ? preferred : regular;
 }
 
 unsigned long calc_csum(void *super, int bytes)
@@ -916,7 +910,10 @@ struct supertype *super_by_fd(int fd)
                if (sra)
                        sysfs_free(sra);
                sra = sysfs_read(-1, devnum, GET_VERSION);
-               verstr = sra->text_version ? : "-no-metadata-";
+               if (sra && sra->text_version[0])
+                       verstr = sra->text_version;
+               else
+                       verstr = "-no-metadata-";
        }
 
        for (i = 0; st == NULL && superlist[i] ; i++)
@@ -1301,6 +1298,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)
 {