udev: add helper udev_device_new_from_stat_rdev()

This is a simple wrapper around udev_device_new_from_devnum(), and uses
the data from a struct stat's .st_rdev field to derive the udev_device
object.
This commit is contained in:
Lennart Poettering
2018-06-07 13:36:19 +02:00
parent 34c20ee09f
commit e5ca27b772
5 changed files with 50 additions and 22 deletions
+23
View File
@@ -42,3 +42,26 @@ int udev_parse_config(void) {
return 0;
}
int udev_device_new_from_stat_rdev(struct udev *udev, const struct stat *st, struct udev_device **ret) {
struct udev_device *nd;
char type;
assert(udev);
assert(st);
assert(ret);
if (S_ISBLK(st->st_mode))
type = 'b';
else if (S_ISCHR(st->st_mode))
type = 'c';
else
return -ENOTTY;
nd = udev_device_new_from_devnum(udev, type, st->st_rdev);
if (!nd)
return -errno;
*ret = nd;
return 0;
}
+2
View File
@@ -21,3 +21,5 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl_msg*, udev_ctrl_msg_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_monitor*, udev_monitor_unref);
int udev_parse_config(void);
int udev_device_new_from_stat_rdev(struct udev *udev, const struct stat *st, struct udev_device **ret);