summaryrefslogtreecommitdiffstats
path: root/src/libsystemd/sd-device/sd-device.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd/sd-device/sd-device.c')
-rw-r--r--src/libsystemd/sd-device/sd-device.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index a3a498f9e2..bf9397c03d 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -43,7 +43,7 @@ int device_new_aux(sd_device **ret) {
.devmode = (mode_t) -1,
.devuid = (uid_t) -1,
.devgid = (gid_t) -1,
- .action = _DEVICE_ACTION_INVALID,
+ .action = _SD_DEVICE_ACTION_INVALID,
};
*ret = device;
@@ -316,6 +316,22 @@ _public_ int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *s
return -ENODEV;
}
+_public_ int sd_device_new_from_stat_rdev(sd_device **ret, const struct stat *st) {
+ char type;
+
+ assert_return(ret, -EINVAL);
+ assert_return(st, -EINVAL);
+
+ 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_set_devtype(sd_device *device, const char *devtype) {
_cleanup_free_ char *t = NULL;
int r;
@@ -1052,6 +1068,30 @@ _public_ int sd_device_get_sysnum(sd_device *device, const char **ret) {
return 0;
}
+_public_ int sd_device_get_action(sd_device *device, sd_device_action_t *ret) {
+ assert_return(device, -EINVAL);
+
+ if (device->action < 0)
+ return -ENOENT;
+
+ if (ret)
+ *ret = device->action;
+
+ return 0;
+}
+
+_public_ int sd_device_get_seqnum(sd_device *device, uint64_t *ret) {
+ assert_return(device, -EINVAL);
+
+ if (device->seqnum == 0)
+ return -ENOENT;
+
+ if (ret)
+ *ret = device->seqnum;
+
+ return 0;
+}
+
static bool is_valid_tag(const char *tag) {
assert(tag);