]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Examine.c
Sort mdstat entries so that composites are well-ordered.
[thirdparty/mdadm.git] / Examine.c
index 8f15a759875dab1e8f504617840098b7d303f231..fcfb02b8d006a1d707758f6247f84e4201b4c0a3 100644 (file)
--- a/Examine.c
+++ b/Examine.c
@@ -51,17 +51,18 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust, struct su
         *   utime, state etc
         *
         * If (brief) gather devices for same array and just print a mdadm.conf line including devices=
-        * if devlist==NULL, use conf_get_devs(
+        * if devlist==NULL, use conf_get_devs()
         */
        int fd; 
        void *super = NULL;
        int rv = 0;
-       int err;
+       int err = 0;
 
        struct array {
                void *super;
                struct supertype *st;
                struct mdinfo info;
+               struct mddev_ident_s ident;
                void *devs;
                struct array *next;
                int spares;
@@ -70,7 +71,7 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust, struct su
        for (; devlist ; devlist=devlist->next) {
                struct supertype *st = forcest;
 
-               fd = open(devlist->devname, O_RDONLY);
+               fd = dev_open(devlist->devname, O_RDONLY);
                if (fd < 0) {
                        if (!scan)
                                fprintf(stderr,Name ": cannot open %s: %s\n",
@@ -82,16 +83,20 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust, struct su
                                st = guess_super(fd);
                        if (st)
                                err = st->ss->load_super(st, fd, &super, (brief||scan)?NULL:devlist->devname);
-                       else
+                       else {
+                               if (!brief)
+                                       fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname);
                                err = 1;
+                       }
                        close(fd);
                }
-               if (err)
+               if (err) {
+                       rv = 1;
                        continue;
-               if (err) rv =1;
+               }
 
                if (SparcAdjust)
-                       st->ss->update_super(NULL, super, "sparc2.2", devlist->devname, 0);
+                       st->ss->update_super(NULL, super, "sparc2.2", devlist->devname,  0);
                /* Ok, its good enough to try, though the checksum could be wrong */
                if (brief) {
                        struct array *ap;
@@ -108,9 +113,9 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust, struct su
                                ap->spares = 0;
                                ap->st = st;
                                arrays = ap;
-                               st->ss->getinfo_super(&ap->info, super);
+                               st->ss->getinfo_super(&ap->info, &ap->ident, super);
                        } else {
-                               st->ss->getinfo_super(&ap->info, super);
+                               st->ss->getinfo_super(&ap->info, &ap->ident, super);
                                free(super);
                        }
                        if (!(ap->info.disk.state & MD_DISK_SYNC))
@@ -139,7 +144,8 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust, struct su
                        }
                        free(ap->super);
                        /* FIXME free ap */
-                       printf("\n");
+                       if (ap->spares || brief > 1)
+                               printf("\n");
                }
        }
        return rv;