From ec5bd90916b6e815a36c14ac04d1b78e3e487400 Mon Sep 17 00:00:00 2001 From: Erik Andersen Date: Wed, 22 Mar 2000 07:12:05 +0000 Subject: Use the nice new find_real_root_device function to find the name of the root device, instead of having libc read whatever lies happen to be in /etc/mtab. -Erik --- utility.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'utility.c') 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) } #endif /* BB_FEATURE_MOUNT_LOOP */ -#if defined BB_MOUNT -char* find_real_root_device_name(void) +#if defined BB_MOUNT || defined BB_DF +extern int find_real_root_device_name(char* name) { - int gotIt=0; DIR *dir; struct dirent *entry; struct stat statBuf, rootStat; char fileName[BUFSIZ]; - if (stat("/", &rootStat) != 0) - fatalError("Wierd. I could not stat '/'\n"); + if (stat("/", &rootStat) != 0) { + errorMsg("could not stat '/'\n"); + return( FALSE); + } - if (!(dir = opendir("/dev")); - fatalError("Wierd. I could not open '/dev'\n"); + dir = opendir("/dev"); + if (!dir) { + errorMsg("could not open '/dev'\n"); + return( FALSE); + } 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; @@ -1495,12 +1499,17 @@ char* find_real_root_device_name(void) if (stat(fileName, &statBuf) != 0) continue; + /* Some char devices have the same dev_t as block + * devices, so make sure this is a block device */ + if (! S_ISBLK(statBuf.st_mode)) + continue; if (statBuf.st_rdev == rootStat.st_rdev) { - return (strdup(fileName)); + strcpy(name, fileName); + return ( TRUE); } } - return( NULL); + return( FALSE); } #endif -- cgit v1.2.3