- if ((dv=map_dev(disk.major, disk.minor, 1))) {
- if ((!st || !st->sb) &&
- (array.raid_disks == 0 ||
- (disk.state & (1<<MD_DISK_ACTIVE)))) {
- /* try to read the superblock from this device
- * to get more info
- */
- int fd2 = dev_open(dv, O_RDONLY);
- if (fd2 >=0 && st &&
- st->ss->load_super(st, fd2, NULL) == 0) {
- st->ss->getinfo_super(st, &info);
- if (array.raid_disks != 0 && /* container */
- (info.array.ctime != array.ctime ||
- info.array.level != array.level))
- st->ss->free_super(st);
- }
- if (fd2 >= 0) close(fd2);
- }
+
+ if (array.raid_disks > 0 &&
+ (disk.state & (1 << MD_DISK_ACTIVE)) == 0)
+ continue;
+
+ dv = map_dev(disk.major, disk.minor, 1);
+ if (!dv)
+ continue;
+
+ fd2 = dev_open(dv, O_RDONLY);
+ if (fd2 < 0)
+ continue;
+
+ if (st->sb)
+ st->ss->free_super(st);
+
+ err = st->ss->load_super(st, fd2, NULL);
+ close(fd2);
+ if (err)
+ continue;
+ if (info)
+ free(info);
+ if (subarray)
+ info = st->ss->container_content(st, subarray);
+ else {
+ info = malloc(sizeof(*info));
+ st->ss->getinfo_super(st, info, NULL);
+ }
+ if (!info)
+ continue;
+
+ if (array.raid_disks != 0 && /* container */
+ (info->array.ctime != array.ctime ||
+ info->array.level != array.level)) {
+ st->ss->free_super(st);
+ continue;
+ }
+ /* some formats (imsm) have free-floating-spares
+ * with a uuid of uuid_zero, they don't
+ * have very good info about the rest of the
+ * container, so keep searching when
+ * encountering such a device. Otherwise, stop
+ * after the first successful call to
+ * ->load_super.
+ */
+ if (memcmp(uuid_zero,
+ info->uuid,
+ sizeof(uuid_zero)) == 0) {
+ st->ss->free_super(st);
+ continue;