aboutsummaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/utility.c b/utility.c
index 37f698ea4..c779cc6ba 100644
--- a/utility.c
+++ b/utility.c
@@ -1469,25 +1469,29 @@ extern char *find_unused_loop_device(void)
1469} 1469}
1470#endif /* BB_FEATURE_MOUNT_LOOP */ 1470#endif /* BB_FEATURE_MOUNT_LOOP */
1471 1471
1472#if defined BB_MOUNT 1472#if defined BB_MOUNT || defined BB_DF
1473char* find_real_root_device_name(void) 1473extern int find_real_root_device_name(char* name)
1474{ 1474{
1475 int gotIt=0;
1476 DIR *dir; 1475 DIR *dir;
1477 struct dirent *entry; 1476 struct dirent *entry;
1478 struct stat statBuf, rootStat; 1477 struct stat statBuf, rootStat;
1479 char fileName[BUFSIZ]; 1478 char fileName[BUFSIZ];
1480 1479
1481 if (stat("/", &rootStat) != 0) 1480 if (stat("/", &rootStat) != 0) {
1482 fatalError("Wierd. I could not stat '/'\n"); 1481 errorMsg("could not stat '/'\n");
1482 return( FALSE);
1483 }
1483 1484
1484 if (!(dir = opendir("/dev")); 1485 dir = opendir("/dev");
1485 fatalError("Wierd. I could not open '/dev'\n"); 1486 if (!dir) {
1487 errorMsg("could not open '/dev'\n");
1488 return( FALSE);
1489 }
1486 1490
1487 while((entry = readdir(dir)) != NULL) { 1491 while((entry = readdir(dir)) != NULL) {
1492
1488 /* Must skip ".." since that is "/", and so we 1493 /* Must skip ".." since that is "/", and so we
1489 * would get a false positive on ".." */ 1494 * would get a false positive on ".." */
1490
1491 if (strcmp(entry->d_name, "..") == 0) 1495 if (strcmp(entry->d_name, "..") == 0)
1492 continue; 1496 continue;
1493 1497
@@ -1495,12 +1499,17 @@ char* find_real_root_device_name(void)
1495 1499
1496 if (stat(fileName, &statBuf) != 0) 1500 if (stat(fileName, &statBuf) != 0)
1497 continue; 1501 continue;
1502 /* Some char devices have the same dev_t as block
1503 * devices, so make sure this is a block device */
1504 if (! S_ISBLK(statBuf.st_mode))
1505 continue;
1498 if (statBuf.st_rdev == rootStat.st_rdev) { 1506 if (statBuf.st_rdev == rootStat.st_rdev) {
1499 return (strdup(fileName)); 1507 strcpy(name, fileName);
1508 return ( TRUE);
1500 } 1509 }
1501 } 1510 }
1502 1511
1503 return( NULL); 1512 return( FALSE);
1504} 1513}
1505#endif 1514#endif
1506 1515