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 * Create an enumeration context to scan /sys.
70 * Returns: an enumeration context.
72 _public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev)
74 struct udev_enumerate *udev_enumerate;
76 udev_enumerate = calloc(1, sizeof(struct udev_enumerate));
77 if (udev_enumerate == NULL)
79 udev_enumerate->refcount = 1;
80 udev_enumerate->udev = udev;
81 udev_list_init(udev, &udev_enumerate->sysattr_match_list, false);
82 udev_list_init(udev, &udev_enumerate->sysattr_nomatch_list, false);
83 udev_list_init(udev, &udev_enumerate->subsystem_match_list, true);
84 udev_list_init(udev, &udev_enumerate->subsystem_nomatch_list, true);
85 udev_list_init(udev, &udev_enumerate->sysname_match_list, true);
86 udev_list_init(udev, &udev_enumerate->properties_match_list, false);
87 udev_list_init(udev, &udev_enumerate->tags_match_list, true);
88 udev_list_init(udev, &udev_enumerate->devices_list, false);
89 return udev_enumerate;
94 * @udev_enumerate: context
96 * Take a reference of a enumeration context.
98 * Returns: the passed enumeration context
100 _public_ struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate)
102 if (udev_enumerate == NULL)
104 udev_enumerate->refcount++;
105 return udev_enumerate;
109 * udev_enumerate_unref:
110 * @udev_enumerate: context
112 * Drop a reference of an enumeration context. If the refcount reaches zero,
113 * all resources of the enumeration context will be released.
115 _public_ struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate)
119 if (udev_enumerate == NULL)
121 udev_enumerate->refcount--;
122 if (udev_enumerate->refcount > 0)
123 return udev_enumerate;
124 udev_list_cleanup(&udev_enumerate->sysattr_match_list);
125 udev_list_cleanup(&udev_enumerate->sysattr_nomatch_list);
126 udev_list_cleanup(&udev_enumerate->subsystem_match_list);
127 udev_list_cleanup(&udev_enumerate->subsystem_nomatch_list);
128 udev_list_cleanup(&udev_enumerate->sysname_match_list);
129 udev_list_cleanup(&udev_enumerate->properties_match_list);
130 udev_list_cleanup(&udev_enumerate->tags_match_list);
131 udev_device_unref(udev_enumerate->parent_match);
132 udev_list_cleanup(&udev_enumerate->devices_list);
133 for (i = 0; i < udev_enumerate->devices_cur; i++)
134 free(udev_enumerate->devices[i].syspath);
135 free(udev_enumerate->devices);
136 free(udev_enumerate);
141 * udev_enumerate_get_udev:
142 * @udev_enumerate: context
144 * Get the udev library context.
146 * Returns: a pointer to the context.
148 _public_ struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate)
150 if (udev_enumerate == NULL)
152 return udev_enumerate->udev;
155 static int syspath_add(struct udev_enumerate *udev_enumerate, const char *syspath)
158 struct syspath *entry;
160 /* double array size if needed */
161 if (udev_enumerate->devices_cur >= udev_enumerate->devices_max) {
165 add = udev_enumerate->devices_max;
168 buf = realloc(udev_enumerate->devices, (udev_enumerate->devices_max + add) * sizeof(struct syspath));
171 udev_enumerate->devices = buf;
172 udev_enumerate->devices_max += add;
175 path = strdup(syspath);
178 entry = &udev_enumerate->devices[udev_enumerate->devices_cur];
179 entry->syspath = path;
180 entry->len = strlen(path);
181 udev_enumerate->devices_cur++;
182 udev_enumerate->devices_uptodate = false;
186 static int syspath_cmp(const void *p1, const void *p2)
188 const struct syspath *path1 = p1;
189 const struct syspath *path2 = p2;
193 len = MIN(path1->len, path2->len);
194 ret = memcmp(path1->syspath, path2->syspath, len);
196 if (path1->len < path2->len)
198 else if (path1->len > path2->len)
204 /* For devices that should be moved to the absolute end of the list */
205 static bool devices_delay_end(struct udev *udev, const char *syspath)
207 static const char *delay_device_list[] = {
214 for (i = 0; delay_device_list[i] != NULL; i++) {
215 if (strstr(syspath + strlen("/sys"), delay_device_list[i]) != NULL)
221 /* For devices that should just be moved a little bit later, just
222 * before the point where some common path prefix changes. Returns the
223 * number of characters that make up that common prefix */
224 static size_t devices_delay_later(struct udev *udev, const char *syspath)
228 /* For sound cards the control device must be enumerated last
229 * to make sure it's the final device node that gets ACLs
230 * applied. Applications rely on this fact and use ACL changes
231 * on the control node as an indicator that the ACL change of
232 * the entire sound card completed. The kernel makes this
233 * guarantee when creating those devices, and hence we should
234 * too when enumerating them. */
236 if ((c = strstr(syspath, "/sound/card"))) {
238 c += strcspn(c, "/");
240 if (startswith(c, "/controlC"))
241 return c - syspath + 1;
248 * udev_enumerate_get_list_entry:
249 * @udev_enumerate: context
251 * Get the first entry of the sorted list of device paths.
253 * Returns: a udev_list_entry.
255 _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate)
257 if (udev_enumerate == NULL)
259 if (!udev_enumerate->devices_uptodate) {
262 struct syspath *prev = NULL, *move_later = NULL;
263 size_t move_later_prefix = 0;
265 udev_list_cleanup(&udev_enumerate->devices_list);
266 qsort(udev_enumerate->devices, udev_enumerate->devices_cur, sizeof(struct syspath), syspath_cmp);
268 max = udev_enumerate->devices_cur;
269 for (i = 0; i < max; i++) {
270 struct syspath *entry = &udev_enumerate->devices[i];
272 /* skip duplicated entries */
274 entry->len == prev->len &&
275 memcmp(entry->syspath, prev->syspath, entry->len) == 0)
279 /* skip to be delayed devices, and add them to the end of the list */
280 if (devices_delay_end(udev_enumerate->udev, entry->syspath)) {
281 syspath_add(udev_enumerate, entry->syspath);
282 /* need to update prev here for the case realloc() gives a different address */
283 prev = &udev_enumerate->devices[i];
287 /* skip to be delayed devices, and move the to
288 * the point where the prefix changes. We can
289 * only move one item at a time. */
291 move_later_prefix = devices_delay_later(udev_enumerate->udev, entry->syspath);
293 if (move_later_prefix > 0) {
300 strncmp(entry->syspath, move_later->syspath, move_later_prefix) != 0) {
302 udev_list_entry_add(&udev_enumerate->devices_list, move_later->syspath, NULL);
306 udev_list_entry_add(&udev_enumerate->devices_list, entry->syspath, NULL);
310 udev_list_entry_add(&udev_enumerate->devices_list, move_later->syspath, NULL);
312 /* add and cleanup delayed devices from end of list */
313 for (i = max; i < udev_enumerate->devices_cur; i++) {
314 struct syspath *entry = &udev_enumerate->devices[i];
316 udev_list_entry_add(&udev_enumerate->devices_list, entry->syspath, NULL);
317 free(entry->syspath);
319 udev_enumerate->devices_cur = max;
321 udev_enumerate->devices_uptodate = true;
323 return udev_list_get_entry(&udev_enumerate->devices_list);
327 * udev_enumerate_add_match_subsystem:
328 * @udev_enumerate: context
329 * @subsystem: filter for a subsystem of the device to include in the list
331 * Match only devices belonging to a certain kernel subsystem.
333 * Returns: 0 on success, otherwise a negative error value.
335 _public_ int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
337 if (udev_enumerate == NULL)
339 if (subsystem == NULL)
341 if (udev_list_entry_add(&udev_enumerate->subsystem_match_list, subsystem, NULL) == NULL)
347 * udev_enumerate_add_nomatch_subsystem:
348 * @udev_enumerate: context
349 * @subsystem: filter for a subsystem of the device to exclude from the list
351 * Match only devices not belonging to a certain kernel subsystem.
353 * Returns: 0 on success, otherwise a negative error value.
355 _public_ int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
357 if (udev_enumerate == NULL)
359 if (subsystem == NULL)
361 if (udev_list_entry_add(&udev_enumerate->subsystem_nomatch_list, subsystem, NULL) == NULL)
367 * udev_enumerate_add_match_sysattr:
368 * @udev_enumerate: context
369 * @sysattr: filter for a sys attribute at the device to include in the list
370 * @value: optional value of the sys attribute
372 * Match only devices with a certain /sys device attribute.
374 * Returns: 0 on success, otherwise a negative error value.
376 _public_ int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value)
378 if (udev_enumerate == NULL)
382 if (udev_list_entry_add(&udev_enumerate->sysattr_match_list, sysattr, value) == NULL)
388 * udev_enumerate_add_nomatch_sysattr:
389 * @udev_enumerate: context
390 * @sysattr: filter for a sys attribute at the device to exclude from the list
391 * @value: optional value of the sys attribute
393 * Match only devices not having a certain /sys device attribute.
395 * Returns: 0 on success, otherwise a negative error value.
397 _public_ int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value)
399 if (udev_enumerate == NULL)
403 if (udev_list_entry_add(&udev_enumerate->sysattr_nomatch_list, sysattr, value) == NULL)
408 static int match_sysattr_value(struct udev_device *dev, const char *sysattr, const char *match_val)
410 const char *val = NULL;
413 val = udev_device_get_sysattr_value(dev, sysattr);
416 if (match_val == NULL) {
420 if (fnmatch(match_val, val, 0) == 0) {
429 * udev_enumerate_add_match_property:
430 * @udev_enumerate: context
431 * @property: filter for a property of the device to include in the list
432 * @value: value of the property
434 * Match only devices with a certain property.
436 * Returns: 0 on success, otherwise a negative error value.
438 _public_ int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value)
440 if (udev_enumerate == NULL)
442 if (property == NULL)
444 if (udev_list_entry_add(&udev_enumerate->properties_match_list, property, value) == NULL)
450 * udev_enumerate_add_match_tag:
451 * @udev_enumerate: context
452 * @tag: filter for a tag of the device to include in the list
454 * Match only devices with a certain tag.
456 * Returns: 0 on success, otherwise a negative error value.
458 _public_ int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag)
460 if (udev_enumerate == NULL)
464 if (udev_list_entry_add(&udev_enumerate->tags_match_list, tag, NULL) == NULL)
470 * udev_enumerate_add_match_parent:
471 * @udev_enumerate: context
472 * @parent: parent device where to start searching
474 * Return the devices on the subtree of one given device. The parent
475 * itself is included in the list.
477 * A reference for the device is held until the udev_enumerate context
480 * Returns: 0 on success, otherwise a negative error value.
482 _public_ int udev_enumerate_add_match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *parent)
484 if (udev_enumerate == NULL)
488 if (udev_enumerate->parent_match != NULL)
489 udev_device_unref(udev_enumerate->parent_match);
490 udev_enumerate->parent_match = udev_device_ref(parent);
495 * udev_enumerate_add_match_is_initialized:
496 * @udev_enumerate: context
498 * Match only devices which udev has set up already. This makes
499 * sure, that the device node permissions and context are properly set
500 * and that network devices are fully renamed.
502 * Usually, devices which are found in the kernel but not already
503 * handled by udev, have still pending events. Services should subscribe
504 * to monitor events and wait for these devices to become ready, instead
505 * of using uninitialized devices.
507 * For now, this will not affect devices which do not have a device node
508 * and are not network interfaces.
510 * Returns: 0 on success, otherwise a negative error value.
512 _public_ int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev_enumerate)
514 if (udev_enumerate == NULL)
516 udev_enumerate->match_is_initialized = true;
521 * udev_enumerate_add_match_sysname:
522 * @udev_enumerate: context
523 * @sysname: filter for the name of the device to include in the list
525 * Match only devices with a given /sys device name.
527 * Returns: 0 on success, otherwise a negative error value.
529 _public_ int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname)
531 if (udev_enumerate == NULL)
535 if (udev_list_entry_add(&udev_enumerate->sysname_match_list, sysname, NULL) == NULL)
540 static bool match_sysattr(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
542 struct udev_list_entry *list_entry;
545 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->sysattr_nomatch_list)) {
546 if (match_sysattr_value(dev, udev_list_entry_get_name(list_entry),
547 udev_list_entry_get_value(list_entry)))
551 if (udev_list_get_entry(&udev_enumerate->sysattr_match_list) != NULL) {
552 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->sysattr_match_list)) {
553 /* anything that does not match, will make it FALSE */
554 if (!match_sysattr_value(dev, udev_list_entry_get_name(list_entry),
555 udev_list_entry_get_value(list_entry)))
563 static bool match_property(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
565 struct udev_list_entry *list_entry;
568 /* no match always matches */
569 if (udev_list_get_entry(&udev_enumerate->properties_match_list) == NULL)
572 /* loop over matches */
573 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->properties_match_list)) {
574 const char *match_key = udev_list_entry_get_name(list_entry);
575 const char *match_value = udev_list_entry_get_value(list_entry);
576 struct udev_list_entry *property_entry;
578 /* loop over device properties */
579 udev_list_entry_foreach(property_entry, udev_device_get_properties_list_entry(dev)) {
580 const char *dev_key = udev_list_entry_get_name(property_entry);
581 const char *dev_value = udev_list_entry_get_value(property_entry);
583 if (fnmatch(match_key, dev_key, 0) != 0)
585 if (match_value == NULL && dev_value == NULL) {
589 if (match_value == NULL || dev_value == NULL)
591 if (fnmatch(match_value, dev_value, 0) == 0) {
601 static bool match_tag(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
603 struct udev_list_entry *list_entry;
605 /* no match always matches */
606 if (udev_list_get_entry(&udev_enumerate->tags_match_list) == NULL)
609 /* loop over matches */
610 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->tags_match_list))
611 if (!udev_device_has_tag(dev, udev_list_entry_get_name(list_entry)))
617 static bool match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
619 if (udev_enumerate->parent_match == NULL)
622 return startswith(udev_device_get_devpath(dev), udev_device_get_devpath(udev_enumerate->parent_match));
625 static bool match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname)
627 struct udev_list_entry *list_entry;
629 if (udev_list_get_entry(&udev_enumerate->sysname_match_list) == NULL)
632 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->sysname_match_list)) {
633 if (fnmatch(udev_list_entry_get_name(list_entry), sysname, 0) != 0)
640 static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate,
641 const char *basedir, const char *subdir1, const char *subdir2)
643 char path[UTIL_PATH_SIZE];
650 l = util_strpcpyl(&s, sizeof(path), "/sys/", basedir, NULL);
652 l = util_strpcpyl(&s, l, "/", subdir1, NULL);
654 util_strpcpyl(&s, l, "/", subdir2, NULL);
658 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
659 char syspath[UTIL_PATH_SIZE];
660 struct udev_device *dev;
662 if (dent->d_name[0] == '.')
665 if (!match_sysname(udev_enumerate, dent->d_name))
668 util_strscpyl(syspath, sizeof(syspath), path, "/", dent->d_name, NULL);
669 dev = udev_device_new_from_syspath(udev_enumerate->udev, syspath);
673 if (udev_enumerate->match_is_initialized) {
675 * All devices with a device node or network interfaces
676 * possibly need udev to adjust the device node permission
677 * or context, or rename the interface before it can be
678 * reliably used from other processes.
680 * For now, we can only check these types of devices, we
681 * might not store a database, and have no way to find out
682 * for all other types of devices.
684 if (!udev_device_get_is_initialized(dev) &&
685 (major(udev_device_get_devnum(dev)) > 0 || udev_device_get_ifindex(dev) > 0))
688 if (!match_parent(udev_enumerate, dev))
690 if (!match_tag(udev_enumerate, dev))
692 if (!match_property(udev_enumerate, dev))
694 if (!match_sysattr(udev_enumerate, dev))
697 syspath_add(udev_enumerate, udev_device_get_syspath(dev));
699 udev_device_unref(dev);
705 static bool match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
707 struct udev_list_entry *list_entry;
709 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->subsystem_nomatch_list)) {
710 if (fnmatch(udev_list_entry_get_name(list_entry), subsystem, 0) == 0)
713 if (udev_list_get_entry(&udev_enumerate->subsystem_match_list) != NULL) {
714 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->subsystem_match_list)) {
715 if (fnmatch(udev_list_entry_get_name(list_entry), subsystem, 0) == 0)
723 static int scan_dir(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir, const char *subsystem)
725 char path[UTIL_PATH_SIZE];
729 util_strscpyl(path, sizeof(path), "/sys/", basedir, NULL);
733 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
734 if (dent->d_name[0] == '.')
736 if (!match_subsystem(udev_enumerate, subsystem != NULL ? subsystem : dent->d_name))
738 scan_dir_and_add_devices(udev_enumerate, basedir, dent->d_name, subdir);
745 * udev_enumerate_add_syspath:
746 * @udev_enumerate: context
747 * @syspath: path of a device
749 * Add a device to the list of devices, to retrieve it back sorted in dependency order.
751 * Returns: 0 on success, otherwise a negative error value.
753 _public_ int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath)
755 struct udev_device *udev_device;
757 if (udev_enumerate == NULL)
761 /* resolve to real syspath */
762 udev_device = udev_device_new_from_syspath(udev_enumerate->udev, syspath);
763 if (udev_device == NULL)
765 syspath_add(udev_enumerate, udev_device_get_syspath(udev_device));
766 udev_device_unref(udev_device);
770 static int scan_devices_tags(struct udev_enumerate *udev_enumerate)
772 struct udev_list_entry *list_entry;
774 /* scan only tagged devices, use tags reverse-index, instead of searching all devices in /sys */
775 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->tags_match_list)) {
778 char path[UTIL_PATH_SIZE];
780 util_strscpyl(path, sizeof(path), "/run/udev/tags/", udev_list_entry_get_name(list_entry), NULL);
784 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
785 struct udev_device *dev;
787 if (dent->d_name[0] == '.')
790 dev = udev_device_new_from_id_filename(udev_enumerate->udev, dent->d_name);
794 if (!match_subsystem(udev_enumerate, udev_device_get_subsystem(dev)))
796 if (!match_sysname(udev_enumerate, udev_device_get_sysname(dev)))
798 if (!match_parent(udev_enumerate, dev))
800 if (!match_property(udev_enumerate, dev))
802 if (!match_sysattr(udev_enumerate, dev))
805 syspath_add(udev_enumerate, udev_device_get_syspath(dev));
807 udev_device_unref(dev);
814 static int parent_add_child(struct udev_enumerate *enumerate, const char *path)
816 struct udev_device *dev;
818 dev = udev_device_new_from_syspath(enumerate->udev, path);
822 if (!match_subsystem(enumerate, udev_device_get_subsystem(dev)))
824 if (!match_sysname(enumerate, udev_device_get_sysname(dev)))
826 if (!match_property(enumerate, dev))
828 if (!match_sysattr(enumerate, dev))
831 syspath_add(enumerate, udev_device_get_syspath(dev));
832 udev_device_unref(dev);
836 static int parent_crawl_children(struct udev_enumerate *enumerate, const char *path, int maxdepth)
845 for (dent = readdir(d); dent != NULL; dent = readdir(d)) {
848 if (dent->d_name[0] == '.')
850 if (dent->d_type != DT_DIR)
852 if (asprintf(&child, "%s/%s", path, dent->d_name) < 0)
854 parent_add_child(enumerate, child);
856 parent_crawl_children(enumerate, child, maxdepth-1);
864 static int scan_devices_children(struct udev_enumerate *enumerate)
868 path = udev_device_get_syspath(enumerate->parent_match);
869 parent_add_child(enumerate, path);
870 return parent_crawl_children(enumerate, path, 256);
873 static int scan_devices_all(struct udev_enumerate *udev_enumerate)
877 if (stat("/sys/subsystem", &statbuf) == 0) {
878 /* we have /subsystem/, forget all the old stuff */
879 scan_dir(udev_enumerate, "subsystem", "devices", NULL);
881 scan_dir(udev_enumerate, "bus", "devices", NULL);
882 scan_dir(udev_enumerate, "class", NULL, NULL);
888 * udev_enumerate_scan_devices:
889 * @udev_enumerate: udev enumeration context
891 * Scan /sys for all devices which match the given filters. No matches
892 * will return all currently available devices.
894 * Returns: 0 on success, otherwise a negative error value.
896 _public_ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate)
898 if (udev_enumerate == NULL)
901 /* efficiently lookup tags only, we maintain a reverse-index */
902 if (udev_list_get_entry(&udev_enumerate->tags_match_list) != NULL)
903 return scan_devices_tags(udev_enumerate);
905 /* walk the subtree of one parent device only */
906 if (udev_enumerate->parent_match != NULL)
907 return scan_devices_children(udev_enumerate);
909 /* scan devices of all subsystems */
910 return scan_devices_all(udev_enumerate);
914 * udev_enumerate_scan_subsystems:
915 * @udev_enumerate: udev enumeration context
917 * Scan /sys for all kernel subsystems, including buses, classes, drivers.
919 * Returns: 0 on success, otherwise a negative error value.
921 _public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate)
924 const char *subsysdir;
926 if (udev_enumerate == NULL)
929 /* all kernel modules */
930 if (match_subsystem(udev_enumerate, "module"))
931 scan_dir_and_add_devices(udev_enumerate, "module", NULL, NULL);
933 if (stat("/sys/subsystem", &statbuf) == 0)
934 subsysdir = "subsystem";
938 /* all subsystems (only buses support coldplug) */
939 if (match_subsystem(udev_enumerate, "subsystem"))
940 scan_dir_and_add_devices(udev_enumerate, subsysdir, NULL, NULL);
942 /* all subsystem drivers */
943 if (match_subsystem(udev_enumerate, "drivers"))
944 scan_dir(udev_enumerate, subsysdir, "drivers", "drivers");