2 This file is part of systemd.
4 Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
31 #include "libudev-private.h"
34 * SECTION:libudev-enumerate
35 * @short_description: lookup and sort sys devices
37 * Lookup devices in the sys filesystem, filter devices by properties,
38 * and return a sorted list of devices.
49 * Opaque object representing one device lookup/sort context.
51 struct udev_enumerate {
54 struct udev_list sysattr_match_list;
55 struct udev_list sysattr_nomatch_list;
56 struct udev_list subsystem_match_list;
57 struct udev_list subsystem_nomatch_list;
58 struct udev_list sysname_match_list;
59 struct udev_list properties_match_list;
60 struct udev_list tags_match_list;
61 struct udev_device *parent_match;
62 struct udev_list devices_list;
63 struct syspath *devices;
64 unsigned int devices_cur;
65 unsigned int devices_max;
66 bool devices_uptodate:1;
67 bool match_is_initialized;
72 * @udev: udev library context
74 * Create an enumeration context to scan /sys.
76 * Returns: an enumeration context.
78 _public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev)
80 struct udev_enumerate *udev_enumerate;
84 udev_enumerate = new0(struct udev_enumerate, 1);
85 if (udev_enumerate == NULL)
87 udev_enumerate->refcount = 1;
88 udev_enumerate->udev = udev;
89 udev_list_init(udev, &udev_enumerate->sysattr_match_list, false);
90 udev_list_init(udev, &udev_enumerate->sysattr_nomatch_list, false);
91 udev_list_init(udev, &udev_enumerate->subsystem_match_list, true);
92 udev_list_init(udev, &udev_enumerate->subsystem_nomatch_list, true);
93 udev_list_init(udev, &udev_enumerate->sysname_match_list, true);
94 udev_list_init(udev, &udev_enumerate->properties_match_list, false);
95 udev_list_init(udev, &udev_enumerate->tags_match_list, true);
96 udev_list_init(udev, &udev_enumerate->devices_list, false);
97 return udev_enumerate;
101 * udev_enumerate_ref:
102 * @udev_enumerate: context
104 * Take a reference of a enumeration context.
106 * Returns: the passed enumeration context
108 _public_ struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate)
110 if (udev_enumerate == NULL)
112 udev_enumerate->refcount++;
113 return udev_enumerate;
117 * udev_enumerate_unref:
118 * @udev_enumerate: context
120 * Drop a reference of an enumeration context. If the refcount reaches zero,
121 * all resources of the enumeration context will be released.
125 _public_ struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate)
129 if (udev_enumerate == NULL)
131 udev_enumerate->refcount--;
132 if (udev_enumerate->refcount > 0)
134 udev_list_cleanup(&udev_enumerate->sysattr_match_list);
135 udev_list_cleanup(&udev_enumerate->sysattr_nomatch_list);
136 udev_list_cleanup(&udev_enumerate->subsystem_match_list);
137 udev_list_cleanup(&udev_enumerate->subsystem_nomatch_list);
138 udev_list_cleanup(&udev_enumerate->sysname_match_list);
139 udev_list_cleanup(&udev_enumerate->properties_match_list);
140 udev_list_cleanup(&udev_enumerate->tags_match_list);
141 udev_device_unref(udev_enumerate->parent_match);
142 udev_list_cleanup(&udev_enumerate->devices_list);
143 for (i = 0; i < udev_enumerate->devices_cur; i++)
144 free(udev_enumerate->devices[i].syspath);
145 free(udev_enumerate->devices);
146 free(udev_enumerate);
151 * udev_enumerate_get_udev:
152 * @udev_enumerate: context
154 * Get the udev library context.
156 * Returns: a pointer to the context.
158 _public_ struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate)
160 if (udev_enumerate == NULL)
162 return udev_enumerate->udev;
165 static int syspath_add(struct udev_enumerate *udev_enumerate, const char *syspath)
168 struct syspath *entry;
170 /* double array size if needed */
171 if (udev_enumerate->devices_cur >= udev_enumerate->devices_max) {
175 add = udev_enumerate->devices_max;
178 buf = realloc(udev_enumerate->devices, (udev_enumerate->devices_max + add) * sizeof(struct syspath));
181 udev_enumerate->devices = buf;
182 udev_enumerate->devices_max += add;
185 path = strdup(syspath);
188 entry = &udev_enumerate->devices[udev_enumerate->devices_cur];
189 entry->syspath = path;
190 entry->len = strlen(path);
191 udev_enumerate->devices_cur++;
192 udev_enumerate->devices_uptodate = false;
196 static int syspath_cmp(const void *p1, const void *p2)
198 const struct syspath *path1 = p1;
199 const struct syspath *path2 = p2;
203 len = MIN(path1->len, path2->len);
204 ret = memcmp(path1->syspath, path2->syspath, len);
206 if (path1->len < path2->len)
208 else if (path1->len > path2->len)
214 /* For devices that should be moved to the absolute end of the list */
215 static bool devices_delay_end(struct udev *udev, const char *syspath)
217 static const char *delay_device_list[] = {
224 for (i = 0; delay_device_list[i] != NULL; i++) {
225 if (strstr(syspath + strlen("/sys"), delay_device_list[i]) != NULL)
231 /* For devices that should just be moved a little bit later, just
232 * before the point where some common path prefix changes. Returns the
233 * number of characters that make up that common prefix */
234 static size_t devices_delay_later(struct udev *udev, const char *syspath)
238 /* For sound cards the control device must be enumerated last
239 * to make sure it's the final device node that gets ACLs
240 * applied. Applications rely on this fact and use ACL changes
241 * on the control node as an indicator that the ACL change of
242 * the entire sound card completed. The kernel makes this
243 * guarantee when creating those devices, and hence we should
244 * too when enumerating them. */
246 if ((c = strstr(syspath, "/sound/card"))) {
248 c += strcspn(c, "/");
250 if (startswith(c, "/controlC"))
251 return c - syspath + 1;
258 * udev_enumerate_get_list_entry:
259 * @udev_enumerate: context
261 * Get the first entry of the sorted list of device paths.
263 * Returns: a udev_list_entry.
265 _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate)
267 if (udev_enumerate == NULL)
269 if (!udev_enumerate->devices_uptodate) {
273 struct syspath *prev = NULL;
274 size_t move_later_prefix = 0;
276 udev_list_cleanup(&udev_enumerate->devices_list);
277 qsort_safe(udev_enumerate->devices, udev_enumerate->devices_cur, sizeof(struct syspath), syspath_cmp);
279 max = udev_enumerate->devices_cur;
280 for (i = 0; i < max; i++) {
281 struct syspath *entry = &udev_enumerate->devices[i];
283 /* skip duplicated entries */
285 entry->len == prev->len &&
286 memcmp(entry->syspath, prev->syspath, entry->len) == 0)
290 /* skip to be delayed devices, and add them to the end of the list */
291 if (devices_delay_end(udev_enumerate->udev, entry->syspath)) {
292 syspath_add(udev_enumerate, entry->syspath);
293 /* need to update prev here for the case realloc() gives a different address */
294 prev = &udev_enumerate->devices[i];
298 /* skip to be delayed devices, and move the to
299 * the point where the prefix changes. We can
300 * only move one item at a time. */
301 if (move_later == -1) {
302 move_later_prefix = devices_delay_later(udev_enumerate->udev, entry->syspath);
304 if (move_later_prefix > 0) {
310 if ((move_later >= 0) &&
311 !strneq(entry->syspath, udev_enumerate->devices[move_later].syspath, move_later_prefix)) {
313 udev_list_entry_add(&udev_enumerate->devices_list,
314 udev_enumerate->devices[move_later].syspath, NULL);
318 udev_list_entry_add(&udev_enumerate->devices_list, entry->syspath, NULL);
322 udev_list_entry_add(&udev_enumerate->devices_list,
323 udev_enumerate->devices[move_later].syspath, NULL);
325 /* add and cleanup delayed devices from end of list */
326 for (i = max; i < udev_enumerate->devices_cur; i++) {
327 struct syspath *entry = &udev_enumerate->devices[i];
329 udev_list_entry_add(&udev_enumerate->devices_list, entry->syspath, NULL);
330 free(entry->syspath);
332 udev_enumerate->devices_cur = max;
334 udev_enumerate->devices_uptodate = true;
336 return udev_list_get_entry(&udev_enumerate->devices_list);
340 * udev_enumerate_add_match_subsystem:
341 * @udev_enumerate: context
342 * @subsystem: filter for a subsystem of the device to include in the list
344 * Match only devices belonging to a certain kernel subsystem.
346 * Returns: 0 on success, otherwise a negative error value.
348 _public_ int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
350 if (udev_enumerate == NULL)
352 if (subsystem == NULL)
354 if (udev_list_entry_add(&udev_enumerate->subsystem_match_list, subsystem, NULL) == NULL)
360 * udev_enumerate_add_nomatch_subsystem:
361 * @udev_enumerate: context
362 * @subsystem: filter for a subsystem of the device to exclude from the list
364 * Match only devices not belonging to a certain kernel subsystem.
366 * Returns: 0 on success, otherwise a negative error value.
368 _public_ int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
370 if (udev_enumerate == NULL)
372 if (subsystem == NULL)
374 if (udev_list_entry_add(&udev_enumerate->subsystem_nomatch_list, subsystem, NULL) == NULL)
380 * udev_enumerate_add_match_sysattr:
381 * @udev_enumerate: context
382 * @sysattr: filter for a sys attribute at the device to include in the list
383 * @value: optional value of the sys attribute
385 * Match only devices with a certain /sys device attribute.
387 * Returns: 0 on success, otherwise a negative error value.
389 _public_ int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value)
391 if (udev_enumerate == NULL)
395 if (udev_list_entry_add(&udev_enumerate->sysattr_match_list, sysattr, value) == NULL)
401 * udev_enumerate_add_nomatch_sysattr:
402 * @udev_enumerate: context
403 * @sysattr: filter for a sys attribute at the device to exclude from the list
404 * @value: optional value of the sys attribute
406 * Match only devices not having a certain /sys device attribute.
408 * Returns: 0 on success, otherwise a negative error value.
410 _public_ int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value)
412 if (udev_enumerate == NULL)
416 if (udev_list_entry_add(&udev_enumerate->sysattr_nomatch_list, sysattr, value) == NULL)
421 static int match_sysattr_value(struct udev_device *dev, const char *sysattr, const char *match_val)
423 const char *val = NULL;
426 val = udev_device_get_sysattr_value(dev, sysattr);
429 if (match_val == NULL) {
433 if (fnmatch(match_val, val, 0) == 0) {
442 * udev_enumerate_add_match_property:
443 * @udev_enumerate: context
444 * @property: filter for a property of the device to include in the list
445 * @value: value of the property
447 * Match only devices with a certain property.
449 * Returns: 0 on success, otherwise a negative error value.
451 _public_ int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value)
453 if (udev_enumerate == NULL)
455 if (property == NULL)
457 if (udev_list_entry_add(&udev_enumerate->properties_match_list, property, value) == NULL)
463 * udev_enumerate_add_match_tag:
464 * @udev_enumerate: context
465 * @tag: filter for a tag of the device to include in the list
467 * Match only devices with a certain tag.
469 * Returns: 0 on success, otherwise a negative error value.
471 _public_ int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag)
473 if (udev_enumerate == NULL)
477 if (udev_list_entry_add(&udev_enumerate->tags_match_list, tag, NULL) == NULL)
483 * udev_enumerate_add_match_parent:
484 * @udev_enumerate: context
485 * @parent: parent device where to start searching
487 * Return the devices on the subtree of one given device. The parent
488 * itself is included in the list.
490 * A reference for the device is held until the udev_enumerate context
493 * Returns: 0 on success, otherwise a negative error value.
495 _public_ int udev_enumerate_add_match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *parent)
497 if (udev_enumerate == NULL)
501 if (udev_enumerate->parent_match != NULL)
502 udev_device_unref(udev_enumerate->parent_match);
503 udev_enumerate->parent_match = udev_device_ref(parent);
508 * udev_enumerate_add_match_is_initialized:
509 * @udev_enumerate: context
511 * Match only devices which udev has set up already. This makes
512 * sure, that the device node permissions and context are properly set
513 * and that network devices are fully renamed.
515 * Usually, devices which are found in the kernel but not already
516 * handled by udev, have still pending events. Services should subscribe
517 * to monitor events and wait for these devices to become ready, instead
518 * of using uninitialized devices.
520 * For now, this will not affect devices which do not have a device node
521 * and are not network interfaces.
523 * Returns: 0 on success, otherwise a negative error value.
525 _public_ int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev_enumerate)
527 if (udev_enumerate == NULL)
529 udev_enumerate->match_is_initialized = true;
534 * udev_enumerate_add_match_sysname:
535 * @udev_enumerate: context
536 * @sysname: filter for the name of the device to include in the list
538 * Match only devices with a given /sys device name.
540 * Returns: 0 on success, otherwise a negative error value.
542 _public_ int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname)
544 if (udev_enumerate == NULL)
548 if (udev_list_entry_add(&udev_enumerate->sysname_match_list, sysname, NULL) == NULL)
553 static bool match_sysattr(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
555 struct udev_list_entry *list_entry;
558 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->sysattr_nomatch_list)) {
559 if (match_sysattr_value(dev, udev_list_entry_get_name(list_entry),
560 udev_list_entry_get_value(list_entry)))
564 if (udev_list_get_entry(&udev_enumerate->sysattr_match_list) != NULL) {
565 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->sysattr_match_list)) {
566 /* anything that does not match, will make it FALSE */
567 if (!match_sysattr_value(dev, udev_list_entry_get_name(list_entry),
568 udev_list_entry_get_value(list_entry)))
576 static bool match_property(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
578 struct udev_list_entry *list_entry;
581 /* no match always matches */
582 if (udev_list_get_entry(&udev_enumerate->properties_match_list) == NULL)
585 /* loop over matches */
586 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->properties_match_list)) {
587 const char *match_key = udev_list_entry_get_name(list_entry);
588 const char *match_value = udev_list_entry_get_value(list_entry);
589 struct udev_list_entry *property_entry;
591 /* loop over device properties */
592 udev_list_entry_foreach(property_entry, udev_device_get_properties_list_entry(dev)) {
593 const char *dev_key = udev_list_entry_get_name(property_entry);
594 const char *dev_value = udev_list_entry_get_value(property_entry);
596 if (fnmatch(match_key, dev_key, 0) != 0)
598 if (match_value == NULL && dev_value == NULL) {
602 if (match_value == NULL || dev_value == NULL)
604 if (fnmatch(match_value, dev_value, 0) == 0) {
614 static bool match_tag(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
616 struct udev_list_entry *list_entry;
618 /* no match always matches */
619 if (udev_list_get_entry(&udev_enumerate->tags_match_list) == NULL)
622 /* loop over matches */
623 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->tags_match_list))
624 if (!udev_device_has_tag(dev, udev_list_entry_get_name(list_entry)))
630 static bool match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
632 if (udev_enumerate->parent_match == NULL)
635 return startswith(udev_device_get_devpath(dev), udev_device_get_devpath(udev_enumerate->parent_match));
638 static bool match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname)
640 struct udev_list_entry *list_entry;
642 if (udev_list_get_entry(&udev_enumerate->sysname_match_list) == NULL)
645 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->sysname_match_list)) {
646 if (fnmatch(udev_list_entry_get_name(list_entry), sysname, 0) != 0)
653 static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate,
654 const char *basedir, const char *subdir1, const char *subdir2)
656 char path[UTIL_PATH_SIZE];
663 l = strpcpyl(&s, sizeof(path), "/sys/", basedir, NULL);
665 l = strpcpyl(&s, l, "/", subdir1, NULL);
667 strpcpyl(&s, l, "/", subdir2, NULL);
671 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
672 char syspath[UTIL_PATH_SIZE];
673 struct udev_device *dev;
675 if (dent->d_name[0] == '.')
678 if (!match_sysname(udev_enumerate, dent->d_name))
681 strscpyl(syspath, sizeof(syspath), path, "/", dent->d_name, NULL);
682 dev = udev_device_new_from_syspath(udev_enumerate->udev, syspath);
686 if (udev_enumerate->match_is_initialized) {
688 * All devices with a device node or network interfaces
689 * possibly need udev to adjust the device node permission
690 * or context, or rename the interface before it can be
691 * reliably used from other processes.
693 * For now, we can only check these types of devices, we
694 * might not store a database, and have no way to find out
695 * for all other types of devices.
697 if (!udev_device_get_is_initialized(dev) &&
698 (major(udev_device_get_devnum(dev)) > 0 || udev_device_get_ifindex(dev) > 0))
701 if (!match_parent(udev_enumerate, dev))
703 if (!match_tag(udev_enumerate, dev))
705 if (!match_property(udev_enumerate, dev))
707 if (!match_sysattr(udev_enumerate, dev))
710 syspath_add(udev_enumerate, udev_device_get_syspath(dev));
712 udev_device_unref(dev);
718 static bool match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
720 struct udev_list_entry *list_entry;
725 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->subsystem_nomatch_list)) {
726 if (fnmatch(udev_list_entry_get_name(list_entry), subsystem, 0) == 0)
730 if (udev_list_get_entry(&udev_enumerate->subsystem_match_list) != NULL) {
731 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->subsystem_match_list)) {
732 if (fnmatch(udev_list_entry_get_name(list_entry), subsystem, 0) == 0)
741 static int scan_dir(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir, const char *subsystem)
743 char path[UTIL_PATH_SIZE];
747 strscpyl(path, sizeof(path), "/sys/", basedir, NULL);
751 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
752 if (dent->d_name[0] == '.')
754 if (!match_subsystem(udev_enumerate, subsystem != NULL ? subsystem : dent->d_name))
756 scan_dir_and_add_devices(udev_enumerate, basedir, dent->d_name, subdir);
763 * udev_enumerate_add_syspath:
764 * @udev_enumerate: context
765 * @syspath: path of a device
767 * Add a device to the list of devices, to retrieve it back sorted in dependency order.
769 * Returns: 0 on success, otherwise a negative error value.
771 _public_ int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath)
773 struct udev_device *udev_device;
775 if (udev_enumerate == NULL)
779 /* resolve to real syspath */
780 udev_device = udev_device_new_from_syspath(udev_enumerate->udev, syspath);
781 if (udev_device == NULL)
783 syspath_add(udev_enumerate, udev_device_get_syspath(udev_device));
784 udev_device_unref(udev_device);
788 static int scan_devices_tags(struct udev_enumerate *udev_enumerate)
790 struct udev_list_entry *list_entry;
792 /* scan only tagged devices, use tags reverse-index, instead of searching all devices in /sys */
793 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->tags_match_list)) {
796 char path[UTIL_PATH_SIZE];
798 strscpyl(path, sizeof(path), "/run/udev/tags/", udev_list_entry_get_name(list_entry), NULL);
802 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
803 struct udev_device *dev;
805 if (dent->d_name[0] == '.')
808 dev = udev_device_new_from_device_id(udev_enumerate->udev, dent->d_name);
812 if (!match_subsystem(udev_enumerate, udev_device_get_subsystem(dev)))
814 if (!match_sysname(udev_enumerate, udev_device_get_sysname(dev)))
816 if (!match_parent(udev_enumerate, dev))
818 if (!match_property(udev_enumerate, dev))
820 if (!match_sysattr(udev_enumerate, dev))
823 syspath_add(udev_enumerate, udev_device_get_syspath(dev));
825 udev_device_unref(dev);
832 static int parent_add_child(struct udev_enumerate *enumerate, const char *path)
834 struct udev_device *dev;
837 dev = udev_device_new_from_syspath(enumerate->udev, path);
841 if (!match_subsystem(enumerate, udev_device_get_subsystem(dev)))
843 if (!match_sysname(enumerate, udev_device_get_sysname(dev)))
845 if (!match_property(enumerate, dev))
847 if (!match_sysattr(enumerate, dev))
850 syspath_add(enumerate, udev_device_get_syspath(dev));
854 udev_device_unref(dev);
858 static int parent_crawl_children(struct udev_enumerate *enumerate, const char *path, int maxdepth)
867 for (dent = readdir(d); dent != NULL; dent = readdir(d)) {
870 if (dent->d_name[0] == '.')
872 if (dent->d_type != DT_DIR)
874 if (asprintf(&child, "%s/%s", path, dent->d_name) < 0)
876 parent_add_child(enumerate, child);
878 parent_crawl_children(enumerate, child, maxdepth-1);
886 static int scan_devices_children(struct udev_enumerate *enumerate)
890 path = udev_device_get_syspath(enumerate->parent_match);
891 parent_add_child(enumerate, path);
892 return parent_crawl_children(enumerate, path, 256);
895 static int scan_devices_all(struct udev_enumerate *udev_enumerate)
899 if (stat("/sys/subsystem", &statbuf) == 0) {
900 /* we have /subsystem/, forget all the old stuff */
901 scan_dir(udev_enumerate, "subsystem", "devices", NULL);
903 scan_dir(udev_enumerate, "bus", "devices", NULL);
904 scan_dir(udev_enumerate, "class", NULL, NULL);
910 * udev_enumerate_scan_devices:
911 * @udev_enumerate: udev enumeration context
913 * Scan /sys for all devices which match the given filters. No matches
914 * will return all currently available devices.
916 * Returns: 0 on success, otherwise a negative error value.
918 _public_ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate)
920 if (udev_enumerate == NULL)
923 /* efficiently lookup tags only, we maintain a reverse-index */
924 if (udev_list_get_entry(&udev_enumerate->tags_match_list) != NULL)
925 return scan_devices_tags(udev_enumerate);
927 /* walk the subtree of one parent device only */
928 if (udev_enumerate->parent_match != NULL)
929 return scan_devices_children(udev_enumerate);
931 /* scan devices of all subsystems */
932 return scan_devices_all(udev_enumerate);
936 * udev_enumerate_scan_subsystems:
937 * @udev_enumerate: udev enumeration context
939 * Scan /sys for all kernel subsystems, including buses, classes, drivers.
941 * Returns: 0 on success, otherwise a negative error value.
943 _public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate)
946 const char *subsysdir;
948 if (udev_enumerate == NULL)
951 /* all kernel modules */
952 if (match_subsystem(udev_enumerate, "module"))
953 scan_dir_and_add_devices(udev_enumerate, "module", NULL, NULL);
955 if (stat("/sys/subsystem", &statbuf) == 0)
956 subsysdir = "subsystem";
960 /* all subsystems (only buses support coldplug) */
961 if (match_subsystem(udev_enumerate, "subsystem"))
962 scan_dir_and_add_devices(udev_enumerate, subsysdir, NULL, NULL);
964 /* all subsystem drivers */
965 if (match_subsystem(udev_enumerate, "drivers"))
966 scan_dir(udev_enumerate, subsysdir, "drivers", "drivers");