[BusyBox] find_root_device
Larry Doolittle
ldoolitt at recycle.lbl.gov
Tue May 22 15:53:21 UTC 2001
Without the following patch, df and mount show (null) for the
root device on my 2.0.36 workstation. With this patch, they
correctly find /dev/sda1. The problem is that stat("/",..)
returns st_dev=(8,1), but st_rdev=(0,0). If you tell me
that 2.0.36 is broken, I'll only half believe you. My
uptime is well over six months.
I added more diagnostic detail, and put in a fallback mode
that may be more useful than (null).
I don't fully understand the difference between st_dev and
st_rdev, but I think this patch is correct anyway. :*)
- Larry
--- /home/ldoolitt/cvs/busybox/libbb/find_root_device.c Tue May 15 12:32:17 2001
+++ find_root_device.c Tue May 22 14:43:25 2001
@@ -39,16 +39,18 @@
struct dirent *entry;
struct stat statBuf, rootStat;
char *fileName;
+ dev_t dev;
if (stat("/", &rootStat) != 0) {
- error_msg("could not stat '/'");
+ perror_msg("could not stat '/'");
return NULL;
}
+ if ((dev = rootStat.st_rdev)==0) dev=rootStat.st_dev;
dir = opendir("/dev");
if (!dir) {
- error_msg("could not open '/dev'");
- return NULL;
+ perror_msg("could not open '/dev'");
+ goto fallback;
}
while((entry = readdir(dir)) != NULL) {
@@ -64,14 +66,18 @@
* devices, so make sure this is a block device */
if (stat(fileName, &statBuf) == 0 &&
S_ISBLK(statBuf.st_mode)!=0 &&
- statBuf.st_rdev == rootStat.st_rdev) {
+ statBuf.st_rdev == dev) {
return fileName;
}
free(fileName);
}
closedir(dir);
- return NULL;
+fallback:
+ /* don't use stack space, caller expects to free() result */
+ fileName=xmalloc(20);
+ sprintf(fileName,"(rdev %u)",(unsigned int) rootStat.st_rdev);
+ return fileName;
}
More information about the busybox
mailing list