diff options
-rw-r--r-- | coreutils/df.c | 8 | ||||
-rw-r--r-- | df.c | 8 | ||||
-rw-r--r-- | internal.h | 2 | ||||
-rw-r--r-- | mount.c | 13 | ||||
-rw-r--r-- | umount.c | 10 | ||||
-rw-r--r-- | util-linux/mount.c | 13 | ||||
-rw-r--r-- | util-linux/umount.c | 10 | ||||
-rw-r--r-- | utility.c | 29 |
8 files changed, 39 insertions, 54 deletions
diff --git a/coreutils/df.c b/coreutils/df.c index bc843f7a2..331ef2d49 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include <mntent.h> | 27 | #include <mntent.h> |
28 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
29 | #include <sys/vfs.h> | 29 | #include <sys/vfs.h> |
30 | #include <fstab.h> | ||
31 | 30 | ||
32 | static const char df_usage[] = "df [filesystem ...]\n" | 31 | static const char df_usage[] = "df [filesystem ...]\n" |
33 | 32 | ||
@@ -40,7 +39,6 @@ static int df(char *device, const char *mountPoint) | |||
40 | struct statfs s; | 39 | struct statfs s; |
41 | long blocks_used; | 40 | long blocks_used; |
42 | long blocks_percent_used; | 41 | long blocks_percent_used; |
43 | struct fstab *fstabItem; | ||
44 | 42 | ||
45 | if (statfs(mountPoint, &s) != 0) { | 43 | if (statfs(mountPoint, &s) != 0) { |
46 | perror(mountPoint); | 44 | perror(mountPoint); |
@@ -53,9 +51,9 @@ static int df(char *device, const char *mountPoint) | |||
53 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); | 51 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); |
54 | /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ | 52 | /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ |
55 | if (strcmp(device, "/dev/root") == 0) { | 53 | if (strcmp(device, "/dev/root") == 0) { |
56 | fstabItem = getfsfile("/"); | 54 | /* Adjusts device to be the real root device, |
57 | if (fstabItem != NULL) | 55 | * or leaves device alone if it can't find it */ |
58 | device = fstabItem->fs_spec; | 56 | find_real_root_device_name( device); |
59 | } | 57 | } |
60 | printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", | 58 | printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", |
61 | device, | 59 | device, |
@@ -27,7 +27,6 @@ | |||
27 | #include <mntent.h> | 27 | #include <mntent.h> |
28 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
29 | #include <sys/vfs.h> | 29 | #include <sys/vfs.h> |
30 | #include <fstab.h> | ||
31 | 30 | ||
32 | static const char df_usage[] = "df [filesystem ...]\n" | 31 | static const char df_usage[] = "df [filesystem ...]\n" |
33 | 32 | ||
@@ -40,7 +39,6 @@ static int df(char *device, const char *mountPoint) | |||
40 | struct statfs s; | 39 | struct statfs s; |
41 | long blocks_used; | 40 | long blocks_used; |
42 | long blocks_percent_used; | 41 | long blocks_percent_used; |
43 | struct fstab *fstabItem; | ||
44 | 42 | ||
45 | if (statfs(mountPoint, &s) != 0) { | 43 | if (statfs(mountPoint, &s) != 0) { |
46 | perror(mountPoint); | 44 | perror(mountPoint); |
@@ -53,9 +51,9 @@ static int df(char *device, const char *mountPoint) | |||
53 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); | 51 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); |
54 | /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ | 52 | /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ |
55 | if (strcmp(device, "/dev/root") == 0) { | 53 | if (strcmp(device, "/dev/root") == 0) { |
56 | fstabItem = getfsfile("/"); | 54 | /* Adjusts device to be the real root device, |
57 | if (fstabItem != NULL) | 55 | * or leaves device alone if it can't find it */ |
58 | device = fstabItem->fs_spec; | 56 | find_real_root_device_name( device); |
59 | } | 57 | } |
60 | printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", | 58 | printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", |
61 | device, | 59 | device, |
diff --git a/internal.h b/internal.h index 353ec8ca3..9f9461def 100644 --- a/internal.h +++ b/internal.h | |||
@@ -216,6 +216,8 @@ extern int check_wildcard_match(const char* text, const char* pattern); | |||
216 | extern long getNum (const char *cp); | 216 | extern long getNum (const char *cp); |
217 | extern pid_t findPidByName( char* pidName); | 217 | extern pid_t findPidByName( char* pidName); |
218 | extern void *xmalloc (size_t size); | 218 | extern void *xmalloc (size_t size); |
219 | extern int find_real_root_device_name(char* name); | ||
220 | |||
219 | #ifdef BB_FEATURE_SH_COMMAND_EDITING | 221 | #ifdef BB_FEATURE_SH_COMMAND_EDITING |
220 | #include <stdio.h> | 222 | #include <stdio.h> |
221 | extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd, char command[BUFSIZ]); | 223 | extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd, char command[BUFSIZ]); |
@@ -45,7 +45,6 @@ | |||
45 | #include <mntent.h> | 45 | #include <mntent.h> |
46 | #include <sys/mount.h> | 46 | #include <sys/mount.h> |
47 | #include <ctype.h> | 47 | #include <ctype.h> |
48 | #include <fstab.h> | ||
49 | #if defined BB_FEATURE_USE_DEVPS_PATCH | 48 | #if defined BB_FEATURE_USE_DEVPS_PATCH |
50 | #include <linux/devmtab.h> | 49 | #include <linux/devmtab.h> |
51 | #endif | 50 | #endif |
@@ -321,9 +320,6 @@ extern int mount_main(int argc, char **argv) | |||
321 | int useMtab = TRUE; | 320 | int useMtab = TRUE; |
322 | int i; | 321 | int i; |
323 | 322 | ||
324 | /* Only compiled in if BB_MTAB is not defined */ | ||
325 | whine_if_fstab_is_missing(); | ||
326 | |||
327 | #if defined BB_FEATURE_USE_DEVPS_PATCH | 323 | #if defined BB_FEATURE_USE_DEVPS_PATCH |
328 | if (argc == 1) { | 324 | if (argc == 1) { |
329 | int fd, i, numfilesystems; | 325 | int fd, i, numfilesystems; |
@@ -364,14 +360,9 @@ extern int mount_main(int argc, char **argv) | |||
364 | struct mntent *m; | 360 | struct mntent *m; |
365 | 361 | ||
366 | while ((m = getmntent(mountTable)) != 0) { | 362 | while ((m = getmntent(mountTable)) != 0) { |
367 | struct fstab *fstabItem; | ||
368 | char *blockDevice = m->mnt_fsname; | 363 | char *blockDevice = m->mnt_fsname; |
369 | |||
370 | /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ | ||
371 | if (strcmp(blockDevice, "/dev/root") == 0) { | 364 | if (strcmp(blockDevice, "/dev/root") == 0) { |
372 | fstabItem = getfsfile("/"); | 365 | find_real_root_device_name( blockDevice); |
373 | if (fstabItem != NULL) | ||
374 | blockDevice = fstabItem->fs_spec; | ||
375 | } | 366 | } |
376 | printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, | 367 | printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, |
377 | m->mnt_type, m->mnt_opts); | 368 | m->mnt_type, m->mnt_opts); |
@@ -445,7 +436,7 @@ extern int mount_main(int argc, char **argv) | |||
445 | FILE *f = setmntent("/etc/fstab", "r"); | 436 | FILE *f = setmntent("/etc/fstab", "r"); |
446 | 437 | ||
447 | if (f == NULL) | 438 | if (f == NULL) |
448 | fatalError( "\nCannot ream /etc/fstab: %s\n", strerror (errno)); | 439 | fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno)); |
449 | 440 | ||
450 | while ((m = getmntent(f)) != NULL) { | 441 | while ((m = getmntent(f)) != NULL) { |
451 | // If the file system isn't noauto, | 442 | // If the file system isn't noauto, |
@@ -26,7 +26,6 @@ | |||
26 | #include <stdio.h> | 26 | #include <stdio.h> |
27 | #include <sys/mount.h> | 27 | #include <sys/mount.h> |
28 | #include <mntent.h> | 28 | #include <mntent.h> |
29 | #include <fstab.h> | ||
30 | #include <errno.h> | 29 | #include <errno.h> |
31 | 30 | ||
32 | 31 | ||
@@ -110,11 +109,10 @@ char *mtab_getinfo(const char *match, const char which) | |||
110 | } else { | 109 | } else { |
111 | #if !defined BB_MTAB | 110 | #if !defined BB_MTAB |
112 | if (strcmp(cur->device, "/dev/root") == 0) { | 111 | if (strcmp(cur->device, "/dev/root") == 0) { |
113 | struct fstab *fstabItem; | 112 | /* Adjusts device to be the real root device, |
114 | 113 | * or leaves device alone if it can't find it */ | |
115 | fstabItem = getfsfile("/"); | 114 | find_real_root_device_name( cur->device); |
116 | if (fstabItem != NULL) | 115 | return ( cur->device); |
117 | return fstabItem->fs_spec; | ||
118 | } | 116 | } |
119 | #endif | 117 | #endif |
120 | return cur->device; | 118 | return cur->device; |
diff --git a/util-linux/mount.c b/util-linux/mount.c index 336cff7d2..03891371a 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -45,7 +45,6 @@ | |||
45 | #include <mntent.h> | 45 | #include <mntent.h> |
46 | #include <sys/mount.h> | 46 | #include <sys/mount.h> |
47 | #include <ctype.h> | 47 | #include <ctype.h> |
48 | #include <fstab.h> | ||
49 | #if defined BB_FEATURE_USE_DEVPS_PATCH | 48 | #if defined BB_FEATURE_USE_DEVPS_PATCH |
50 | #include <linux/devmtab.h> | 49 | #include <linux/devmtab.h> |
51 | #endif | 50 | #endif |
@@ -321,9 +320,6 @@ extern int mount_main(int argc, char **argv) | |||
321 | int useMtab = TRUE; | 320 | int useMtab = TRUE; |
322 | int i; | 321 | int i; |
323 | 322 | ||
324 | /* Only compiled in if BB_MTAB is not defined */ | ||
325 | whine_if_fstab_is_missing(); | ||
326 | |||
327 | #if defined BB_FEATURE_USE_DEVPS_PATCH | 323 | #if defined BB_FEATURE_USE_DEVPS_PATCH |
328 | if (argc == 1) { | 324 | if (argc == 1) { |
329 | int fd, i, numfilesystems; | 325 | int fd, i, numfilesystems; |
@@ -364,14 +360,9 @@ extern int mount_main(int argc, char **argv) | |||
364 | struct mntent *m; | 360 | struct mntent *m; |
365 | 361 | ||
366 | while ((m = getmntent(mountTable)) != 0) { | 362 | while ((m = getmntent(mountTable)) != 0) { |
367 | struct fstab *fstabItem; | ||
368 | char *blockDevice = m->mnt_fsname; | 363 | char *blockDevice = m->mnt_fsname; |
369 | |||
370 | /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ | ||
371 | if (strcmp(blockDevice, "/dev/root") == 0) { | 364 | if (strcmp(blockDevice, "/dev/root") == 0) { |
372 | fstabItem = getfsfile("/"); | 365 | find_real_root_device_name( blockDevice); |
373 | if (fstabItem != NULL) | ||
374 | blockDevice = fstabItem->fs_spec; | ||
375 | } | 366 | } |
376 | printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, | 367 | printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, |
377 | m->mnt_type, m->mnt_opts); | 368 | m->mnt_type, m->mnt_opts); |
@@ -445,7 +436,7 @@ extern int mount_main(int argc, char **argv) | |||
445 | FILE *f = setmntent("/etc/fstab", "r"); | 436 | FILE *f = setmntent("/etc/fstab", "r"); |
446 | 437 | ||
447 | if (f == NULL) | 438 | if (f == NULL) |
448 | fatalError( "\nCannot ream /etc/fstab: %s\n", strerror (errno)); | 439 | fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno)); |
449 | 440 | ||
450 | while ((m = getmntent(f)) != NULL) { | 441 | while ((m = getmntent(f)) != NULL) { |
451 | // If the file system isn't noauto, | 442 | // If the file system isn't noauto, |
diff --git a/util-linux/umount.c b/util-linux/umount.c index 6661db878..c34bf5fc3 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c | |||
@@ -26,7 +26,6 @@ | |||
26 | #include <stdio.h> | 26 | #include <stdio.h> |
27 | #include <sys/mount.h> | 27 | #include <sys/mount.h> |
28 | #include <mntent.h> | 28 | #include <mntent.h> |
29 | #include <fstab.h> | ||
30 | #include <errno.h> | 29 | #include <errno.h> |
31 | 30 | ||
32 | 31 | ||
@@ -110,11 +109,10 @@ char *mtab_getinfo(const char *match, const char which) | |||
110 | } else { | 109 | } else { |
111 | #if !defined BB_MTAB | 110 | #if !defined BB_MTAB |
112 | if (strcmp(cur->device, "/dev/root") == 0) { | 111 | if (strcmp(cur->device, "/dev/root") == 0) { |
113 | struct fstab *fstabItem; | 112 | /* Adjusts device to be the real root device, |
114 | 113 | * or leaves device alone if it can't find it */ | |
115 | fstabItem = getfsfile("/"); | 114 | find_real_root_device_name( cur->device); |
116 | if (fstabItem != NULL) | 115 | return ( cur->device); |
117 | return fstabItem->fs_spec; | ||
118 | } | 116 | } |
119 | #endif | 117 | #endif |
120 | return cur->device; | 118 | return cur->device; |
@@ -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 |
1473 | char* find_real_root_device_name(void) | 1473 | extern 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 | ||