diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2012-11-02 20:15:39 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2012-11-02 20:15:39 +0400 |
commit | b13154de3eca5ba28fbb4854d916cd0be5febeed (patch) | |
tree | 30f2e9e89ab71a2df837076ac68c3ba770230294 /fdisks/partname.c | |
download | util-linux-upstream.tar.gz |
Imported Upstream version 2.22upstream/2.22upstream
Diffstat (limited to 'fdisks/partname.c')
-rw-r--r-- | fdisks/partname.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/fdisks/partname.c b/fdisks/partname.c new file mode 100644 index 0000000..1671e19 --- /dev/null +++ b/fdisks/partname.c @@ -0,0 +1,48 @@ +#include <ctype.h> +#include <stdio.h> +#include <string.h> + +#include "blkdev.h" +#include "pathnames.h" +#include "common.h" +#include "c.h" + +/* + * return partition name - uses static storage unless buf is supplied + */ +char * +partname(char *dev, int pno, int lth) { + static char bufp[PATH_MAX]; + char *p; + int w, wp; + + w = strlen(dev); + p = ""; + + if (isdigit(dev[w-1])) + p = "p"; + + /* devfs kludge - note: fdisk partition names are not supposed + to equal kernel names, so there is no reason to do this */ + if (strcmp (dev + w - 4, "disc") == 0) { + w -= 4; + p = "part"; + } + + /* udev names partitions by appending -partN + e.g. ata-SAMSUNG_SV8004H_0357J1FT712448-part1 */ + if ((strncmp(dev, _PATH_DEV_BYID, strlen(_PATH_DEV_BYID)) == 0) || + strncmp(dev, _PATH_DEV_BYPATH, strlen(_PATH_DEV_BYPATH)) == 0) { + p = "-part"; + } + + wp = strlen(p); + + if (lth) { + snprintf(bufp, sizeof(bufp), "%*.*s%s%-2u", + lth-wp-2, w, dev, p, pno); + } else { + snprintf(bufp, sizeof(bufp), "%.*s%s%-2u", w, dev, p, pno); + } + return bufp; +} |