cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
cbc4cf
From 5aea6937edf77a753e0d504bb637214e116aaed2 Mon Sep 17 00:00:00 2001
cbc4cf
From: KyleMahlkuch <Kyle.Mahlkuch@ibm.com>
cbc4cf
Date: Mon, 25 Jun 2018 14:52:01 -0500
cbc4cf
Subject: [PATCH 13/14] libfdisk: Fix multipath partition seperators for
cbc4cf
 user-friendly names
cbc4cf
cbc4cf
The current code assumes "-part" is the only partition sepereator
cbc4cf
but this is not true for some distros.
cbc4cf
cbc4cf
For example in Ubuntu 18.04 fdisk does not print the correct names for
cbc4cf
mpatha:
cbc4cf
cbc4cf
~# ls -l /dev/mapper/mpatha*
cbc4cf
lrwxrwxrwx 1 root root 7 Feb  1 04:39 /dev/mapper/mpatha -> ../dm-0
cbc4cf
lrwxrwxrwx 1 root root 7 Feb  1 04:38 /dev/mapper/mpatha1 -> ../dm-4
cbc4cf
lrwxrwxrwx 1 root root 7 Feb  1 04:38 /dev/mapper/mpatha2 -> ../dm-5
cbc4cf
lrwxrwxrwx 1 root root 7 Feb  1 04:38 /dev/mapper/mpatha3 -> ../dm-6
cbc4cf
cbc4cf
~# fdisk -l /dev/mapper/mpatha
cbc4cf
Device                   Boot     Start        End   Sectors  Size Id Type
cbc4cf
/dev/mapper/mpatha-part1           2048  419432447 419430400  200G 83 Linux
cbc4cf
/dev/mapper/mpatha-part2      419432448  838862847 419430400  200G 83 Linux
cbc4cf
/dev/mapper/mpatha-part3      838862848 1258291199 419428352  200G 83 Linux
cbc4cf
cbc4cf
Instead of assuming a partition seperator of "-part" this patch uses
cbc4cf
access to check the file system for a partition seperator of "p" or
cbc4cf
the absense of a partition seperator. If neither of these work the patch
cbc4cf
defaults to "-part" like we had before this patch.
cbc4cf
cbc4cf
Upstream: http://github.com/karelzak/util-linux/commit/73775189767195f1d9f5b6b6f6a54e51f61c4356
cbc4cf
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1655650
cbc4cf
Signed-off-by: Karel Zak <kzak@redhat.com>
cbc4cf
---
cbc4cf
 libfdisk/src/utils.c | 15 ++++++++++++++-
cbc4cf
 1 file changed, 14 insertions(+), 1 deletion(-)
cbc4cf
cbc4cf
diff --git a/libfdisk/src/utils.c b/libfdisk/src/utils.c
cbc4cf
index 5ba9e0466..54e28b2fa 100644
cbc4cf
--- a/libfdisk/src/utils.c
cbc4cf
+++ b/libfdisk/src/utils.c
cbc4cf
@@ -153,7 +153,20 @@ char *fdisk_partname(const char *dev, size_t partno)
cbc4cf
 	if ((strncmp(dev, _PATH_DEV_BYID, sizeof(_PATH_DEV_BYID) - 1) == 0) ||
cbc4cf
 	     strncmp(dev, _PATH_DEV_BYPATH, sizeof(_PATH_DEV_BYPATH) - 1) == 0 ||
cbc4cf
 	     strncmp(dev, "/dev/mapper", sizeof("/dev/mapper") - 1) == 0) {
cbc4cf
-	       p = "-part";
cbc4cf
+		asprintf(&res, "%.*s%zu", w, dev, partno);
cbc4cf
+		if (access(res, F_OK) == 0){
cbc4cf
+			p = "";
cbc4cf
+		} else {
cbc4cf
+			/* check for partition seperator "p" */
cbc4cf
+			p = "p";
cbc4cf
+			free(res);
cbc4cf
+			asprintf(&res, "%.*s%s%zu", w, dev, p, partno);
cbc4cf
+			if (access(res, F_OK) != 0){
cbc4cf
+				/* otherwise, default to "-path" */
cbc4cf
+				p = "-part";
cbc4cf
+			}
cbc4cf
+		}
cbc4cf
+		free(res);
cbc4cf
 	}
cbc4cf
 
cbc4cf
 	if (asprintf(&res, "%.*s%s%zu", w, dev, p, partno) <= 0)
cbc4cf
-- 
cbc4cf
2.17.2
cbc4cf