[systemd-devel] Scan all USB devices from Linux service

Lennart Poettering lennart at poettering.net
Wed Feb 14 15:32:31 UTC 2024


On Mi, 14.02.24 20:24, Muni Sekhar (munisekharrms at gmail.com) wrote:

> HI all,
>
> USB devices can have multiple interfaces (functional units) that serve
> different purposes (e.g., data transfer, control, audio, etc.).
>
> Each interface can have an associated string descriptor (referred to
> as iInterface). The string descriptor provides a human-readable name
> or description for the interface.
>
> >From user space service utility, How to scan all the USB devices
> connected to the system and read each interface string
> descriptor(iInterface)  and check whether it matches "Particular
> String" or not.

You can use sd-device.h, allocate an sd_device_enumerator_new(), then
apply some filter via sd_device_enumerator_add_match_sysattr() and
then enumerate through it via
sd_device_enumerator_get_device_first()/sd_device_enumerator_get_device_next().

Lennart

--
Lennart Poettering, Berlin


More information about the systemd-devel mailing list