diff options
author | Erik Andersen | 2000-03-22 07:12:05 +0000 |
---|---|---|
committer | Erik Andersen | 2000-03-22 07:12:05 +0000 |
commit | ec5bd90916b6e815a36c14ac04d1b78e3e487400 (patch) | |
tree | 3602e12b02fe289306dccfb27fba31fda53db690 /utility.c | |
parent | 016ffe93077975b01e84493d7cc303f78f70441a (diff) | |
download | busybox-ec5bd90916b6e815a36c14ac04d1b78e3e487400.zip busybox-ec5bd90916b6e815a36c14ac04d1b78e3e487400.tar.gz |
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
Diffstat (limited to 'utility.c')
-rw-r--r-- | utility.c | 29 |
1 files changed, 19 insertions, 10 deletions
@@ -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 |