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
This commit is contained in:
Erik Andersen 2000-03-22 07:12:05 +00:00
parent 016ffe9307
commit ec5bd90916
8 changed files with 39 additions and 54 deletions

View File

@ -27,7 +27,6 @@
#include <mntent.h> #include <mntent.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/vfs.h> #include <sys/vfs.h>
#include <fstab.h>
static const char df_usage[] = "df [filesystem ...]\n" static const char df_usage[] = "df [filesystem ...]\n"
@ -40,7 +39,6 @@ static int df(char *device, const char *mountPoint)
struct statfs s; struct statfs s;
long blocks_used; long blocks_used;
long blocks_percent_used; long blocks_percent_used;
struct fstab *fstabItem;
if (statfs(mountPoint, &s) != 0) { if (statfs(mountPoint, &s) != 0) {
perror(mountPoint); perror(mountPoint);
@ -53,9 +51,9 @@ static int df(char *device, const char *mountPoint)
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
if (strcmp(device, "/dev/root") == 0) { if (strcmp(device, "/dev/root") == 0) {
fstabItem = getfsfile("/"); /* Adjusts device to be the real root device,
if (fstabItem != NULL) * or leaves device alone if it can't find it */
device = fstabItem->fs_spec; find_real_root_device_name( device);
} }
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
device, device,

8
df.c
View File

@ -27,7 +27,6 @@
#include <mntent.h> #include <mntent.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/vfs.h> #include <sys/vfs.h>
#include <fstab.h>
static const char df_usage[] = "df [filesystem ...]\n" static const char df_usage[] = "df [filesystem ...]\n"
@ -40,7 +39,6 @@ static int df(char *device, const char *mountPoint)
struct statfs s; struct statfs s;
long blocks_used; long blocks_used;
long blocks_percent_used; long blocks_percent_used;
struct fstab *fstabItem;
if (statfs(mountPoint, &s) != 0) { if (statfs(mountPoint, &s) != 0) {
perror(mountPoint); perror(mountPoint);
@ -53,9 +51,9 @@ static int df(char *device, const char *mountPoint)
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
if (strcmp(device, "/dev/root") == 0) { if (strcmp(device, "/dev/root") == 0) {
fstabItem = getfsfile("/"); /* Adjusts device to be the real root device,
if (fstabItem != NULL) * or leaves device alone if it can't find it */
device = fstabItem->fs_spec; find_real_root_device_name( device);
} }
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
device, device,

View File

@ -216,6 +216,8 @@ extern int check_wildcard_match(const char* text, const char* pattern);
extern long getNum (const char *cp); extern long getNum (const char *cp);
extern pid_t findPidByName( char* pidName); extern pid_t findPidByName( char* pidName);
extern void *xmalloc (size_t size); extern void *xmalloc (size_t size);
extern int find_real_root_device_name(char* name);
#ifdef BB_FEATURE_SH_COMMAND_EDITING #ifdef BB_FEATURE_SH_COMMAND_EDITING
#include <stdio.h> #include <stdio.h>
extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd, char command[BUFSIZ]); extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd, char command[BUFSIZ]);

13
mount.c
View File

@ -45,7 +45,6 @@
#include <mntent.h> #include <mntent.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <ctype.h> #include <ctype.h>
#include <fstab.h>
#if defined BB_FEATURE_USE_DEVPS_PATCH #if defined BB_FEATURE_USE_DEVPS_PATCH
#include <linux/devmtab.h> #include <linux/devmtab.h>
#endif #endif
@ -321,9 +320,6 @@ extern int mount_main(int argc, char **argv)
int useMtab = TRUE; int useMtab = TRUE;
int i; int i;
/* Only compiled in if BB_MTAB is not defined */
whine_if_fstab_is_missing();
#if defined BB_FEATURE_USE_DEVPS_PATCH #if defined BB_FEATURE_USE_DEVPS_PATCH
if (argc == 1) { if (argc == 1) {
int fd, i, numfilesystems; int fd, i, numfilesystems;
@ -364,14 +360,9 @@ extern int mount_main(int argc, char **argv)
struct mntent *m; struct mntent *m;
while ((m = getmntent(mountTable)) != 0) { while ((m = getmntent(mountTable)) != 0) {
struct fstab *fstabItem;
char *blockDevice = m->mnt_fsname; char *blockDevice = m->mnt_fsname;
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
if (strcmp(blockDevice, "/dev/root") == 0) { if (strcmp(blockDevice, "/dev/root") == 0) {
fstabItem = getfsfile("/"); find_real_root_device_name( blockDevice);
if (fstabItem != NULL)
blockDevice = fstabItem->fs_spec;
} }
printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir,
m->mnt_type, m->mnt_opts); m->mnt_type, m->mnt_opts);
@ -445,7 +436,7 @@ extern int mount_main(int argc, char **argv)
FILE *f = setmntent("/etc/fstab", "r"); FILE *f = setmntent("/etc/fstab", "r");
if (f == NULL) if (f == NULL)
fatalError( "\nCannot ream /etc/fstab: %s\n", strerror (errno)); fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno));
while ((m = getmntent(f)) != NULL) { while ((m = getmntent(f)) != NULL) {
// If the file system isn't noauto, // If the file system isn't noauto,

View File

@ -26,7 +26,6 @@
#include <stdio.h> #include <stdio.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <mntent.h> #include <mntent.h>
#include <fstab.h>
#include <errno.h> #include <errno.h>
@ -110,11 +109,10 @@ char *mtab_getinfo(const char *match, const char which)
} else { } else {
#if !defined BB_MTAB #if !defined BB_MTAB
if (strcmp(cur->device, "/dev/root") == 0) { if (strcmp(cur->device, "/dev/root") == 0) {
struct fstab *fstabItem; /* Adjusts device to be the real root device,
* or leaves device alone if it can't find it */
fstabItem = getfsfile("/"); find_real_root_device_name( cur->device);
if (fstabItem != NULL) return ( cur->device);
return fstabItem->fs_spec;
} }
#endif #endif
return cur->device; return cur->device;

View File

@ -45,7 +45,6 @@
#include <mntent.h> #include <mntent.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <ctype.h> #include <ctype.h>
#include <fstab.h>
#if defined BB_FEATURE_USE_DEVPS_PATCH #if defined BB_FEATURE_USE_DEVPS_PATCH
#include <linux/devmtab.h> #include <linux/devmtab.h>
#endif #endif
@ -321,9 +320,6 @@ extern int mount_main(int argc, char **argv)
int useMtab = TRUE; int useMtab = TRUE;
int i; int i;
/* Only compiled in if BB_MTAB is not defined */
whine_if_fstab_is_missing();
#if defined BB_FEATURE_USE_DEVPS_PATCH #if defined BB_FEATURE_USE_DEVPS_PATCH
if (argc == 1) { if (argc == 1) {
int fd, i, numfilesystems; int fd, i, numfilesystems;
@ -364,14 +360,9 @@ extern int mount_main(int argc, char **argv)
struct mntent *m; struct mntent *m;
while ((m = getmntent(mountTable)) != 0) { while ((m = getmntent(mountTable)) != 0) {
struct fstab *fstabItem;
char *blockDevice = m->mnt_fsname; char *blockDevice = m->mnt_fsname;
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
if (strcmp(blockDevice, "/dev/root") == 0) { if (strcmp(blockDevice, "/dev/root") == 0) {
fstabItem = getfsfile("/"); find_real_root_device_name( blockDevice);
if (fstabItem != NULL)
blockDevice = fstabItem->fs_spec;
} }
printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir,
m->mnt_type, m->mnt_opts); m->mnt_type, m->mnt_opts);
@ -445,7 +436,7 @@ extern int mount_main(int argc, char **argv)
FILE *f = setmntent("/etc/fstab", "r"); FILE *f = setmntent("/etc/fstab", "r");
if (f == NULL) if (f == NULL)
fatalError( "\nCannot ream /etc/fstab: %s\n", strerror (errno)); fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno));
while ((m = getmntent(f)) != NULL) { while ((m = getmntent(f)) != NULL) {
// If the file system isn't noauto, // If the file system isn't noauto,

View File

@ -26,7 +26,6 @@
#include <stdio.h> #include <stdio.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <mntent.h> #include <mntent.h>
#include <fstab.h>
#include <errno.h> #include <errno.h>
@ -110,11 +109,10 @@ char *mtab_getinfo(const char *match, const char which)
} else { } else {
#if !defined BB_MTAB #if !defined BB_MTAB
if (strcmp(cur->device, "/dev/root") == 0) { if (strcmp(cur->device, "/dev/root") == 0) {
struct fstab *fstabItem; /* Adjusts device to be the real root device,
* or leaves device alone if it can't find it */
fstabItem = getfsfile("/"); find_real_root_device_name( cur->device);
if (fstabItem != NULL) return ( cur->device);
return fstabItem->fs_spec;
} }
#endif #endif
return cur->device; return cur->device;

View File

@ -1469,25 +1469,29 @@ extern char *find_unused_loop_device(void)
} }
#endif /* BB_FEATURE_MOUNT_LOOP */ #endif /* BB_FEATURE_MOUNT_LOOP */
#if defined BB_MOUNT #if defined BB_MOUNT || defined BB_DF
char* find_real_root_device_name(void) extern int find_real_root_device_name(char* name)
{ {
int gotIt=0;
DIR *dir; DIR *dir;
struct dirent *entry; struct dirent *entry;
struct stat statBuf, rootStat; struct stat statBuf, rootStat;
char fileName[BUFSIZ]; char fileName[BUFSIZ];
if (stat("/", &rootStat) != 0) if (stat("/", &rootStat) != 0) {
fatalError("Wierd. I could not stat '/'\n"); errorMsg("could not stat '/'\n");
return( FALSE);
}
if (!(dir = opendir("/dev")); dir = opendir("/dev");
fatalError("Wierd. I could not open '/dev'\n"); if (!dir) {
errorMsg("could not open '/dev'\n");
return( FALSE);
}
while((entry = readdir(dir)) != NULL) { while((entry = readdir(dir)) != NULL) {
/* Must skip ".." since that is "/", and so we /* Must skip ".." since that is "/", and so we
* would get a false positive on ".." */ * would get a false positive on ".." */
if (strcmp(entry->d_name, "..") == 0) if (strcmp(entry->d_name, "..") == 0)
continue; continue;
@ -1495,12 +1499,17 @@ char* find_real_root_device_name(void)
if (stat(fileName, &statBuf) != 0) if (stat(fileName, &statBuf) != 0)
continue; 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) { if (statBuf.st_rdev == rootStat.st_rdev) {
return (strdup(fileName)); strcpy(name, fileName);
return ( TRUE);
} }
} }
return( NULL); return( FALSE);
} }
#endif #endif