2 * libudev - interface to udev device information
4 * Copyright (C) 2008-2010 Kay Sievers <kay.sievers@vrfy.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
22 #include <sys/param.h>
25 #include "libudev-private.h"
28 * SECTION:libudev-enumerate
29 * @short_description: lookup and sort sys devices
31 * Lookup devices in the sys filesystem, filter devices by properties,
32 * and return a sorted list of devices.
43 * Opaque object representing one device lookup/sort context.
45 struct udev_enumerate {
48 struct udev_list sysattr_match_list;
49 struct udev_list sysattr_nomatch_list;
50 struct udev_list subsystem_match_list;
51 struct udev_list subsystem_nomatch_list;
52 struct udev_list sysname_match_list;
53 struct udev_list properties_match_list;
54 struct udev_list tags_match_list;
55 struct udev_device *parent_match;
56 struct udev_list devices_list;
57 struct syspath *devices;
58 unsigned int devices_cur;
59 unsigned int devices_max;
60 bool devices_uptodate:1;
61 bool match_is_initialized;
66 * @udev: udev library context
68 * Returns: an enumeration context
70 _public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev)
72 struct udev_enumerate *udev_enumerate;
74 udev_enumerate = calloc(1, sizeof(struct udev_enumerate));
75 if (udev_enumerate == NULL)
77 udev_enumerate->refcount = 1;
78 udev_enumerate->udev = udev;
79 udev_list_init(udev, &udev_enumerate->sysattr_match_list, false);
80 udev_list_init(udev, &udev_enumerate->sysattr_nomatch_list, false);
81 udev_list_init(udev, &udev_enumerate->subsystem_match_list, true);
82 udev_list_init(udev, &udev_enumerate->subsystem_nomatch_list, true);
83 udev_list_init(udev, &udev_enumerate->sysname_match_list, true);
84 udev_list_init(udev, &udev_enumerate->properties_match_list, false);
85 udev_list_init(udev, &udev_enumerate->tags_match_list, true);
86 udev_list_init(udev, &udev_enumerate->devices_list, false);
87 return udev_enumerate;
92 * @udev_enumerate: context
94 * Take a reference of a enumeration context.
96 * Returns: the passed enumeration context
98 _public_ struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate)
100 if (udev_enumerate == NULL)
102 udev_enumerate->refcount++;
103 return udev_enumerate;
107 * udev_enumerate_unref:
108 * @udev_enumerate: context
110 * Drop a reference of an enumeration context. If the refcount reaches zero,
111 * all resources of the enumeration context will be released.
113 _public_ void udev_enumerate_unref(struct udev_enumerate *udev_enumerate)
117 if (udev_enumerate == NULL)
119 udev_enumerate->refcount--;
120 if (udev_enumerate->refcount > 0)
122 udev_list_cleanup(&udev_enumerate->sysattr_match_list);
123 udev_list_cleanup(&udev_enumerate->sysattr_nomatch_list);
124 udev_list_cleanup(&udev_enumerate->subsystem_match_list);
125 udev_list_cleanup(&udev_enumerate->subsystem_nomatch_list);
126 udev_list_cleanup(&udev_enumerate->sysname_match_list);
127 udev_list_cleanup(&udev_enumerate->properties_match_list);
128 udev_list_cleanup(&udev_enumerate->tags_match_list);
129 udev_device_unref(udev_enumerate->parent_match);
130 udev_list_cleanup(&udev_enumerate->devices_list);
131 for (i = 0; i < udev_enumerate->devices_cur; i++)
132 free(udev_enumerate->devices[i].syspath);
133 free(udev_enumerate->devices);
134 free(udev_enumerate);
138 * udev_enumerate_get_udev:
139 * @udev_enumerate: context
141 * Returns: the udev library context.
143 _public_ struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate)
145 if (udev_enumerate == NULL)
147 return udev_enumerate->udev;
150 static int syspath_add(struct udev_enumerate *udev_enumerate, const char *syspath)
153 struct syspath *entry;
155 /* double array size if needed */
156 if (udev_enumerate->devices_cur >= udev_enumerate->devices_max) {
160 add = udev_enumerate->devices_max;
163 buf = realloc(udev_enumerate->devices, (udev_enumerate->devices_max + add) * sizeof(struct syspath));
166 udev_enumerate->devices = buf;
167 udev_enumerate->devices_max += add;
170 path = strdup(syspath);
173 entry = &udev_enumerate->devices[udev_enumerate->devices_cur];
174 entry->syspath = path;
175 entry->len = strlen(path);
176 udev_enumerate->devices_cur++;
177 udev_enumerate->devices_uptodate = false;
181 static int syspath_cmp(const void *p1, const void *p2)
183 const struct syspath *path1 = p1;
184 const struct syspath *path2 = p2;
188 len = MIN(path1->len, path2->len);
189 ret = memcmp(path1->syspath, path2->syspath, len);
191 if (path1->len < path2->len)
193 else if (path1->len > path2->len)
199 /* For devices that should be moved to the absolute end of the list */
200 static bool devices_delay_end(struct udev *udev, const char *syspath)
202 static const char *delay_device_list[] = {
209 for (i = 0; delay_device_list[i] != NULL; i++) {
210 if (strstr(syspath + strlen("/sys"), delay_device_list[i]) != NULL)
216 /* For devices that should just be moved a little bit later, just
217 * before the point where some common path prefix changes. Returns the
218 * number of characters that make up that common prefix */
219 static size_t devices_delay_later(struct udev *udev, const char *syspath)
223 /* For sound cards the control device must be enumerated last
224 * to make sure it's the final device node that gets ACLs
225 * applied. Applications rely on this fact and use ACL changes
226 * on the control node as an indicator that the ACL change of
227 * the entire sound card completed. The kernel makes this
228 * guarantee when creating those devices, and hence we should
229 * too when enumerating them. */
231 if ((c = strstr(syspath, "/sound/card"))) {
233 c += strcspn(c, "/");
235 if (startswith(c, "/controlC"))
236 return c - syspath + 1;
243 * udev_enumerate_get_list_entry:
244 * @udev_enumerate: context
246 * Returns: the first entry of the sorted list of device paths.
248 _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate)
250 if (udev_enumerate == NULL)
252 if (!udev_enumerate->devices_uptodate) {
255 struct syspath *prev = NULL, *move_later = NULL;
256 size_t move_later_prefix = 0;
258 udev_list_cleanup(&udev_enumerate->devices_list);
259 qsort(udev_enumerate->devices, udev_enumerate->devices_cur, sizeof(struct syspath), syspath_cmp);
261 max = udev_enumerate->devices_cur;
262 for (i = 0; i < max; i++) {
263 struct syspath *entry = &udev_enumerate->devices[i];
265 /* skip duplicated entries */
267 entry->len == prev->len &&
268 memcmp(entry->syspath, prev->syspath, entry->len) == 0)
272 /* skip to be delayed devices, and add them to the end of the list */
273 if (devices_delay_end(udev_enumerate->udev, entry->syspath)) {
274 syspath_add(udev_enumerate, entry->syspath);
275 /* need to update prev here for the case realloc() gives a different address */
276 prev = &udev_enumerate->devices[i];
280 /* skip to be delayed devices, and move the to
281 * the point where the prefix changes. We can
282 * only move one item at a time. */
284 move_later_prefix = devices_delay_later(udev_enumerate->udev, entry->syspath);
286 if (move_later_prefix > 0) {
293 strncmp(entry->syspath, move_later->syspath, move_later_prefix) != 0) {
295 udev_list_entry_add(&udev_enumerate->devices_list, move_later->syspath, NULL);
299 udev_list_entry_add(&udev_enumerate->devices_list, entry->syspath, NULL);
303 udev_list_entry_add(&udev_enumerate->devices_list, move_later->syspath, NULL);
305 /* add and cleanup delayed devices from end of list */
306 for (i = max; i < udev_enumerate->devices_cur; i++) {
307 struct syspath *entry = &udev_enumerate->devices[i];
309 udev_list_entry_add(&udev_enumerate->devices_list, entry->syspath, NULL);
310 free(entry->syspath);
312 udev_enumerate->devices_cur = max;
314 udev_enumerate->devices_uptodate = true;
316 return udev_list_get_entry(&udev_enumerate->devices_list);
320 * udev_enumerate_add_match_subsystem:
321 * @udev_enumerate: context
322 * @subsystem: filter for a subsystem of the device to include in the list
324 * Returns: 0 on success, otherwise a negative error value.
326 _public_ int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
328 if (udev_enumerate == NULL)
330 if (subsystem == NULL)
332 if (udev_list_entry_add(&udev_enumerate->subsystem_match_list, subsystem, NULL) == NULL)
338 * udev_enumerate_add_nomatch_subsystem:
339 * @udev_enumerate: context
340 * @subsystem: filter for a subsystem of the device to exclude from the list
342 * Returns: 0 on success, otherwise a negative error value.
344 _public_ int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
346 if (udev_enumerate == NULL)
348 if (subsystem == NULL)
350 if (udev_list_entry_add(&udev_enumerate->subsystem_nomatch_list, subsystem, NULL) == NULL)
356 * udev_enumerate_add_match_sysattr:
357 * @udev_enumerate: context
358 * @sysattr: filter for a sys attribute at the device to include in the list
359 * @value: optional value of the sys attribute
361 * Returns: 0 on success, otherwise a negative error value.
363 _public_ int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value)
365 if (udev_enumerate == NULL)
369 if (udev_list_entry_add(&udev_enumerate->sysattr_match_list, sysattr, value) == NULL)
375 * udev_enumerate_add_nomatch_sysattr:
376 * @udev_enumerate: context
377 * @sysattr: filter for a sys attribute at the device to exclude from the list
378 * @value: optional value of the sys attribute
380 * Returns: 0 on success, otherwise a negative error value.
382 _public_ int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value)
384 if (udev_enumerate == NULL)
388 if (udev_list_entry_add(&udev_enumerate->sysattr_nomatch_list, sysattr, value) == NULL)
393 static int match_sysattr_value(struct udev_device *dev, const char *sysattr, const char *match_val)
395 const char *val = NULL;
398 val = udev_device_get_sysattr_value(dev, sysattr);
401 if (match_val == NULL) {
405 if (fnmatch(match_val, val, 0) == 0) {
414 * udev_enumerate_add_match_property:
415 * @udev_enumerate: context
416 * @property: filter for a property of the device to include in the list
417 * @value: value of the property
419 * Returns: 0 on success, otherwise a negative error value.
421 _public_ int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value)
423 if (udev_enumerate == NULL)
425 if (property == NULL)
427 if (udev_list_entry_add(&udev_enumerate->properties_match_list, property, value) == NULL)
433 * udev_enumerate_add_match_tag:
434 * @udev_enumerate: context
435 * @tag: filter for a tag of the device to include in the list
437 * Returns: 0 on success, otherwise a negative error value.
439 _public_ int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag)
441 if (udev_enumerate == NULL)
445 if (udev_list_entry_add(&udev_enumerate->tags_match_list, tag, NULL) == NULL)
451 * udev_enumerate_add_match_parent:
452 * @udev_enumerate: context
453 * @parent: parent device where to start searching
455 * Return the devices on the subtree of one given device. The parent
456 * itself is included in the list.
458 * A reference for the device is held until the udev_enumerate context
461 * Returns: 0 on success, otherwise a negative error value.
463 _public_ int udev_enumerate_add_match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *parent)
465 if (udev_enumerate == NULL)
469 if (udev_enumerate->parent_match != NULL)
470 udev_device_unref(udev_enumerate->parent_match);
471 udev_enumerate->parent_match = udev_device_ref(parent);
476 * udev_enumerate_add_match_is_initialized:
477 * @udev_enumerate: context
479 * Match only devices which udev has set up already. This makes
480 * sure, that the device node permissions and context are properly set
481 * and that network devices are fully renamed.
483 * Usually, devices which are found in the kernel but not already
484 * handled by udev, have still pending events. Services should subscribe
485 * to monitor events and wait for these devices to become ready, instead
486 * of using uninitialized devices.
488 * For now, this will not affect devices which do not have a device node
489 * and are not network interfaces.
491 * Returns: 0 on success, otherwise a negative error value.
493 _public_ int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev_enumerate)
495 if (udev_enumerate == NULL)
497 udev_enumerate->match_is_initialized = true;
502 * udev_enumerate_add_match_sysname:
503 * @udev_enumerate: context
504 * @sysname: filter for the name of the device to include in the list
506 * Returns: 0 on success, otherwise a negative error value.
508 _public_ int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname)
510 if (udev_enumerate == NULL)
514 if (udev_list_entry_add(&udev_enumerate->sysname_match_list, sysname, NULL) == NULL)
519 static bool match_sysattr(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
521 struct udev_list_entry *list_entry;
524 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->sysattr_nomatch_list)) {
525 if (match_sysattr_value(dev, udev_list_entry_get_name(list_entry),
526 udev_list_entry_get_value(list_entry)))
530 if (udev_list_get_entry(&udev_enumerate->sysattr_match_list) != NULL) {
531 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->sysattr_match_list)) {
532 /* anything that does not match, will make it FALSE */
533 if (!match_sysattr_value(dev, udev_list_entry_get_name(list_entry),
534 udev_list_entry_get_value(list_entry)))
542 static bool match_property(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
544 struct udev_list_entry *list_entry;
547 /* no match always matches */
548 if (udev_list_get_entry(&udev_enumerate->properties_match_list) == NULL)
551 /* loop over matches */
552 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->properties_match_list)) {
553 const char *match_key = udev_list_entry_get_name(list_entry);
554 const char *match_value = udev_list_entry_get_value(list_entry);
555 struct udev_list_entry *property_entry;
557 /* loop over device properties */
558 udev_list_entry_foreach(property_entry, udev_device_get_properties_list_entry(dev)) {
559 const char *dev_key = udev_list_entry_get_name(property_entry);
560 const char *dev_value = udev_list_entry_get_value(property_entry);
562 if (fnmatch(match_key, dev_key, 0) != 0)
564 if (match_value == NULL && dev_value == NULL) {
568 if (match_value == NULL || dev_value == NULL)
570 if (fnmatch(match_value, dev_value, 0) == 0) {
580 static bool match_tag(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
582 struct udev_list_entry *list_entry;
584 /* no match always matches */
585 if (udev_list_get_entry(&udev_enumerate->tags_match_list) == NULL)
588 /* loop over matches */
589 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->tags_match_list))
590 if (!udev_device_has_tag(dev, udev_list_entry_get_name(list_entry)))
596 static bool match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
598 if (udev_enumerate->parent_match == NULL)
601 return startswith(udev_device_get_devpath(dev), udev_device_get_devpath(udev_enumerate->parent_match));
604 static bool match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname)
606 struct udev_list_entry *list_entry;
608 if (udev_list_get_entry(&udev_enumerate->sysname_match_list) == NULL)
611 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->sysname_match_list)) {
612 if (fnmatch(udev_list_entry_get_name(list_entry), sysname, 0) != 0)
619 static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate,
620 const char *basedir, const char *subdir1, const char *subdir2)
622 char path[UTIL_PATH_SIZE];
629 l = util_strpcpyl(&s, sizeof(path), "/sys/", basedir, NULL);
631 l = util_strpcpyl(&s, l, "/", subdir1, NULL);
633 util_strpcpyl(&s, l, "/", subdir2, NULL);
637 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
638 char syspath[UTIL_PATH_SIZE];
639 struct udev_device *dev;
641 if (dent->d_name[0] == '.')
644 if (!match_sysname(udev_enumerate, dent->d_name))
647 util_strscpyl(syspath, sizeof(syspath), path, "/", dent->d_name, NULL);
648 dev = udev_device_new_from_syspath(udev_enumerate->udev, syspath);
652 if (udev_enumerate->match_is_initialized) {
654 * All devices with a device node or network interfaces
655 * possibly need udev to adjust the device node permission
656 * or context, or rename the interface before it can be
657 * reliably used from other processes.
659 * For now, we can only check these types of devices, we
660 * might not store a database, and have no way to find out
661 * for all other types of devices.
663 if (!udev_device_get_is_initialized(dev) &&
664 (major(udev_device_get_devnum(dev)) > 0 || udev_device_get_ifindex(dev) > 0))
667 if (!match_parent(udev_enumerate, dev))
669 if (!match_tag(udev_enumerate, dev))
671 if (!match_property(udev_enumerate, dev))
673 if (!match_sysattr(udev_enumerate, dev))
676 syspath_add(udev_enumerate, udev_device_get_syspath(dev));
678 udev_device_unref(dev);
684 static bool match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
686 struct udev_list_entry *list_entry;
688 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->subsystem_nomatch_list)) {
689 if (fnmatch(udev_list_entry_get_name(list_entry), subsystem, 0) == 0)
692 if (udev_list_get_entry(&udev_enumerate->subsystem_match_list) != NULL) {
693 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->subsystem_match_list)) {
694 if (fnmatch(udev_list_entry_get_name(list_entry), subsystem, 0) == 0)
702 static int scan_dir(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir, const char *subsystem)
704 char path[UTIL_PATH_SIZE];
708 util_strscpyl(path, sizeof(path), "/sys/", basedir, NULL);
712 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
713 if (dent->d_name[0] == '.')
715 if (!match_subsystem(udev_enumerate, subsystem != NULL ? subsystem : dent->d_name))
717 scan_dir_and_add_devices(udev_enumerate, basedir, dent->d_name, subdir);
724 * udev_enumerate_add_syspath:
725 * @udev_enumerate: context
726 * @syspath: path of a device
728 * Add a device to the list of devices, to retrieve it back sorted in dependency order.
730 * Returns: 0 on success, otherwise a negative error value.
732 _public_ int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath)
734 struct udev_device *udev_device;
736 if (udev_enumerate == NULL)
740 /* resolve to real syspath */
741 udev_device = udev_device_new_from_syspath(udev_enumerate->udev, syspath);
742 if (udev_device == NULL)
744 syspath_add(udev_enumerate, udev_device_get_syspath(udev_device));
745 udev_device_unref(udev_device);
749 static int scan_devices_tags(struct udev_enumerate *udev_enumerate)
751 struct udev_list_entry *list_entry;
753 /* scan only tagged devices, use tags reverse-index, instead of searching all devices in /sys */
754 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->tags_match_list)) {
757 char path[UTIL_PATH_SIZE];
759 util_strscpyl(path, sizeof(path), "/run/udev/tags/", udev_list_entry_get_name(list_entry), NULL);
763 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
764 struct udev_device *dev;
766 if (dent->d_name[0] == '.')
769 dev = udev_device_new_from_id_filename(udev_enumerate->udev, dent->d_name);
773 if (!match_subsystem(udev_enumerate, udev_device_get_subsystem(dev)))
775 if (!match_sysname(udev_enumerate, udev_device_get_sysname(dev)))
777 if (!match_parent(udev_enumerate, dev))
779 if (!match_property(udev_enumerate, dev))
781 if (!match_sysattr(udev_enumerate, dev))
784 syspath_add(udev_enumerate, udev_device_get_syspath(dev));
786 udev_device_unref(dev);
793 static int parent_add_child(struct udev_enumerate *enumerate, const char *path)
795 struct udev_device *dev;
797 dev = udev_device_new_from_syspath(enumerate->udev, path);
801 if (!match_subsystem(enumerate, udev_device_get_subsystem(dev)))
803 if (!match_sysname(enumerate, udev_device_get_sysname(dev)))
805 if (!match_property(enumerate, dev))
807 if (!match_sysattr(enumerate, dev))
810 syspath_add(enumerate, udev_device_get_syspath(dev));
811 udev_device_unref(dev);
815 static int parent_crawl_children(struct udev_enumerate *enumerate, const char *path, int maxdepth)
824 for (dent = readdir(d); dent != NULL; dent = readdir(d)) {
827 if (dent->d_name[0] == '.')
829 if (dent->d_type != DT_DIR)
831 if (asprintf(&child, "%s/%s", path, dent->d_name) < 0)
833 parent_add_child(enumerate, child);
835 parent_crawl_children(enumerate, child, maxdepth-1);
843 static int scan_devices_children(struct udev_enumerate *enumerate)
847 path = udev_device_get_syspath(enumerate->parent_match);
848 parent_add_child(enumerate, path);
849 return parent_crawl_children(enumerate, path, 256);
852 static int scan_devices_all(struct udev_enumerate *udev_enumerate)
856 if (stat("/sys/subsystem", &statbuf) == 0) {
857 /* we have /subsystem/, forget all the old stuff */
858 scan_dir(udev_enumerate, "subsystem", "devices", NULL);
860 scan_dir(udev_enumerate, "bus", "devices", NULL);
861 scan_dir(udev_enumerate, "class", NULL, NULL);
867 * udev_enumerate_scan_devices:
868 * @udev_enumerate: udev enumeration context
870 * Returns: 0 on success, otherwise a negative error value.
872 _public_ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate)
874 if (udev_enumerate == NULL)
877 /* efficiently lookup tags only, we maintain a reverse-index */
878 if (udev_list_get_entry(&udev_enumerate->tags_match_list) != NULL)
879 return scan_devices_tags(udev_enumerate);
881 /* walk the subtree of one parent device only */
882 if (udev_enumerate->parent_match != NULL)
883 return scan_devices_children(udev_enumerate);
885 /* scan devices of all subsystems */
886 return scan_devices_all(udev_enumerate);
890 * udev_enumerate_scan_subsystems:
891 * @udev_enumerate: udev enumeration context
893 * Returns: 0 on success, otherwise a negative error value.
895 _public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate)
898 const char *subsysdir;
900 if (udev_enumerate == NULL)
903 /* all kernel modules */
904 if (match_subsystem(udev_enumerate, "module"))
905 scan_dir_and_add_devices(udev_enumerate, "module", NULL, NULL);
907 if (stat("/sys/subsystem", &statbuf) == 0)
908 subsysdir = "subsystem";
912 /* all subsystems (only buses support coldplug) */
913 if (match_subsystem(udev_enumerate, "subsystem"))
914 scan_dir_and_add_devices(udev_enumerate, subsysdir, NULL, NULL);
916 /* all subsystem drivers */
917 if (match_subsystem(udev_enumerate, "drivers"))
918 scan_dir(udev_enumerate, subsysdir, "drivers", "drivers");