From: Stanislav Brabec <sbrabec@suse.cz>
To: util-linux@vger.kernel.org
Subject: [PATCH] Use predictable /dev/mapper partition names for /dev/dm-N
Date: Tue, 26 May 2015 17:59:29 +0200 [thread overview]
Message-ID: <55649861.7030501@suse.cz> (raw)
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@suse.cz>
---
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@suse.cz
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
next reply other threads:[~2015-05-26 15:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-26 15:59 Stanislav Brabec [this message]
2015-05-28 10:32 ` [PATCH] Use predictable /dev/mapper partition names for /dev/dm-N Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55649861.7030501@suse.cz \
--to=sbrabec@suse.cz \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox