sd-device: introduce sd_device_get_driver_subsystem()

To create the sd_device object of a driver, the function
sd_device_new_from_subsystem_sysname() requires "drivers" for subsystem
and e.g. "pci:iwlwifi" for sysname. Similarly, sd_device_new_from_device_id()
also requires driver subsystem. However, we have never provided a
way to get the driver subsystem ("pci" for the previous example) from
an existing sd_device object.

Let's introduce a way to get driver subsystem.
This commit is contained in:
Yu Watanabe
2024-08-28 05:18:14 +09:00
parent 55e35a4d59
commit 44bc6f3cab
6 changed files with 37 additions and 3 deletions
+1
View File
@@ -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;
+14
View File
@@ -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;
+5 -3
View File
@@ -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);