- if (argc > 1) {
- if (argc == 2 && !strcmp(argv[1],"-s")) {
- RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
- strcpy(temp,"/sys/block");
- find_dev(temp);
- strcpy(temp,"/sys/class");
- find_dev(temp);
- if(ENABLE_FEATURE_CLEAN_UP)
- RELEASE_CONFIG_BUFFER(temp);
- return 0;
- } else bb_show_usage();
- }
-
-/* hotplug support goes here */
-
+ char *action;
+ char *env_path;
+ RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
+
+ bb_xchdir(DEV_PATH);
+
+ /* Scan */
+
+ if (argc == 2 && !strcmp(argv[1],"-s")) {
+ struct stat st;
+
+ stat("/", &st); // If this fails, we have bigger problems.
+ bbg.root_major=major(st.st_dev);
+ bbg.root_minor=minor(st.st_dev);
+ strcpy(temp,"/sys/block");
+ find_dev(temp);
+ strcpy(temp,"/sys/class");
+ find_dev(temp);
+
+ /* Hotplug */
+
+ } else {
+ action = getenv("ACTION");
+ env_path = getenv("DEVPATH");
+ if (!action || !env_path)
+ bb_show_usage();
+
+ if (!strcmp(action, "add")) {
+ sprintf(temp, "/sys%s", env_path);
+ make_device(temp);
+ } else if (!strcmp(action, "remove")) {
+ unlink(strrchr(env_path, '/') + 1);
+ }
+ }
+
+ if (ENABLE_FEATURE_CLEAN_UP) RELEASE_CONFIG_BUFFER(temp);