]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: Fix multipath partition seperators for user-friendly names
authorKyleMahlkuch <Kyle.Mahlkuch@ibm.com>
Mon, 25 Jun 2018 19:52:01 +0000 (14:52 -0500)
committerKarel Zak <kzak@redhat.com>
Wed, 4 Jul 2018 13:08:00 +0000 (15:08 +0200)
The current code assumes "-part" is the only partition sepereator
but this is not true for some distros.

For example in Ubuntu 18.04 fdisk does not print the correct names for
mpatha:

~# ls -l /dev/mapper/mpatha*
lrwxrwxrwx 1 root root 7 Feb  1 04:39 /dev/mapper/mpatha -> ../dm-0
lrwxrwxrwx 1 root root 7 Feb  1 04:38 /dev/mapper/mpatha1 -> ../dm-4
lrwxrwxrwx 1 root root 7 Feb  1 04:38 /dev/mapper/mpatha2 -> ../dm-5
lrwxrwxrwx 1 root root 7 Feb  1 04:38 /dev/mapper/mpatha3 -> ../dm-6

~# fdisk -l /dev/mapper/mpatha
Device                   Boot     Start        End   Sectors  Size Id Type
/dev/mapper/mpatha-part1           2048  419432447 419430400  200G 83 Linux
/dev/mapper/mpatha-part2      419432448  838862847 419430400  200G 83 Linux
/dev/mapper/mpatha-part3      838862848 1258291199 419428352  200G 83 Linux

Instead of assuming a partition seperator of "-part" this patch uses
access to check the file system for a partition seperator of "p" or
the absense of a partition seperator. If neither of these work the patch
defaults to "-part" like we had before this patch.

libfdisk/src/utils.c

index 5ba9e046680e5db589e7049b5fbbc4c5fa8a1b9f..54e28b2fa8130bde403710b3f02a8f2627cd593d 100644 (file)
@@ -153,7 +153,20 @@ char *fdisk_partname(const char *dev, size_t partno)
        if ((strncmp(dev, _PATH_DEV_BYID, sizeof(_PATH_DEV_BYID) - 1) == 0) ||
             strncmp(dev, _PATH_DEV_BYPATH, sizeof(_PATH_DEV_BYPATH) - 1) == 0 ||
             strncmp(dev, "/dev/mapper", sizeof("/dev/mapper") - 1) == 0) {
-              p = "-part";
+               asprintf(&res, "%.*s%zu", w, dev, partno);
+               if (access(res, F_OK) == 0){
+                       p = "";
+               } else {
+                       /* check for partition seperator "p" */
+                       p = "p";
+                       free(res);
+                       asprintf(&res, "%.*s%s%zu", w, dev, p, partno);
+                       if (access(res, F_OK) != 0){
+                               /* otherwise, default to "-path" */
+                               p = "-part";
+                       }
+               }
+               free(res);
        }
 
        if (asprintf(&res, "%.*s%s%zu", w, dev, p, partno) <= 0)