SD\_DEVICE\_ENUMERATOR\_GET\_DEVICE\_FIRST(3) sd\_device\_enumerator\_get\_device\_first SD\_DEVICE\_ENUMERATOR\_GET\_DEVICE\_FIRST(3)

.SH "NAME" sd\_device\_enumerator\_get\_device\_first, sd\_device\_enumerator\_get\_device\_next, sd\_device\_enumerator\_get\_subsystem\_first, sd\_device\_enumerator\_get\_subsystem\_next - Enumerates devices and get the first or next device.

.SH "SYNOPSIS"

```
#include <systemd/sd-device.h>
```

.HP 1176u **sd\_device \*sd\_device\_enumerator\_get\_device\_first(sd\_device\_enumerator \*enumerator);**

.HP 1152u **sd\_device \*sd\_device\_enumerator\_get\_device\_next(sd\_device\_enumerator \*enumerator);**

.HP 1248u **sd\_device \*sd\_device\_enumerator\_get\_subsystem\_first(sd\_device\_enumerator \*enumerator);**

.HP 1224u **sd\_device \*sd\_device\_enumerator\_get\_subsystem\_next(sd\_device\_enumerator \*enumerator);**

.SH "DESCRIPTION"

.PP The **sd\_device\_enumerator\_get\_device\_first()** function enumerates all matching devices under /sys/bus/*SUBSYSTEM*/devices/ and /sys/class/*SUBSYSTEM*/devices/, and returns a pointer to the first **sd\_device** object. If no devices are found, **NULL** is returned.

.PP The **sd\_device\_enumerator\_get\_device\_next()** function returns the pointer to the next **sd\_device** from the *enumerator*. It should be called after **sd\_device\_enumerator\_get\_device\_first()** or after a previous call to this function. If no more devices are available, **NULL** is returned.

.PP The **sd\_device\_enumerator\_get\_subsystem\_first()** function enumerates all matching subsystem devices in /sys/module/, /sys/bus/, and /sys/bus/*SUBSYSTEM*/drivers/ (such as /sys/bus/pci/drivers/). It returns a pointer to the first **sd\_device** object. If no devices are found **NULL** is returned. Note that this does *not* enumerate devices provided by **sd\_device\_enumerator\_get\_device\_first/next()**. Hence, e.g. /sys/bus/pci/, /sys/bus/pci/drivers/ahci/ and so on are enumerated, but /sys/bus/pci/devices/0000:00:00.0/ and so on are not.

.PP The **sd\_device\_enumerator\_get\_subsystem\_next()** function returns the next subsystem device from the enumerator. It should be called after **sd\_device\_enumerator\_get\_subsystem\_first()** or after a previous call to this function. If no more subsystem devices are available, **NULL** is returned.

.SH "RETURN VALUE"

.PP On success, these functions return a pointer to an **sd\_device** object. On failure or when no more devices are available, **NULL** is returned. The returned pointers are owned by the enumerator and should not be freed by the caller.

.SH "HISTORY"

.PP **sd\_device\_enumerator\_get\_device\_first()**, **sd\_device\_enumerator\_get\_device\_next()**, **sd\_device\_enumerator\_get\_subsystem\_first()**, and **sd\_device\_enumerator\_get\_subsystem\_next()** were introduced in systemd version 240.

.SH "SEE ALSO"

.PP [**sd\_device\_enumerator\_new**(3)](/man/os/systemd/sd_device_enumerator_new.3), [**sd\_device\_enumerator\_add\_match\_parent**(3)](/man/os/systemd/sd_device_enumerator_add_match_parent.3), [**sd\_device\_ref**(3)](/man/os/systemd/sd_device_ref.3)

systemd 262.2

---

Document: sd_device_enumerator_get_device_first(3) from systemd 262.2-r1 (Chainguard OS)
Source: https://github.com/systemd/systemd
