]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
IMSM/DDF: don't recognised these metadata on partitions.
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index d292a6603a2c2f87791120fae830979d7e2f8ef8..25f1e56ae01d05277765ef6c4779ac08d6a11f75 100644 (file)
--- a/util.c
+++ b/util.c
@@ -302,6 +302,31 @@ void remove_partitions(int fd)
 #endif
 }
 
+int test_partition(int fd)
+{
+       /* Check if fd is a whole-disk or a partition.
+        * BLKPG will return EINVAL on a partition, and BLKPG_DEL_PARTITION
+        * will return ENXIO on an invalid partition number.
+        */
+       struct blkpg_ioctl_arg a;
+       struct blkpg_partition p;
+       a.op = BLKPG_DEL_PARTITION;
+       a.data = (void*)&p;
+       a.datalen = sizeof(p);
+       a.flags = 0;
+       memset(a.data, 0, a.datalen);
+       p.pno = 1<<30;
+       if (ioctl(fd, BLKPG, &a) == 0)
+               /* Very unlikely, but not a partition */
+               return 0;
+       if (errno == ENXIO)
+               /* not a partition */
+               return 0;
+
+       return 1;
+}
+
+
 int enough(int level, int raid_disks, int layout, int clean,
           char *avail, int avail_disks)
 {
@@ -425,7 +450,12 @@ char *__fname_from_uuid(int id[4], int swap, char *buf, char sep)
 
 char *fname_from_uuid(struct supertype *st, struct mdinfo *info, char *buf, char sep)
 {
-       return __fname_from_uuid(info->uuid, st->ss->swapuuid, buf, sep);
+       // dirty hack to work around an issue with super1 superblocks...
+       // super1 superblocks need swapuuid set in order for assembly to
+       // work, but can't have it set if we want this printout to match
+       // all the other uuid printouts in super1.c, so we force swapuuid
+       // to 1 to make our printout match the rest of super1
+       return __fname_from_uuid(info->uuid, (st->ss == &super1) ? 1 : st->ss->swapuuid, buf, sep);
 }
 
 #ifndef MDASSEMBLE