It is impossible to predict /dev/dm-N partition names. Use predictable and better readable /dev/mapper names instead. Signed-off-by: Stanislav Brabec <sbrabec@xxxxxxx> --- libfdisk/src/utils.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libfdisk/src/utils.c b/libfdisk/src/utils.c index 4789dbd..569ee50 100644 --- a/libfdisk/src/utils.c +++ b/libfdisk/src/utils.c @@ -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,13 @@ 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; + + if (dev_mapped) + free(dev_mapped); - return NULL; + return res; } #ifdef TEST_PROGRAM -- 2.4.1 -- Best Regards / S pozdravem, Stanislav Brabec software developer --------------------------------------------------------------------- SUSE LINUX, s. r. o. e-mail: sbrabec@xxxxxxx Lihovarská 1060/12 tel: +49 911 7405384547 190 00 Praha 9 fax: +420 284 084 001 Czech Republic http://www.suse.cz/ PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html