diff options
Diffstat (limited to 'libbb/find_root_device.c')
-rw-r--r-- | libbb/find_root_device.c | 70 |
1 files changed, 15 insertions, 55 deletions
diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c index 2600ce5e0..7ff65bb57 100644 --- a/libbb/find_root_device.c +++ b/libbb/find_root_device.c | |||
@@ -25,65 +25,25 @@ | |||
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | #include "libbb.h" | 26 | #include "libbb.h" |
27 | 27 | ||
28 | 28 | extern char *find_block_device(char *path) | |
29 | |||
30 | extern char *find_real_root_device_name(void) | ||
31 | { | 29 | { |
32 | DIR *dir; | 30 | DIR *dir; |
33 | struct dirent *entry; | 31 | struct dirent *entry; |
34 | struct stat statBuf, rootStat; | 32 | struct stat st; |
35 | char *fileName = NULL; | ||
36 | dev_t dev; | 33 | dev_t dev; |
37 | 34 | char *retpath=NULL; | |
38 | if (stat("/", &rootStat) != 0) | 35 | |
39 | bb_perror_msg("could not stat '/'"); | 36 | if(stat(path, &st) || !(dir = opendir("/dev"))) return NULL; |
40 | else { | 37 | dev = (st.st_mode & S_IFMT) == S_IFBLK ? st.st_rdev : st.st_dev; |
41 | /* This check is here in case they pass in /dev name */ | 38 | while((entry = readdir(dir)) != NULL) { |
42 | if ((rootStat.st_mode & S_IFMT) == S_IFBLK) | 39 | char devpath[PATH_MAX]; |
43 | dev = rootStat.st_rdev; | 40 | sprintf(devpath,"/dev/%s", entry->d_name); |
44 | else | 41 | if(!stat(devpath, &st) && S_ISBLK(st.st_mode) && st.st_rdev == dev) { |
45 | dev = rootStat.st_dev; | 42 | retpath = bb_xstrdup(devpath); |
46 | 43 | break; | |
47 | dir = opendir("/dev"); | ||
48 | if (!dir) | ||
49 | bb_perror_msg("could not open '/dev'"); | ||
50 | else { | ||
51 | while((entry = readdir(dir)) != NULL) { | ||
52 | const char *myname = entry->d_name; | ||
53 | /* Must skip ".." since that is "/", and so we | ||
54 | * would get a false positive on ".." */ | ||
55 | if (myname[0] == '.' && myname[1] == '.' && !myname[2]) | ||
56 | continue; | ||
57 | #ifdef CONFIG_FEATURE_DEVFS | ||
58 | /* if there is a link named /dev/root skip that too */ | ||
59 | if (strcmp(myname, "root")==0) | ||
60 | continue; | ||
61 | #endif | ||
62 | fileName = concat_path_file("/dev", myname); | ||
63 | |||
64 | /* Some char devices have the same dev_t as block | ||
65 | * devices, so make sure this is a block device */ | ||
66 | if (stat(fileName, &statBuf) == 0 && | ||
67 | S_ISBLK(statBuf.st_mode)!=0 && | ||
68 | statBuf.st_rdev == dev) | ||
69 | break; | ||
70 | free(fileName); | ||
71 | fileName=NULL; | ||
72 | } | ||
73 | closedir(dir); | ||
74 | } | 44 | } |
75 | } | 45 | } |
76 | if(fileName==NULL) | 46 | closedir(dir); |
77 | fileName = bb_xstrdup("/dev/root"); | ||
78 | return fileName; | ||
79 | } | ||
80 | |||
81 | 47 | ||
82 | /* END CODE */ | 48 | return retpath; |
83 | /* | 49 | } |
84 | Local Variables: | ||
85 | c-file-style: "linux" | ||
86 | c-basic-offset: 4 | ||
87 | tab-width: 4 | ||
88 | End: | ||
89 | */ | ||