Upload Tizen:Base source
[framework/base/util-linux-ng.git] / fdisk / partname.c
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 #include "blkdev.h"
6 #include "pathnames.h"
7 #include "common.h"
8
9 /*
10  * return partition name - uses static storage unless buf is supplied
11  */
12 char *
13 partname(char *dev, int pno, int lth) {
14         static char bufp[80];
15         char *p;
16         int w, wp;
17
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
31         /* udev names partitions by appending -partN
32            e.g. ata-SAMSUNG_SV8004H_0357J1FT712448-part1 */
33         if ((strncmp(dev, _PATH_DEV_BYID, strlen(_PATH_DEV_BYID)) == 0) ||
34              strncmp(dev, _PATH_DEV_BYPATH, strlen(_PATH_DEV_BYPATH)) == 0) {
35                p = "-part";
36         }
37
38         wp = strlen(p);
39
40         if (lth) {
41                 snprintf(bufp, sizeof(bufp), "%*.*s%s%-2u",
42                          lth-wp-2, w, dev, p, pno);
43         } else {
44                 snprintf(bufp, sizeof(bufp), "%.*s%s%-2u", w, dev, p, pno);
45         }
46         return bufp;
47 }
48