mirror of
https://github.com/systemd/systemd.git
synced 2025-08-02 04:22:27 +03:00
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:
@ -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',
|
||||
|
@ -22,6 +22,7 @@
|
||||
<refname>sd_device_get_sysname</refname>
|
||||
<refname>sd_device_get_sysnum</refname>
|
||||
<refname>sd_device_get_subsystem</refname>
|
||||
<refname>sd_device_get_driver_subsystem</refname>
|
||||
<refname>sd_device_get_devtype</refname>
|
||||
<refname>sd_device_get_devname</refname>
|
||||
<refname>sd_device_get_devnum</refname>
|
||||
@ -66,6 +67,12 @@
|
||||
<paramdef>const char **<parameter>ret</parameter></paramdef>
|
||||
</funcprototype>
|
||||
|
||||
<funcprototype>
|
||||
<funcdef>int <function>sd_device_get_driver_subsystem</function></funcdef>
|
||||
<paramdef>sd_device *<parameter>device</parameter></paramdef>
|
||||
<paramdef>const char **<parameter>ret</parameter></paramdef>
|
||||
</funcprototype>
|
||||
|
||||
<funcprototype>
|
||||
<funcdef>int <function>sd_device_get_devtype</function></funcdef>
|
||||
<paramdef>sd_device *<parameter>device</parameter></paramdef>
|
||||
@ -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: <literal>tty</literal>, <literal>block</literal> or <literal>net</literal>.</para>
|
||||
|
||||
<para><function>sd_device_get_driver_subsystem()</function> returns the connected bus type of the devices
|
||||
loaded by the specified driver device record. For example, when <literal>iwlwifi</literal> driver device
|
||||
is specified, which is used by the wireless network interfaces connected to PCI bus, this function returns
|
||||
<literal>pci</literal>. This function only succeeds when <function>sd_device_get_subsystem()</function>
|
||||
returns <literal>drivers</literal>. Example: <literal>pci</literal>, <literal>i2c</literal>, or
|
||||
<literal>hid</literal>.</para>
|
||||
|
||||
<para><function>sd_device_get_devtype()</function> returns the device type of the specified device
|
||||
record, if the subsystem manages multiple types of devices. Example: for devices of the
|
||||
<literal>block</literal> subsystem this can be <literal>disk</literal> or <literal>partition</literal>
|
||||
@ -206,6 +220,7 @@
|
||||
<function>sd_device_get_ifindex()</function>,
|
||||
<function>sd_device_get_driver()</function>, and
|
||||
<function>sd_device_get_diskseq()</function> were added in version 251.</para>
|
||||
<para><function>sd_device_get_driver_subsystem()</function> was added in version 257.</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user