]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Release 1.8.1 after some man page updates and other fixes.
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index bb4a4794b823ac96d74226386bd4f01911b257fc..010764ea0661b5a8c0a7fbaa326e29fa9e9621da 100644 (file)
--- a/util.c
+++ b/util.c
@@ -386,6 +386,15 @@ unsigned long calc_csum(void *super, int bytes)
        for(i=0; i<bytes/4; i++)
                newcsum+= superc[i];
        csum = (newcsum& 0xffffffff) + (newcsum>>32);
+#ifdef __alpha__
+/* The in-kernel checksum calculation is always 16bit on 
+ * the alpha, though it is 32 bit on i386...
+ * I wonder what it is elsewhere... (it uses and API in
+ * a way that it shouldn't).
+ */
+       csum = (csum & 0xffff) + (csum >> 16);
+       csum = (csum & 0xffff) + (csum >> 16);
+#endif
        return csum;
 }
 
@@ -544,6 +553,8 @@ struct supertype *guess_super(int fd)
         */
        struct superswitch  *ss;
        struct supertype *st;
+       unsigned long besttime = 0;
+       int bestsuper = -1;
        
        void *sbp = NULL;
        int i;
@@ -554,10 +565,26 @@ struct supertype *guess_super(int fd)
                int rv;
                ss = superlist[i];
                rv = ss->load_super(st, fd, &sbp, NULL);
+               if (rv == 0) {
+                       struct mdinfo info;
+                       ss->getinfo_super(&info, sbp);
+                       if (bestsuper == -1 ||
+                           besttime < info.array.ctime) {
+                               bestsuper = i;
+                               besttime = info.array.ctime;
+                               st->ss = NULL;
+                       }
+                       free(sbp);
+               }
+       }
+       if (bestsuper != -1) {
+               int rv;
+               rv = superlist[bestsuper]->load_super(st, fd, &sbp, NULL);
                if (rv == 0) {
                        free(sbp);
                        return st;
                }
        }
+       free(st);
        return NULL;
 }