]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Add some comments to explain some of the bits of superswitch.
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 6f1620a6132fb51e169e5005693e6e7926173990..08c6bb0b0e977acbb8c2bba724a96f456b1e58cd 100644 (file)
--- a/util.c
+++ b/util.c
@@ -834,30 +834,20 @@ struct supertype *super_by_fd(int fd)
 #endif /* !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) */
 
 
-struct supertype *dup_super(struct supertype *st)
+struct supertype *dup_super(struct supertype *orig)
 {
-       struct supertype *stnew = NULL;
-       char *verstr = NULL;
-       char version[20];
-       int i;
+       struct supertype *st;
 
+       st = malloc(sizeof(*st));
        if (!st)
                return st;
-
-       if (st->ss->text_version)
-               strcpy(version, st->ss->text_version);
-       else if (st->minor_version == -1)
-               sprintf(version, "%d", st->ss->major);
-       else
-               sprintf(version, "%d.%d", st->ss->major, st->minor_version);
-       verstr = version;
-
-       for (i = 0; stnew == NULL && superlist[i] ; i++)
-               stnew = superlist[i]->match_metadata_desc(verstr);
-
-       if (stnew)
-               stnew->sb = NULL;
-       return stnew;
+       memset(st, 0, sizeof(*st));
+       st->ss = orig->ss;
+       st->max_devs = orig->max_devs;
+       st->minor_version = orig->minor_version;
+       st->sb = NULL;
+       st->info = NULL;
+       return st;
 }
 
 struct supertype *guess_super(int fd)
@@ -872,11 +862,10 @@ struct supertype *guess_super(int fd)
        int i;
 
        st = malloc(sizeof(*st));
-       memset(st, 0, sizeof(*st));
        for (i=0 ; superlist[i]; i++) {
                int rv;
                ss = superlist[i];
-               st->ss = NULL;
+               memset(st, 0, sizeof(*st));
                rv = ss->load_super(st, fd, NULL);
                if (rv == 0) {
                        struct mdinfo info;
@@ -891,7 +880,7 @@ struct supertype *guess_super(int fd)
        }
        if (bestsuper != -1) {
                int rv;
-               st->ss = NULL;
+               memset(st, 0, sizeof(*st));
                rv = superlist[bestsuper]->load_super(st, fd, NULL);
                if (rv == 0) {
                        superlist[bestsuper]->free_super(st);