]>
Commit | Line | Data |
---|---|---|
22853e4a KZ |
1 | #include <ctype.h> |
2 | #include <stdio.h> | |
3 | #include <string.h> | |
929f243f | 4 | |
6ee3f81f | 5 | #include "blkdev.h" |
525dd316 | 6 | #include "pathnames.h" |
22853e4a KZ |
7 | #include "common.h" |
8 | ||
9 | /* | |
10 | * return partition name - uses static storage unless buf is supplied | |
11 | */ | |
19eecef2 KZ |
12 | char * |
13 | partname(char *dev, int pno, int lth) { | |
14 | static char bufp[80]; | |
22853e4a KZ |
15 | char *p; |
16 | int w, wp; | |
17 | ||
22853e4a KZ |
18 | w = strlen(dev); |
19 | p = ""; | |
20 | ||
21 | if (isdigit(dev[w-1])) | |
22 | p = "p"; | |
23 | ||
24 | /* devfs kludge - note: fdisk partition names are not supposed | |
25 | to equal kernel names, so there is no reason to do this */ | |
26 | if (strcmp (dev + w - 4, "disc") == 0) { | |
27 | w -= 4; | |
28 | p = "part"; | |
29 | } | |
30 | ||
4fd4e8d3 MK |
31 | /* udev names partitions by appending -partN |
32 | e.g. ata-SAMSUNG_SV8004H_0357J1FT712448-part1 */ | |
525dd316 KZ |
33 | if ((strncmp(dev, _PATH_DEV_BYID, strlen(_PATH_DEV_BYID)) == 0) || |
34 | strncmp(dev, _PATH_DEV_BYPATH, strlen(_PATH_DEV_BYPATH)) == 0) { | |
4fd4e8d3 MK |
35 | p = "-part"; |
36 | } | |
37 | ||
22853e4a | 38 | wp = strlen(p); |
19eecef2 | 39 | |
22853e4a | 40 | if (lth) { |
19eecef2 | 41 | snprintf(bufp, sizeof(bufp), "%*.*s%s%-2u", |
63cccae4 | 42 | lth-wp-2, w, dev, p, pno); |
22853e4a | 43 | } else { |
19eecef2 | 44 | snprintf(bufp, sizeof(bufp), "%.*s%s%-2u", w, dev, p, pno); |
22853e4a KZ |
45 | } |
46 | return bufp; | |
47 | } | |
48 |