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;
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)
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
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
**/
const char *udev_device_get_subsystem(struct udev_device *udev_device)
{
- char subsystem[UTIL_PATH_SIZE];
+ char subsystem[UTIL_NAME_SIZE];
if (udev_device == NULL)
return NULL;
if (udev_device == NULL)
return -1;
list_for_each_entry(name_loop, &udev_device->env_list, node) {
- char name[UTIL_PATH_SIZE];
+ char name[UTIL_NAME_SIZE];
char *val;
strncpy(name, name_loop->name, sizeof(name));
const char *udev_device_get_driver(struct udev_device *udev_device)
{
- char driver[UTIL_PATH_SIZE];
+ char driver[UTIL_NAME_SIZE];
if (udev_device == NULL)
return NULL;
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;
}