|
20 | 20 | typedef enum DeviceEnumerationType { |
21 | 21 | DEVICE_ENUMERATION_TYPE_DEVICES, |
22 | 22 | DEVICE_ENUMERATION_TYPE_SUBSYSTEMS, |
| 23 | + DEVICE_ENUMERATION_TYPE_ALL, |
23 | 24 | _DEVICE_ENUMERATION_TYPE_MAX, |
24 | 25 | _DEVICE_ENUMERATION_TYPE_INVALID = -EINVAL, |
25 | 26 | } DeviceEnumerationType; |
@@ -980,6 +981,58 @@ _public_ sd_device *sd_device_enumerator_get_subsystem_next(sd_device_enumerator |
980 | 981 | return enumerator->devices[++enumerator->current_device_index]; |
981 | 982 | } |
982 | 983 |
|
| 984 | +int device_enumerator_scan_devices_and_subsystems(sd_device_enumerator *enumerator) { |
| 985 | + int r = 0, k; |
| 986 | + |
| 987 | + assert(enumerator); |
| 988 | + |
| 989 | + if (enumerator->scan_uptodate && |
| 990 | + enumerator->type == DEVICE_ENUMERATION_TYPE_ALL) |
| 991 | + return 0; |
| 992 | + |
| 993 | + device_enumerator_unref_devices(enumerator); |
| 994 | + |
| 995 | + if (!set_isempty(enumerator->match_tag)) { |
| 996 | + k = enumerator_scan_devices_tags(enumerator); |
| 997 | + if (k < 0) |
| 998 | + r = k; |
| 999 | + } else if (enumerator->match_parent) { |
| 1000 | + k = enumerator_scan_devices_children(enumerator); |
| 1001 | + if (k < 0) |
| 1002 | + r = k; |
| 1003 | + } else { |
| 1004 | + k = enumerator_scan_dir(enumerator, "class", NULL, NULL); |
| 1005 | + if (k < 0) |
| 1006 | + r = log_debug_errno(k, "sd-device-enumerator: Failed to scan /sys/class: %m"); |
| 1007 | + |
| 1008 | + k = enumerator_scan_dir(enumerator, "bus", "devices", NULL); |
| 1009 | + if (k < 0) |
| 1010 | + r = log_debug_errno(k, "sd-device-enumerator: Failed to scan /sys/bus: %m"); |
| 1011 | + |
| 1012 | + if (match_subsystem(enumerator, "module")) { |
| 1013 | + k = enumerator_scan_dir_and_add_devices(enumerator, "module", NULL, NULL); |
| 1014 | + if (k < 0) |
| 1015 | + r = log_debug_errno(k, "sd-device-enumerator: Failed to scan modules: %m"); |
| 1016 | + } |
| 1017 | + if (match_subsystem(enumerator, "subsystem")) { |
| 1018 | + k = enumerator_scan_dir_and_add_devices(enumerator, "bus", NULL, NULL); |
| 1019 | + if (k < 0) |
| 1020 | + r = log_debug_errno(k, "sd-device-enumerator: Failed to scan subsystems: %m"); |
| 1021 | + } |
| 1022 | + |
| 1023 | + if (match_subsystem(enumerator, "drivers")) { |
| 1024 | + k = enumerator_scan_dir(enumerator, "bus", "drivers", "drivers"); |
| 1025 | + if (k < 0) |
| 1026 | + r = log_debug_errno(k, "sd-device-enumerator: Failed to scan drivers: %m"); |
| 1027 | + } |
| 1028 | + } |
| 1029 | + |
| 1030 | + enumerator->scan_uptodate = true; |
| 1031 | + enumerator->type = DEVICE_ENUMERATION_TYPE_ALL; |
| 1032 | + |
| 1033 | + return r; |
| 1034 | +} |
| 1035 | + |
983 | 1036 | sd_device *device_enumerator_get_first(sd_device_enumerator *enumerator) { |
984 | 1037 | assert_return(enumerator, NULL); |
985 | 1038 |
|
|
0 commit comments