-
- if (stat("/", &rootStat) != 0)
- bb_perror_msg("could not stat '/'");
- else {
- if ((dev = rootStat.st_rdev)==0)
- dev=rootStat.st_dev;
-
- dir = opendir("/dev");
- if (!dir)
- bb_perror_msg("could not open '/dev'");
- else {
- while((entry = readdir(dir)) != NULL) {
-
- /* Must skip ".." since that is "/", and so we
- * would get a false positive on ".." */
- if (strcmp(entry->d_name, "..") == 0)
- continue;
-
- fileName = concat_path_file("/dev", entry->d_name);
-
- /* Some char devices have the same dev_t as block
- * devices, so make sure this is a block device */
- if (stat(fileName, &statBuf) == 0 &&
- S_ISBLK(statBuf.st_mode)!=0 &&
- statBuf.st_rdev == dev)
- break;
- free(fileName);
- fileName=NULL;
- }
- closedir(dir);
+ char *retpath=NULL;
+
+ if(stat(path, &st) || !(dir = opendir("/dev"))) return NULL;
+ dev = (st.st_mode & S_IFMT) == S_IFBLK ? st.st_rdev : st.st_dev;
+ while((entry = readdir(dir)) != NULL) {
+ char devpath[PATH_MAX];
+ sprintf(devpath,"/dev/%s", entry->d_name);
+ if(!stat(devpath, &st) && S_ISBLK(st.st_mode) && st.st_rdev == dev) {
+ retpath = xstrdup(devpath);
+ break;