diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 2596410433..1e41773bba 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -843,6 +843,22 @@ int device_new_from_synthetic_event(sd_device **new_device, const char *syspath, return 0; } +int device_new_from_stat_rdev(sd_device **ret, const struct stat *st) { + char type; + + assert(ret); + assert(st); + + if (S_ISBLK(st->st_mode)) + type = 'b'; + else if (S_ISCHR(st->st_mode)) + type = 'c'; + else + return -ENOTTY; + + return sd_device_new_from_devnum(ret, type, st->st_rdev); +} + int device_copy_properties(sd_device *device_dst, sd_device *device_src) { const char *property, *value; int r; diff --git a/src/libsystemd/sd-device/device-private.h b/src/libsystemd/sd-device/device-private.h index 22d7d8013e..7e4a78e067 100644 --- a/src/libsystemd/sd-device/device-private.h +++ b/src/libsystemd/sd-device/device-private.h @@ -3,12 +3,14 @@ #include #include +#include #include #include "sd-device.h" int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len); int device_new_from_strv(sd_device **ret, char **strv); +int device_new_from_stat_rdev(sd_device **ret, const struct stat *st); int device_get_id_filename(sd_device *device, const char **ret);