-static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *filename, size_t len)
+static size_t syspath_to_db_path(struct udev_device *udev_device, char *filename, size_t len)
- devpath_to_db_path(udev_device->udev, udev_device->devpath, filename, sizeof(filename));
+ syspath_to_db_path(udev_device, filename, sizeof(filename));
if (lstat(filename, &stats) != 0) {
info(udev_device->udev, "no db file to read %s: %s\n", filename, strerror(errno));
if (lstat(filename, &stats) != 0) {
info(udev_device->udev, "no db file to read %s: %s\n", filename, strerror(errno));
- * Create new udev device, and fill in information from the sysfs
- * device and the udev database entry. The devpath must not contain
- * the sysfs mount path, and must contain a leading '/'.
+ * Create new udev device, and fill in information from the sys
+ * device and the udev database entry. The sypath is the absolute
+ * path to the device, including the sys mount point.
*
* The initial refcount is 1, and needs to be decremented to
* release the ressources of the udev device.
*
* Returns: a new udev device, or #NULL, if it does not exist
**/
*
* The initial refcount is 1, and needs to be decremented to
* release the ressources of the udev device.
*
* Returns: a new udev device, or #NULL, if it does not exist
**/
- util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
- util_strlcat(path, devpath, sizeof(path));
+ util_strlcpy(path, syspath, sizeof(path));
util_strlcat(path, "/uevent", sizeof(path));
if (stat(path, &statbuf) != 0) {
util_strlcat(path, "/uevent", sizeof(path));
if (stat(path, &statbuf) != 0) {
info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
if (device_read_db(udev_device) >= 0)
info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
if (device_read_db(udev_device) >= 0)
while (1) {
pos = strrchr(path, '/');
if (pos == path || pos == NULL)
break;
pos[0] = '\0';
while (1) {
pos = strrchr(path, '/');
if (pos == path || pos == NULL)
break;
pos[0] = '\0';
util_strlcat(path, "/device", sizeof(path));
if (util_resolve_sys_link(udev_device->udev, path, sizeof(path)) == 0) {
util_strlcat(path, "/device", sizeof(path));
if (util_resolve_sys_link(udev_device->udev, path, sizeof(path)) == 0) {
- if (util_get_sys_subsystem(udev_device->udev, udev_device->devpath, subsystem, sizeof(subsystem)) == 0) {
+ if (util_get_sys_subsystem(udev_device->udev, udev_device->syspath, subsystem, sizeof(subsystem)) == 0) {
- if (util_get_sys_driver(udev_device->udev, udev_device->devpath, driver, sizeof(driver)) < 2)
+ if (util_get_sys_driver(udev_device->udev, udev_device->syspath, driver, sizeof(driver)) < 2)
- if (asprintf(&udev_device->syspath, "%s%s", udev_get_sys_path(udev_device->udev), devpath) < 0)
+ const char *pos;
+
+ udev_device->syspath = strdup(syspath);
+ if (udev_device->syspath == NULL)
- udev_device->sysname = strrchr(udev_device->syspath, '/');
- if (udev_device->sysname != NULL)
- udev_device->sysname = &udev_device->sysname[1];
+ pos = strrchr(udev_device->syspath, '/');
+ if (pos == NULL)
+ return -EINVAL;
+ udev_device->sysname = &pos[1];