]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: Use predictable /dev/mapper partition names for /dev/dm-N
authorStanislav Brabec <sbrabec@suse.cz>
Tue, 26 May 2015 15:59:29 +0000 (17:59 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 28 May 2015 08:25:58 +0000 (10:25 +0200)
It is impossible to predict /dev/dm-N partition names. Use predictable
and better readable /dev/mapper names instead.

[kzak@redhat.com: - remove if-before-free]

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/utils.c

index 4789dbd22659f7af2ba4761642689af3eae349b8..5feea53f60eda413a050db91043e22d2aaf05e57 100644 (file)
@@ -1,6 +1,7 @@
 
 #include "fdiskP.h"
 #include "pathnames.h"
+#include "canonicalize.h"
 
 #include <ctype.h>
 
@@ -115,6 +116,7 @@ char *fdisk_partname(const char *dev, size_t partno)
 {
        char *res = NULL;
        const char *p = "";
+       char *dev_mapped = NULL;
        int w = 0;
 
        if (!dev || !*dev) {
@@ -123,6 +125,13 @@ char *fdisk_partname(const char *dev, size_t partno)
                return NULL;
        }
 
+       /* It is impossible to predict /dev/dm-N partition names. */
+       if (strncmp(dev, "/dev/dm-", sizeof("/dev/dm-") - 1) == 0) {
+               dev_mapped = canonicalize_dm_name (dev + 5);
+               if (dev_mapped)
+                       dev = dev_mapped;
+       }
+
        w = strlen(dev);
        if (isdigit(dev[w - 1]))
 #ifdef __GNU__
@@ -147,10 +156,11 @@ char *fdisk_partname(const char *dev, size_t partno)
               p = "-part";
        }
 
-       if (asprintf(&res, "%.*s%s%zu", w, dev, p, partno) > 0)
-               return res;
+       if (asprintf(&res, "%.*s%s%zu", w, dev, p, partno) <= 0)
+               res = NULL;
 
-       return NULL;
+       free(dev_mapped);
+       return res;
 }
 
 #ifdef TEST_PROGRAM