-enum scan_type {
- SCAN_DEVICES,
- SCAN_SUBSYSTEM,
-};
-
-static void scan_subsystem(struct udev *udev, const char *subsys, enum scan_type scan)
-{
- char base[UTIL_PATH_SIZE];
- DIR *dir;
- struct dirent *dent;
- const char *subdir;
-
- if (scan == SCAN_DEVICES)
- subdir = "/devices";
- else if (scan == SCAN_SUBSYSTEM)
- subdir = "/drivers";
- else
- return;
-
- util_strlcpy(base, udev_get_sys_path(udev), sizeof(base));
- util_strlcat(base, "/", sizeof(base));
- util_strlcat(base, subsys, sizeof(base));
-
- dir = opendir(base);
- if (dir != NULL) {
- for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- char dirname[UTIL_PATH_SIZE];
- DIR *dir2;
- struct dirent *dent2;
-
- if (dent->d_name[0] == '.')
- continue;
-
- if (scan == SCAN_DEVICES)
- if (subsystem_filtered(dent->d_name))
- continue;
-
- util_strlcpy(dirname, base, sizeof(dirname));
- util_strlcat(dirname, "/", sizeof(dirname));
- util_strlcat(dirname, dent->d_name, sizeof(dirname));
-
- if (scan == SCAN_SUBSYSTEM) {
- if (attr_filtered(dirname))
- continue;
- if (!subsystem_filtered("subsystem"))
- device_list_insert(udev, dirname);
- if (subsystem_filtered("drivers"))
- continue;
- }
-
- util_strlcat(dirname, subdir, sizeof(dirname));
-
- /* look for devices/drivers */
- dir2 = opendir(dirname);
- if (dir2 != NULL) {
- for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
- char dirname2[UTIL_PATH_SIZE];
-
- if (dent2->d_name[0] == '.')
- continue;
-
- util_strlcpy(dirname2, dirname, sizeof(dirname2));
- util_strlcat(dirname2, "/", sizeof(dirname2));
- util_strlcat(dirname2, dent2->d_name, sizeof(dirname2));
- if (attr_filtered(dirname2))
- continue;
- device_list_insert(udev, dirname2);
- }
- closedir(dir2);
- }
- }
- closedir(dir);
- }
-}
-
-static void scan_block(struct udev *udev)
-{
- char base[UTIL_PATH_SIZE];
- DIR *dir;
- struct dirent *dent;
-
- if (subsystem_filtered("block"))
- return;
-
- util_strlcpy(base, udev_get_sys_path(udev), sizeof(base));
- util_strlcat(base, "/block", sizeof(base));
-
- dir = opendir(base);
- if (dir != NULL) {
- for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- char dirname[UTIL_PATH_SIZE];
- DIR *dir2;
- struct dirent *dent2;
-
- if (dent->d_name[0] == '.')
- continue;
-
- util_strlcpy(dirname, base, sizeof(dirname));
- util_strlcat(dirname, "/", sizeof(dirname));
- util_strlcat(dirname, dent->d_name, sizeof(dirname));
- if (attr_filtered(dirname))
- continue;
- if (device_list_insert(udev, dirname) != 0)
- continue;
-
- /* look for partitions */
- dir2 = opendir(dirname);
- if (dir2 != NULL) {
- for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
- char dirname2[UTIL_PATH_SIZE];
-
- if (dent2->d_name[0] == '.')
- continue;
-
- if (!strcmp(dent2->d_name,"device"))
- continue;
-
- util_strlcpy(dirname2, dirname, sizeof(dirname2));
- util_strlcat(dirname2, "/", sizeof(dirname2));
- util_strlcat(dirname2, dent2->d_name, sizeof(dirname2));
- if (attr_filtered(dirname2))
- continue;
- device_list_insert(udev, dirname2);
- }
- closedir(dir2);
- }
- }
- closedir(dir);
- }
-}
-
-static void scan_class(struct udev *udev)
-{
- char base[UTIL_PATH_SIZE];
- DIR *dir;
- struct dirent *dent;
-
- util_strlcpy(base, udev_get_sys_path(udev), sizeof(base));
- util_strlcat(base, "/class", sizeof(base));
-
- dir = opendir(base);
- if (dir != NULL) {
- for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- char dirname[UTIL_PATH_SIZE];
- DIR *dir2;
- struct dirent *dent2;
-
- if (dent->d_name[0] == '.')
- continue;
-
- if (subsystem_filtered(dent->d_name))
- continue;
-
- util_strlcpy(dirname, base, sizeof(dirname));
- util_strlcat(dirname, "/", sizeof(dirname));
- util_strlcat(dirname, dent->d_name, sizeof(dirname));
- dir2 = opendir(dirname);
- if (dir2 != NULL) {
- for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
- char dirname2[UTIL_PATH_SIZE];
-
- if (dent2->d_name[0] == '.')
- continue;
-
- if (!strcmp(dent2->d_name, "device"))
- continue;
-
- util_strlcpy(dirname2, dirname, sizeof(dirname2));
- util_strlcat(dirname2, "/", sizeof(dirname2));
- util_strlcat(dirname2, dent2->d_name, sizeof(dirname2));
- if (attr_filtered(dirname2))
- continue;
- device_list_insert(udev, dirname2);
- }
- closedir(dir2);
- }
- }
- closedir(dir);
- }
-}
-
-static void scan_failed(struct udev *udev)