]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super0.c
Support --uuid= with --create to choose your own UUID.
[thirdparty/mdadm.git] / super0.c
index 770d96e990ec492ea6b71154d2a19d219644bcea..757d9056672b2f1110acbdae5ea2d08da19fde73 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -505,11 +505,11 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update,
 
 
 static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
-                      unsigned long long size, char *ignored_name, char *homehost)
+                      unsigned long long size, char *ignored_name, char *homehost,
+                      int *uuid)
 {
        mdp_super_t *sb = malloc(MD_SB_BYTES + sizeof(bitmap_super_t));
        int spares;
-       int rfd;
        memset(sb, 0, MD_SB_BYTES + sizeof(bitmap_super_t));
 
        if (info->major_version == -1) {
@@ -525,14 +525,11 @@ static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
                return 0;
        }
 
-       rfd = open("/dev/urandom", O_RDONLY);
        sb->md_magic = MD_SB_MAGIC;
        sb->major_version = 0;
        sb->minor_version = 90;
        sb->patch_version = 0;
        sb->gvalid_words = 0; /* ignored */
-       if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4)
-               sb->set_uuid0 = random();
        sb->ctime = time(0);
        sb->level = info->level;
        if (size != info->size)
@@ -542,13 +539,23 @@ static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
        sb->raid_disks = info->raid_disks;
        sb->md_minor = info->md_minor;
        sb->not_persistent = 0;
-       if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
-               sb->set_uuid1 = random();
-               sb->set_uuid2 = random();
-               sb->set_uuid3 = random();
+       if (uuid) {
+               sb->set_uuid0 = uuid[0];
+               sb->set_uuid1 = uuid[1];
+               sb->set_uuid2 = uuid[2];
+               sb->set_uuid3 = uuid[3];
+       } else {
+               int rfd = open("/dev/urandom", O_RDONLY);
+               if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4)
+                       sb->set_uuid0 = random();
+               if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
+                       sb->set_uuid1 = random();
+                       sb->set_uuid2 = random();
+                       sb->set_uuid3 = random();
+               }
+               if (rfd >= 0)
+                       close(rfd);
        }
-       if (rfd >= 0)
-               close(rfd);
        if (homehost) {
                char buf[20];
                char *hash = sha1_buffer(homehost,