]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
fix load_super/free_super mismatch in util.c
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index dd8b176ab43558f6f47fc15520bcc8cde206ced8..dbe46404c89ae1d00d649b6ecb02292709e5b879 100644 (file)
--- a/util.c
+++ b/util.c
@@ -730,7 +730,7 @@ struct supertype *super_by_fd(int fd)
        int minor;
        struct supertype *st = NULL;
        struct mdinfo *sra;
-       char *verstr = NULL;
+       char *verstr;
        char version[20];
        int i;
 
@@ -739,11 +739,13 @@ struct supertype *super_by_fd(int fd)
        if (sra) {
                vers = sra->array.major_version;
                minor = sra->array.minor_version;
+               verstr = sra->text_version;
        } else {
                if (ioctl(fd, GET_ARRAY_INFO, &array))
                        array.major_version = array.minor_version = 0;
                vers = array.major_version;
                minor = array.minor_version;
+               verstr = "";
        }
 
        if (vers != -1) {
@@ -816,7 +818,7 @@ struct supertype *guess_super(int fd)
                st->ss = NULL;
                rv = superlist[bestsuper]->load_super(st, fd, NULL);
                if (rv == 0) {
-                       ss->free_super(st);
+                       superlist[bestsuper]->free_super(st);
                        return st;
                }
        }
@@ -828,6 +830,11 @@ struct supertype *guess_super(int fd)
 int get_dev_size(int fd, char *dname, unsigned long long *sizep)
 {
        unsigned long long ldsize;
+       struct stat st;
+
+       if (fstat(fd, &st) != -1 && S_ISREG(st.st_mode))
+               ldsize = (unsigned long long)st.st_size;
+       else
 #ifdef BLKGETSIZE64
        if (ioctl(fd, BLKGETSIZE64, &ldsize) != 0)
 #endif