chiark / gitweb /
libudev: add udev_device_new_from_devnum()
[elogind.git] / udev / lib / libudev-device.c
index 782d6625497675430894d03908b585a546413b03..8103c7fcc46448c5812a5a393afa8217c9b83d7f 100644 (file)
@@ -17,8 +17,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
@@ -218,6 +216,20 @@ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *
        return udev_device;
 }
 
+struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum)
+{
+       char path[UTIL_PATH_SIZE];
+
+       snprintf(path, sizeof(path), "%s/dev/%s/%u:%u",
+                udev_get_sys_path(udev),
+                type == 'b' ? "block" : "char",
+                major(devnum), minor(devnum));
+       if (util_resolve_sys_link(udev, path, sizeof(path)) < 0)
+               return NULL;
+
+       return udev_device_new_from_syspath(udev, path);
+}
+
 static struct udev_device *device_new_from_parent(struct udev_device *udev_device)
 {
        struct udev_device *udev_device_parent = NULL;
@@ -363,7 +375,7 @@ const char *udev_device_get_sysname(struct udev_device *udev_device)
 }
 
 /**
- * udev_device_get_devname:
+ * udev_device_get_devnode:
  * @udev_device: udev device
  *
  * Retrieve the device node file name belonging to the udev device.
@@ -371,7 +383,7 @@ const char *udev_device_get_sysname(struct udev_device *udev_device)
  *
  * Returns: the device node file name of the udev device, or #NULL if no device node exists
  **/
-const char *udev_device_get_devname(struct udev_device *udev_device)
+const char *udev_device_get_devnode(struct udev_device *udev_device)
 {
        if (udev_device == NULL)
                return NULL;
@@ -397,7 +409,7 @@ const char *udev_device_get_subsystem(struct udev_device *udev_device)
                return udev_device->subsystem;
 
        /* read "subsytem" link */
-       if (util_get_sys_subsystem(udev_device->udev, udev_device->syspath, subsystem, sizeof(subsystem)) == 0) {
+       if (util_get_sys_subsystem(udev_device->udev, udev_device->syspath, subsystem, sizeof(subsystem)) > 0) {
                udev_device->subsystem = strdup(subsystem);
                return udev_device->subsystem;
        }