summaryrefslogtreecommitdiff
path: root/udev/lib/libudev-device.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2008-09-11 17:08:12 +0200
committerKay Sievers <kay.sievers@vrfy.org>2008-09-11 17:08:12 +0200
commit4ad3a37f50ed3af4158cd0d0badbd146eb8e3500 (patch)
tree234ce35efee7e35cd56d1265de7a394161fe45f3 /udev/lib/libudev-device.c
parent17fcfb5972977b6a3aedca6ad2aa8d1fbfbc761d (diff)
udevadm: info - use "udev_device"
Diffstat (limited to 'udev/lib/libudev-device.c')
-rw-r--r--udev/lib/libudev-device.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/udev/lib/libudev-device.c b/udev/lib/libudev-device.c
index 0405e1c98a..f3f20cd992 100644
--- a/udev/lib/libudev-device.c
+++ b/udev/lib/libudev-device.c
@@ -34,8 +34,9 @@
struct udev_device {
int refcount;
struct udev *udev;
- char *devpath;
char *syspath;
+ const char *devpath;
+ const char *sysname;
char *devname;
char *subsystem;
struct list_head link_list;
@@ -193,10 +194,11 @@ struct udev_device *udev_device_new_from_devpath(struct udev *udev, const char *
util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
util_strlcat(path, devpath, sizeof(path));
- if (stat(path, &statbuf) != 0)
- return NULL;
- if (!S_ISDIR(statbuf.st_mode))
+ util_strlcat(path, "/uevent", sizeof(path));
+ if (stat(path, &statbuf) != 0) {
+ info(udev, "not a device :%s\n", path);
return NULL;
+ }
udev_device = device_init(udev);
if (udev_device == NULL)
@@ -214,6 +216,28 @@ struct udev_device *udev_device_new_from_devpath(struct udev *udev, const char *
return udev_device;
}
+struct udev_device *udev_device_new_from_parent(struct udev_device *udev_device)
+{
+ struct udev_device *udev_device_parent = NULL;
+ char path[UTIL_PATH_SIZE];
+ char *pos;
+
+ if (udev_device == NULL)
+ return NULL;
+
+ util_strlcpy(path, udev_device_get_devpath(udev_device), sizeof(path));
+ while (1) {
+ pos = strrchr(path, '/');
+ if (pos == NULL)
+ break;
+ pos[0] = '\0';
+ udev_device_parent = udev_device_new_from_devpath(udev_device->udev, path);
+ if (udev_device_parent != NULL)
+ break;
+ }
+ return udev_device_parent;
+}
+
/**
* udev_device_get_udev:
* @udev_device: udev device
@@ -305,6 +329,13 @@ const char *udev_device_get_syspath(struct udev_device *udev_device)
return udev_device->syspath;
}
+const char *udev_device_get_sysname(struct udev_device *udev_device)
+{
+ if (udev_device == NULL)
+ return NULL;
+ return udev_device->sysname;
+}
+
/**
* udev_device_get_devname:
* @udev_device: udev device
@@ -454,6 +485,9 @@ int device_set_devpath(struct udev_device *udev_device, const char *devpath)
if (asprintf(&udev_device->syspath, "%s%s", udev_get_sys_path(udev_device->udev), devpath) < 0)
return -ENOMEM;
udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))];
+ udev_device->sysname = strrchr(udev_device->syspath, '/');
+ if (udev_device->sysname != NULL)
+ udev_device->sysname = &udev_device->sysname[1];
return 0;
}