diff --git a/man/rules/meson.build b/man/rules/meson.build
index a42143ec7cf..f551c25e6b7 100644
--- a/man/rules/meson.build
+++ b/man/rules/meson.build
@@ -530,6 +530,7 @@ manpages = [
'sd_device_get_devtype',
'sd_device_get_diskseq',
'sd_device_get_driver',
+ 'sd_device_get_driver_subsystem',
'sd_device_get_ifindex',
'sd_device_get_subsystem',
'sd_device_get_sysname',
diff --git a/man/sd_device_get_syspath.xml b/man/sd_device_get_syspath.xml
index 718da91e87d..f21d7a297bc 100644
--- a/man/sd_device_get_syspath.xml
+++ b/man/sd_device_get_syspath.xml
@@ -22,6 +22,7 @@
sd_device_get_sysname
sd_device_get_sysnum
sd_device_get_subsystem
+ sd_device_get_driver_subsystem
sd_device_get_devtype
sd_device_get_devname
sd_device_get_devnum
@@ -66,6 +67,12 @@
const char **ret
+
+ int sd_device_get_driver_subsystem
+ sd_device *device
+ const char **ret
+
+
int sd_device_get_devtype
sd_device *device
@@ -126,6 +133,13 @@
record. This is a short string fitting into a filename, and thus does not contain a slash and cannot be
empty. Example: tty, block or net.
+ sd_device_get_driver_subsystem() returns the connected bus type of the devices
+ loaded by the specified driver device record. For example, when iwlwifi driver device
+ is specified, which is used by the wireless network interfaces connected to PCI bus, this function returns
+ pci. This function only succeeds when sd_device_get_subsystem()
+ returns drivers. Example: pci, i2c, or
+ hid.
+
sd_device_get_devtype() returns the device type of the specified device
record, if the subsystem manages multiple types of devices. Example: for devices of the
block subsystem this can be disk or partition
@@ -206,6 +220,7 @@
sd_device_get_ifindex(),
sd_device_get_driver(), and
sd_device_get_diskseq() were added in version 251.
+ sd_device_get_driver_subsystem() was added in version 257.
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index 50ef8096db0..e79c1a65d29 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -1046,6 +1046,7 @@ global:
sd_varlink_take_fd;
sd_varlink_unref;
sd_varlink_wait;
+ sd_device_get_driver_subsystem;
sd_device_monitor_is_running;
sd_device_monitor_get_fd;
sd_device_monitor_receive;
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index 3d683fb2802..6dedfc43790 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -1198,6 +1198,20 @@ _public_ int sd_device_get_subsystem(sd_device *device, const char **ret) {
return 0;
}
+_public_ int sd_device_get_driver_subsystem(sd_device *device, const char **ret) {
+ assert_return(device, -EINVAL);
+
+ if (!device_in_subsystem(device, "drivers"))
+ return -ENOENT;
+
+ assert(device->driver_subsystem);
+
+ if (ret)
+ *ret = device->driver_subsystem;
+
+ return 0;
+}
+
_public_ int sd_device_get_devtype(sd_device *device, const char **devtype) {
int r;
diff --git a/src/libsystemd/sd-device/test-sd-device.c b/src/libsystemd/sd-device/test-sd-device.c
index 9fde1a08143..ae745ab3210 100644
--- a/src/libsystemd/sd-device/test-sd-device.c
+++ b/src/libsystemd/sd-device/test-sd-device.c
@@ -79,9 +79,11 @@ static void test_sd_device_one(sd_device *d) {
* sd_device_new_from_device_id() may not work as expected. */
const char *name, *id;
- if (streq(subsystem, "drivers"))
- name = strjoina(d->driver_subsystem, ":", sysname);
- else
+ if (streq(subsystem, "drivers")) {
+ const char *driver_subsystem;
+ ASSERT_OK(sd_device_get_driver_subsystem(d, &driver_subsystem));
+ name = strjoina(driver_subsystem, ":", sysname);
+ } else
name = sysname;
assert_se(sd_device_new_from_subsystem_sysname(&dev, subsystem, name) >= 0);
assert_se(sd_device_get_syspath(dev, &val) >= 0);
diff --git a/src/systemd/sd-device.h b/src/systemd/sd-device.h
index c84cc552029..86f90a1fd1d 100644
--- a/src/systemd/sd-device.h
+++ b/src/systemd/sd-device.h
@@ -74,6 +74,7 @@ int sd_device_get_parent_with_subsystem_devtype(sd_device *child, const char *su
int sd_device_get_syspath(sd_device *device, const char **ret);
int sd_device_get_subsystem(sd_device *device, const char **ret);
+int sd_device_get_driver_subsystem(sd_device *device, const char **ret);
int sd_device_get_devtype(sd_device *device, const char **ret);
int sd_device_get_devnum(sd_device *device, dev_t *devnum);
int sd_device_get_ifindex(sd_device *device, int *ifindex);