diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-06-04 22:52:02 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-06-07 13:36:19 +0200 |
commit | e5ca27b772267bd18109eb460fb6653a920e551e (patch) | |
tree | e0a23f07c1ae580171d27e82a5e7763d52ea4bdf /src/shared/udev-util.c | |
parent | core: split out device validation from device_found_node() (diff) | |
download | systemd-e5ca27b772267bd18109eb460fb6653a920e551e.tar.xz systemd-e5ca27b772267bd18109eb460fb6653a920e551e.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | src/shared/udev-util.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index 29484226c6..a5ed8e8f6b 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -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; +} |