summaryrefslogtreecommitdiff
path: root/udev
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2008-09-09 18:14:54 +0200
committerKay Sievers <kay.sievers@vrfy.org>2008-09-09 18:14:54 +0200
commit95d90c4fe0581d8b630c62e38591b3af960d131a (patch)
tree8f15713aa846bea364dd26351cc92f5c4f66ea31 /udev
parent9b3a33a9ff9386b4af3229762fa7673e670b00e7 (diff)
libudev: udev_device - read "driver" value
Diffstat (limited to 'udev')
-rw-r--r--udev/lib/libudev-device.c7
-rw-r--r--udev/lib/libudev-private.h1
-rw-r--r--udev/lib/libudev-utils.c16
-rw-r--r--udev/lib/test-libudev.c2
4 files changed, 24 insertions, 2 deletions
diff --git a/udev/lib/libudev-device.c b/udev/lib/libudev-device.c
index 00b9440386..578afe7ec2 100644
--- a/udev/lib/libudev-device.c
+++ b/udev/lib/libudev-device.c
@@ -346,8 +346,15 @@ int udev_device_get_properties(struct udev_device *udev_device,
const char *udev_device_get_driver(struct udev_device *udev_device)
{
+ char driver[NAME_SIZE];
+
if (udev_device == NULL)
return NULL;
+ if (udev_device->driver != NULL)
+ return udev_device->driver;
+ if (util_get_sys_driver(udev_device->udev, udev_device->devpath, driver, sizeof(driver)) < 2)
+ return NULL;
+ udev_device->driver = strdup(driver);
return udev_device->driver;
}
diff --git a/udev/lib/libudev-private.h b/udev/lib/libudev-private.h
index 53a58cc619..bc91927bed 100644
--- a/udev/lib/libudev-private.h
+++ b/udev/lib/libudev-private.h
@@ -99,4 +99,5 @@ extern int udev_ctrl_get_set_max_childs(struct udev_ctrl_msg *ctrl_msg);
/* libudev-utils */
extern ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size);
+extern ssize_t util_get_sys_driver(struct udev *udev, const char *devpath, char *driver, size_t size);
#endif
diff --git a/udev/lib/libudev-utils.c b/udev/lib/libudev-utils.c
index 8251b64da9..82acb1a481 100644
--- a/udev/lib/libudev-utils.c
+++ b/udev/lib/libudev-utils.c
@@ -32,7 +32,7 @@
#include "libudev-private.h"
#include "../udev.h"
-ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size)
+static ssize_t get_sys_link(struct udev *udev, const char *slink, const char *devpath, char *subsystem, size_t size)
{
char path[PATH_SIZE];
ssize_t len;
@@ -40,7 +40,8 @@ ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *sub
strlcpy(path, udev_get_sys_path(udev), sizeof(path));
strlcat(path, devpath, sizeof(path));
- strlcat(path, "/subsystem", sizeof(path));
+ strlcat(path, "/", sizeof(path));
+ strlcat(path, slink, sizeof(path));
len = readlink(path, path, sizeof(path));
if (len < 0 || len >= (ssize_t) sizeof(path))
return -1;
@@ -51,3 +52,14 @@ ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *sub
pos = &pos[1];
return strlcpy(subsystem, pos, size);
}
+
+ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size)
+{
+ return get_sys_link(udev, "subsystem", devpath, subsystem, size);
+}
+
+ssize_t util_get_sys_driver(struct udev *udev, const char *devpath, char *driver, size_t size)
+{
+ return get_sys_link(udev, "driver", devpath, driver, size);
+}
+
diff --git a/udev/lib/test-libudev.c b/udev/lib/test-libudev.c
index 835536af84..4fdef68881 100644
--- a/udev/lib/test-libudev.c
+++ b/udev/lib/test-libudev.c
@@ -58,6 +58,8 @@ static void print_device(struct udev_device *device)
printf("devpath: '%s'\n", str);
str = udev_device_get_subsystem(device);
printf("subsystem: '%s'\n", str);
+ str = udev_device_get_driver(device);
+ printf("driver: '%s'\n", str);
str = udev_device_get_syspath(device);
printf("syspath: '%s'\n", str);
str = udev_device_get_devname(device);