summaryrefslogtreecommitdiff
path: root/lib.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2013-08-01 14:32:04 +1000
committerNeilBrown <neilb@suse.de>2013-08-01 14:32:04 +1000
commitbc17158dcc9eac6eed4b84d1f41d1dcaa108cb9b (patch)
tree31d02887a1d5f157272385af8015efbb35c7ee5b /lib.c
parent879982efa90c8cf6b7afc708316cf47c4247bfe3 (diff)
Introduce devid2kname - slightly different to devid2devnm.
The purpose od devid2devnm is to return a kernel name of an md device, whether that device is a whole device or a partition, we want the whole device. md4, never md4p2. In one place I was using devid2devnm where I really wanted the partition if there was one ... and wasn't really interested in it being an md device. So introduce a new 'devid2kname' for that case. Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 8285f346..6808f62d 100644
--- a/lib.c
+++ b/lib.c
@@ -58,6 +58,32 @@ static int mdp_major = -1;
return mdp_major;
}
+char *devid2kname(int devid)
+{
+ char path[30];
+ char link[200];
+ static char devnm[32];
+ char *cp;
+ int n;
+
+ /* Look at the
+ * /sys/dev/block/%d:%d link which must look like
+ * and take the last component.
+ */
+ sprintf(path, "/sys/dev/block/%d:%d", major(devid),
+ minor(devid));
+ n = readlink(path, link, sizeof(link)-1);
+ if (n > 0) {
+ link[n] = 0;
+ cp = strrchr(link, '/');
+ if (cp) {
+ strcpy(devnm, cp+1);
+ return devnm;
+ }
+ }
+ return NULL;
+}
+
char *devid2devnm(int devid)
{
char path[30];