return 0;
}
-static void scan_subdir(const char *base)
+static void scan_subdir(const char *base, const char *subdir,
+ bool insert, int depth)
{
DIR *dir;
struct dirent *dent;
strlcpy(dirname, base, sizeof(dirname));
strlcat(dirname, "/", sizeof(dirname));
strlcat(dirname, dent->d_name, sizeof(dirname));
- device_list_insert(dirname);
+
+ if (insert) {
+ int err;
+
+ err = device_list_insert(dirname);
+ if (err)
+ continue;
+ }
+
+ if (subdir)
+ strlcat(dirname, subdir, sizeof(base));
+
+ if (depth)
+ scan_subdir(dirname, NULL, true, depth - 1);
}
closedir(dir);
strlcat(dirname, "/devices", sizeof(dirname));
/* look for devices */
- scan_subdir(dirname);
+ scan_subdir(dirname, NULL, true, 0);
}
closedir(dir);
continue;
/* look for partitions */
- scan_subdir(dirname);
+ scan_subdir(dirname, NULL, true, 0);
}
closedir(dir);
strlcat(dirname, "/", sizeof(dirname));
strlcat(dirname, dent->d_name, sizeof(dirname));
- scan_subdir(dirname);
+ scan_subdir(dirname, NULL, true, 0);
}
closedir(dir);