diff options
| author | Eric Andersen <andersen@codepoet.org> | 1999-11-06 06:07:27 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 1999-11-06 06:07:27 +0000 |
| commit | 29d2e362dedf42d60ffebf6756144fb5449e753a (patch) | |
| tree | 57ba26bdcf5dae8deb91a3d1a9b47bcc140689a0 | |
| parent | bc3419069494fac078b316ce3a2f6a232c763c3e (diff) | |
| download | busybox-w32-29d2e362dedf42d60ffebf6756144fb5449e753a.tar.gz busybox-w32-29d2e362dedf42d60ffebf6756144fb5449e753a.tar.bz2 busybox-w32-29d2e362dedf42d60ffebf6756144fb5449e753a.zip | |
Fixed ln, df, and removed redundant stuff from mtab.
| -rw-r--r-- | Changelog | 7 | ||||
| -rw-r--r-- | coreutils/df.c | 54 | ||||
| -rw-r--r-- | coreutils/ln.c | 33 | ||||
| -rw-r--r-- | df.c | 54 | ||||
| -rw-r--r-- | internal.h | 10 | ||||
| -rw-r--r-- | ln.c | 33 | ||||
| -rw-r--r-- | mount.c | 5 | ||||
| -rw-r--r-- | mtab.c | 42 | ||||
| -rw-r--r-- | util-linux/mount.c | 5 | ||||
| -rw-r--r-- | utility.c | 59 |
10 files changed, 127 insertions, 175 deletions
| @@ -1,5 +1,12 @@ | |||
| 1 | 0.33 | 1 | 0.33 |
| 2 | * Fixed a bug where init could hang instead of rebooting. | 2 | * Fixed a bug where init could hang instead of rebooting. |
| 3 | * Removed some debugging noise from init.c | ||
| 4 | * Fixed ln so it works now (it was very broken). | ||
| 5 | * Fixed df so it won't segfault when there is no /etc/fstab, | ||
| 6 | * If BB_MTAB is not defined, df and mount will whine if /etc/fstab | ||
| 7 | is not installed (since they cannot fixup "/dev/root" to | ||
| 8 | state the real root device name) | ||
| 9 | * merged some redundant code from mtab.c/df.c into utility.c | ||
| 3 | 10 | ||
| 4 | 0.32 | 11 | 0.32 |
| 5 | * More changes -- many thanks to Lineo for paying me to work on | 12 | * More changes -- many thanks to Lineo for paying me to work on |
diff --git a/coreutils/df.c b/coreutils/df.c index 94b6b8231..a84a330d8 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
| @@ -38,6 +38,7 @@ static int df(char *device, const char *mountPoint) | |||
| 38 | struct statfs s; | 38 | struct statfs s; |
| 39 | long blocks_used; | 39 | long blocks_used; |
| 40 | long blocks_percent_used; | 40 | long blocks_percent_used; |
| 41 | struct fstab* fstabItem; | ||
| 41 | 42 | ||
| 42 | if (statfs(mountPoint, &s) != 0) { | 43 | if (statfs(mountPoint, &s) != 0) { |
| 43 | perror(mountPoint); | 44 | perror(mountPoint); |
| @@ -48,9 +49,12 @@ static int df(char *device, const char *mountPoint) | |||
| 48 | blocks_used = s.f_blocks - s.f_bfree; | 49 | blocks_used = s.f_blocks - s.f_bfree; |
| 49 | blocks_percent_used = (long) | 50 | blocks_percent_used = (long) |
| 50 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); | 51 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); |
| 51 | if (strcmp(device, "/dev/root") == 0) | 52 | /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ |
| 52 | device = (getfsfile("/"))->fs_spec; | 53 | if (strcmp (device, "/dev/root") == 0) { |
| 53 | 54 | fstabItem = getfsfile ("/"); | |
| 55 | if (fstabItem != NULL) | ||
| 56 | device = fstabItem->fs_spec; | ||
| 57 | } | ||
| 54 | printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", | 58 | printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", |
| 55 | device, | 59 | device, |
| 56 | (long) (s.f_blocks * (s.f_bsize / 1024.0)), | 60 | (long) (s.f_blocks * (s.f_bsize / 1024.0)), |
| @@ -63,52 +67,14 @@ static int df(char *device, const char *mountPoint) | |||
| 63 | return 0; | 67 | return 0; |
| 64 | } | 68 | } |
| 65 | 69 | ||
| 66 | /* | ||
| 67 | * Given a block device, find the mount table entry if that block device | ||
| 68 | * is mounted. | ||
| 69 | * | ||
| 70 | * Given any other file (or directory), find the mount table entry for its | ||
| 71 | * filesystem. | ||
| 72 | */ | ||
| 73 | extern struct mntent *findMountPoint(const char *name, const char *table) | ||
| 74 | { | ||
| 75 | struct stat s; | ||
| 76 | dev_t mountDevice; | ||
| 77 | FILE *mountTable; | ||
| 78 | struct mntent *mountEntry; | ||
| 79 | |||
| 80 | if (stat(name, &s) != 0) | ||
| 81 | return 0; | ||
| 82 | |||
| 83 | if ((s.st_mode & S_IFMT) == S_IFBLK) | ||
| 84 | mountDevice = s.st_rdev; | ||
| 85 | else | ||
| 86 | mountDevice = s.st_dev; | ||
| 87 | |||
| 88 | |||
| 89 | if ((mountTable = setmntent(table, "r")) == 0) | ||
| 90 | return 0; | ||
| 91 | |||
| 92 | while ((mountEntry = getmntent(mountTable)) != 0) { | ||
| 93 | if (strcmp(name, mountEntry->mnt_dir) == 0 | ||
| 94 | || strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */ | ||
| 95 | break; | ||
| 96 | if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */ | ||
| 97 | break; | ||
| 98 | if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */ | ||
| 99 | break; | ||
| 100 | } | ||
| 101 | endmntent(mountTable); | ||
| 102 | return mountEntry; | ||
| 103 | } | ||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | extern int df_main(int argc, char **argv) | 70 | extern int df_main(int argc, char **argv) |
| 108 | { | 71 | { |
| 109 | printf("%-20s %-14s %s %s %s %s\n", "Filesystem", | 72 | printf("%-20s %-14s %s %s %s %s\n", "Filesystem", |
| 110 | "1k-blocks", "Used", "Available", "Use%", "Mounted on"); | 73 | "1k-blocks", "Used", "Available", "Use%", "Mounted on"); |
| 111 | 74 | ||
| 75 | /* Only compiled in if BB_MTAB is not defined */ | ||
| 76 | whine_if_fstab_is_missing(); | ||
| 77 | |||
| 112 | if (argc > 1) { | 78 | if (argc > 1) { |
| 113 | struct mntent *mountEntry; | 79 | struct mntent *mountEntry; |
| 114 | int status; | 80 | int status; |
diff --git a/coreutils/ln.c b/coreutils/ln.c index 1e30e2b29..62496fba0 100644 --- a/coreutils/ln.c +++ b/coreutils/ln.c | |||
| @@ -27,23 +27,21 @@ | |||
| 27 | #include <errno.h> | 27 | #include <errno.h> |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | static const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n" | 30 | static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n" |
| 31 | "\n" | 31 | "Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n" |
| 32 | "\tAdd a new name that refers to the same file as \"original-name\"\n" | 32 | "\nOptions:\n" |
| 33 | "\n" | 33 | "\t-s\tmake symbolic links instead of hard links\n" |
| 34 | "\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n" | 34 | "\t-f\tremove existing destination files\n"; |
| 35 | "\t-f:\tRemove existing destination files.\n"; | ||
| 36 | 35 | ||
| 37 | 36 | ||
| 38 | static int symlinkFlag = FALSE; | 37 | static int symlinkFlag = FALSE; |
| 39 | static int removeoldFlag = FALSE; | 38 | static int removeoldFlag = FALSE; |
| 40 | static const char *destName; | ||
| 41 | 39 | ||
| 42 | 40 | ||
| 43 | extern int ln_main(int argc, char **argv) | 41 | extern int ln_main(int argc, char **argv) |
| 44 | { | 42 | { |
| 45 | int status; | 43 | int status; |
| 46 | char newdestName[NAME_MAX]; | 44 | static char* linkName; |
| 47 | 45 | ||
| 48 | if (argc < 3) { | 46 | if (argc < 3) { |
| 49 | usage (ln_usage); | 47 | usage (ln_usage); |
| @@ -69,30 +67,27 @@ extern int ln_main(int argc, char **argv) | |||
| 69 | } | 67 | } |
| 70 | 68 | ||
| 71 | 69 | ||
| 72 | destName = argv[argc - 1]; | 70 | linkName = argv[argc - 1]; |
| 73 | 71 | ||
| 74 | if ((argc > 3) && !(isDirectory(destName))) { | 72 | if ((argc > 3) && !(isDirectory(linkName))) { |
| 75 | fprintf(stderr, "%s: not a directory\n", destName); | 73 | fprintf(stderr, "%s: not a directory\n", linkName); |
| 76 | exit (FALSE); | 74 | exit (FALSE); |
| 77 | } | 75 | } |
| 78 | 76 | ||
| 79 | while (argc-- >= 2) { | 77 | while (argc-- >= 2) { |
| 80 | strcpy(newdestName, destName); | ||
| 81 | strcat(newdestName, (*argv)+(strlen(*(++argv)))); | ||
| 82 | |||
| 83 | if (removeoldFlag==TRUE ) { | 78 | if (removeoldFlag==TRUE ) { |
| 84 | status = ( unlink(newdestName) && errno != ENOENT ); | 79 | status = ( unlink(linkName) && errno != ENOENT ); |
| 85 | if ( status != 0 ) { | 80 | if ( status != 0 ) { |
| 86 | perror(newdestName); | 81 | perror(linkName); |
| 87 | exit( FALSE); | 82 | exit( FALSE); |
| 88 | } | 83 | } |
| 89 | } | 84 | } |
| 90 | if ( symlinkFlag==TRUE) | 85 | if ( symlinkFlag==TRUE) |
| 91 | status = symlink(*argv, newdestName); | 86 | status = symlink(*argv, linkName); |
| 92 | else | 87 | else |
| 93 | status = link(*argv, newdestName); | 88 | status = link(*argv, linkName); |
| 94 | if ( status != 0 ) { | 89 | if ( status != 0 ) { |
| 95 | perror(newdestName); | 90 | perror(linkName); |
| 96 | exit( FALSE); | 91 | exit( FALSE); |
| 97 | } | 92 | } |
| 98 | } | 93 | } |
| @@ -38,6 +38,7 @@ static int df(char *device, const char *mountPoint) | |||
| 38 | struct statfs s; | 38 | struct statfs s; |
| 39 | long blocks_used; | 39 | long blocks_used; |
| 40 | long blocks_percent_used; | 40 | long blocks_percent_used; |
| 41 | struct fstab* fstabItem; | ||
| 41 | 42 | ||
| 42 | if (statfs(mountPoint, &s) != 0) { | 43 | if (statfs(mountPoint, &s) != 0) { |
| 43 | perror(mountPoint); | 44 | perror(mountPoint); |
| @@ -48,9 +49,12 @@ static int df(char *device, const char *mountPoint) | |||
| 48 | blocks_used = s.f_blocks - s.f_bfree; | 49 | blocks_used = s.f_blocks - s.f_bfree; |
| 49 | blocks_percent_used = (long) | 50 | blocks_percent_used = (long) |
| 50 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); | 51 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); |
| 51 | if (strcmp(device, "/dev/root") == 0) | 52 | /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ |
| 52 | device = (getfsfile("/"))->fs_spec; | 53 | if (strcmp (device, "/dev/root") == 0) { |
| 53 | 54 | fstabItem = getfsfile ("/"); | |
| 55 | if (fstabItem != NULL) | ||
| 56 | device = fstabItem->fs_spec; | ||
| 57 | } | ||
| 54 | printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", | 58 | printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", |
| 55 | device, | 59 | device, |
| 56 | (long) (s.f_blocks * (s.f_bsize / 1024.0)), | 60 | (long) (s.f_blocks * (s.f_bsize / 1024.0)), |
| @@ -63,52 +67,14 @@ static int df(char *device, const char *mountPoint) | |||
| 63 | return 0; | 67 | return 0; |
| 64 | } | 68 | } |
| 65 | 69 | ||
| 66 | /* | ||
| 67 | * Given a block device, find the mount table entry if that block device | ||
| 68 | * is mounted. | ||
| 69 | * | ||
| 70 | * Given any other file (or directory), find the mount table entry for its | ||
| 71 | * filesystem. | ||
| 72 | */ | ||
| 73 | extern struct mntent *findMountPoint(const char *name, const char *table) | ||
| 74 | { | ||
| 75 | struct stat s; | ||
| 76 | dev_t mountDevice; | ||
| 77 | FILE *mountTable; | ||
| 78 | struct mntent *mountEntry; | ||
| 79 | |||
| 80 | if (stat(name, &s) != 0) | ||
| 81 | return 0; | ||
| 82 | |||
| 83 | if ((s.st_mode & S_IFMT) == S_IFBLK) | ||
| 84 | mountDevice = s.st_rdev; | ||
| 85 | else | ||
| 86 | mountDevice = s.st_dev; | ||
| 87 | |||
| 88 | |||
| 89 | if ((mountTable = setmntent(table, "r")) == 0) | ||
| 90 | return 0; | ||
| 91 | |||
| 92 | while ((mountEntry = getmntent(mountTable)) != 0) { | ||
| 93 | if (strcmp(name, mountEntry->mnt_dir) == 0 | ||
| 94 | || strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */ | ||
| 95 | break; | ||
| 96 | if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */ | ||
| 97 | break; | ||
| 98 | if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */ | ||
| 99 | break; | ||
| 100 | } | ||
| 101 | endmntent(mountTable); | ||
| 102 | return mountEntry; | ||
| 103 | } | ||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | extern int df_main(int argc, char **argv) | 70 | extern int df_main(int argc, char **argv) |
| 108 | { | 71 | { |
| 109 | printf("%-20s %-14s %s %s %s %s\n", "Filesystem", | 72 | printf("%-20s %-14s %s %s %s %s\n", "Filesystem", |
| 110 | "1k-blocks", "Used", "Available", "Use%", "Mounted on"); | 73 | "1k-blocks", "Used", "Available", "Use%", "Mounted on"); |
| 111 | 74 | ||
| 75 | /* Only compiled in if BB_MTAB is not defined */ | ||
| 76 | whine_if_fstab_is_missing(); | ||
| 77 | |||
| 112 | if (argc > 1) { | 78 | if (argc > 1) { |
| 113 | struct mntent *mountEntry; | 79 | struct mntent *mountEntry; |
| 114 | int status; | 80 | int status; |
diff --git a/internal.h b/internal.h index c66c9f116..8d111a6c9 100644 --- a/internal.h +++ b/internal.h | |||
| @@ -29,6 +29,7 @@ | |||
| 29 | #include <string.h> | 29 | #include <string.h> |
| 30 | #include <unistd.h> | 30 | #include <unistd.h> |
| 31 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
| 32 | #include <mntent.h> | ||
| 32 | 33 | ||
| 33 | 34 | ||
| 34 | /* Some useful definitions */ | 35 | /* Some useful definitions */ |
| @@ -145,12 +146,19 @@ extern void my_getpwuid(char* name, uid_t uid); | |||
| 145 | extern void my_getgrgid(char* group, gid_t gid); | 146 | extern void my_getgrgid(char* group, gid_t gid); |
| 146 | extern int get_kernel_revision(); | 147 | extern int get_kernel_revision(); |
| 147 | extern int get_console_fd(char* tty_name); | 148 | extern int get_console_fd(char* tty_name); |
| 148 | 149 | extern struct mntent *findMountPoint(const char *name, const char *table); | |
| 149 | extern void write_mtab(char* blockDevice, char* directory, | 150 | extern void write_mtab(char* blockDevice, char* directory, |
| 150 | char* filesystemType, long flags, char* string_flags); | 151 | char* filesystemType, long flags, char* string_flags); |
| 151 | extern void erase_mtab(const char * name); | 152 | extern void erase_mtab(const char * name); |
| 152 | 153 | ||
| 153 | 154 | ||
| 155 | #if defined BB_MTAB | ||
| 156 | #define whine_if_fstab_is_missing() {} | ||
| 157 | #else | ||
| 158 | extern void whine_if_fstab_is_missing(); | ||
| 159 | #endif | ||
| 160 | |||
| 161 | |||
| 154 | #if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX) | 162 | #if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX) |
| 155 | 163 | ||
| 156 | static inline int bit(char * addr,unsigned int nr) | 164 | static inline int bit(char * addr,unsigned int nr) |
| @@ -27,23 +27,21 @@ | |||
| 27 | #include <errno.h> | 27 | #include <errno.h> |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | static const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n" | 30 | static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n" |
| 31 | "\n" | 31 | "Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n" |
| 32 | "\tAdd a new name that refers to the same file as \"original-name\"\n" | 32 | "\nOptions:\n" |
| 33 | "\n" | 33 | "\t-s\tmake symbolic links instead of hard links\n" |
| 34 | "\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n" | 34 | "\t-f\tremove existing destination files\n"; |
| 35 | "\t-f:\tRemove existing destination files.\n"; | ||
| 36 | 35 | ||
| 37 | 36 | ||
| 38 | static int symlinkFlag = FALSE; | 37 | static int symlinkFlag = FALSE; |
| 39 | static int removeoldFlag = FALSE; | 38 | static int removeoldFlag = FALSE; |
| 40 | static const char *destName; | ||
| 41 | 39 | ||
| 42 | 40 | ||
| 43 | extern int ln_main(int argc, char **argv) | 41 | extern int ln_main(int argc, char **argv) |
| 44 | { | 42 | { |
| 45 | int status; | 43 | int status; |
| 46 | char newdestName[NAME_MAX]; | 44 | static char* linkName; |
| 47 | 45 | ||
| 48 | if (argc < 3) { | 46 | if (argc < 3) { |
| 49 | usage (ln_usage); | 47 | usage (ln_usage); |
| @@ -69,30 +67,27 @@ extern int ln_main(int argc, char **argv) | |||
| 69 | } | 67 | } |
| 70 | 68 | ||
| 71 | 69 | ||
| 72 | destName = argv[argc - 1]; | 70 | linkName = argv[argc - 1]; |
| 73 | 71 | ||
| 74 | if ((argc > 3) && !(isDirectory(destName))) { | 72 | if ((argc > 3) && !(isDirectory(linkName))) { |
| 75 | fprintf(stderr, "%s: not a directory\n", destName); | 73 | fprintf(stderr, "%s: not a directory\n", linkName); |
| 76 | exit (FALSE); | 74 | exit (FALSE); |
| 77 | } | 75 | } |
| 78 | 76 | ||
| 79 | while (argc-- >= 2) { | 77 | while (argc-- >= 2) { |
| 80 | strcpy(newdestName, destName); | ||
| 81 | strcat(newdestName, (*argv)+(strlen(*(++argv)))); | ||
| 82 | |||
| 83 | if (removeoldFlag==TRUE ) { | 78 | if (removeoldFlag==TRUE ) { |
| 84 | status = ( unlink(newdestName) && errno != ENOENT ); | 79 | status = ( unlink(linkName) && errno != ENOENT ); |
| 85 | if ( status != 0 ) { | 80 | if ( status != 0 ) { |
| 86 | perror(newdestName); | 81 | perror(linkName); |
| 87 | exit( FALSE); | 82 | exit( FALSE); |
| 88 | } | 83 | } |
| 89 | } | 84 | } |
| 90 | if ( symlinkFlag==TRUE) | 85 | if ( symlinkFlag==TRUE) |
| 91 | status = symlink(*argv, newdestName); | 86 | status = symlink(*argv, linkName); |
| 92 | else | 87 | else |
| 93 | status = link(*argv, newdestName); | 88 | status = link(*argv, linkName); |
| 94 | if ( status != 0 ) { | 89 | if ( status != 0 ) { |
| 95 | perror(newdestName); | 90 | perror(linkName); |
| 96 | exit( FALSE); | 91 | exit( FALSE); |
| 97 | } | 92 | } |
| 98 | } | 93 | } |
| @@ -208,14 +208,13 @@ extern int mount_main (int argc, char **argv) | |||
| 208 | char *filesystemType = "auto"; | 208 | char *filesystemType = "auto"; |
| 209 | char *device = NULL; | 209 | char *device = NULL; |
| 210 | char *directory = NULL; | 210 | char *directory = NULL; |
| 211 | struct stat statBuf; | ||
| 212 | int all = FALSE; | 211 | int all = FALSE; |
| 213 | int fakeIt = FALSE; | 212 | int fakeIt = FALSE; |
| 214 | int useMtab = TRUE; | 213 | int useMtab = TRUE; |
| 215 | int i; | 214 | int i; |
| 216 | 215 | ||
| 217 | if (stat("/etc/fstab", &statBuf) < 0) | 216 | /* Only compiled in if BB_MTAB is not defined */ |
| 218 | fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n"); | 217 | whine_if_fstab_is_missing(); |
| 219 | 218 | ||
| 220 | if (argc == 1) { | 219 | if (argc == 1) { |
| 221 | FILE *mountTable = setmntent (mtab_file, "r"); | 220 | FILE *mountTable = setmntent (mtab_file, "r"); |
| @@ -59,48 +59,6 @@ erase_mtab(const char * name) | |||
| 59 | perror(mtab_file); | 59 | perror(mtab_file); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | /* | ||
| 63 | * Given a block device, find the mount table entry if that block device | ||
| 64 | * is mounted. | ||
| 65 | * | ||
| 66 | * Given any other file (or directory), find the mount table entry for its | ||
| 67 | * filesystem. | ||
| 68 | */ | ||
| 69 | static struct mntent * | ||
| 70 | findMountPoint(const char * name, const char * table) | ||
| 71 | { | ||
| 72 | struct stat s; | ||
| 73 | dev_t mountDevice; | ||
| 74 | FILE* mountTable; | ||
| 75 | struct mntent* mountEntry; | ||
| 76 | |||
| 77 | if ( stat(name, &s) != 0 ) | ||
| 78 | return 0; | ||
| 79 | |||
| 80 | if ( (s.st_mode & S_IFMT) == S_IFBLK ) | ||
| 81 | mountDevice = s.st_rdev; | ||
| 82 | else | ||
| 83 | mountDevice = s.st_dev; | ||
| 84 | |||
| 85 | |||
| 86 | if ( (mountTable = setmntent(table, "r")) == 0 ) | ||
| 87 | return 0; | ||
| 88 | |||
| 89 | while ( (mountEntry = getmntent(mountTable)) != 0 ) { | ||
| 90 | if ( strcmp(name, mountEntry->mnt_dir) == 0 || | ||
| 91 | strcmp(name, mountEntry->mnt_fsname) == 0 ) /* String match. */ | ||
| 92 | break; | ||
| 93 | if ( stat(mountEntry->mnt_fsname, &s) == 0 && | ||
| 94 | s.st_rdev == mountDevice ) /* Match the device. */ | ||
| 95 | break; | ||
| 96 | if ( stat(mountEntry->mnt_dir, &s) == 0 && | ||
| 97 | s.st_dev == mountDevice ) /* Match the directory's mount point. */ | ||
| 98 | break; | ||
| 99 | } | ||
| 100 | endmntent(mountTable); | ||
| 101 | return mountEntry; | ||
| 102 | } | ||
| 103 | |||
| 104 | extern void | 62 | extern void |
| 105 | write_mtab(char* blockDevice, char* directory, | 63 | write_mtab(char* blockDevice, char* directory, |
| 106 | char* filesystemType, long flags, char* string_flags) | 64 | char* filesystemType, long flags, char* string_flags) |
diff --git a/util-linux/mount.c b/util-linux/mount.c index 8b5efe14f..4c085d01b 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
| @@ -208,14 +208,13 @@ extern int mount_main (int argc, char **argv) | |||
| 208 | char *filesystemType = "auto"; | 208 | char *filesystemType = "auto"; |
| 209 | char *device = NULL; | 209 | char *device = NULL; |
| 210 | char *directory = NULL; | 210 | char *directory = NULL; |
| 211 | struct stat statBuf; | ||
| 212 | int all = FALSE; | 211 | int all = FALSE; |
| 213 | int fakeIt = FALSE; | 212 | int fakeIt = FALSE; |
| 214 | int useMtab = TRUE; | 213 | int useMtab = TRUE; |
| 215 | int i; | 214 | int i; |
| 216 | 215 | ||
| 217 | if (stat("/etc/fstab", &statBuf) < 0) | 216 | /* Only compiled in if BB_MTAB is not defined */ |
| 218 | fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n"); | 217 | whine_if_fstab_is_missing(); |
| 219 | 218 | ||
| 220 | if (argc == 1) { | 219 | if (argc == 1) { |
| 221 | FILE *mountTable = setmntent (mtab_file, "r"); | 220 | FILE *mountTable = setmntent (mtab_file, "r"); |
| @@ -868,5 +868,64 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, int igno | |||
| 868 | 868 | ||
| 869 | 869 | ||
| 870 | #endif | 870 | #endif |
| 871 | |||
| 872 | |||
| 873 | |||
| 874 | |||
| 875 | #if defined BB_DF | defined BB_MTAB | ||
| 876 | /* | ||
| 877 | * Given a block device, find the mount table entry if that block device | ||
| 878 | * is mounted. | ||
| 879 | * | ||
| 880 | * Given any other file (or directory), find the mount table entry for its | ||
| 881 | * filesystem. | ||
| 882 | */ | ||
| 883 | extern struct mntent *findMountPoint(const char *name, const char *table) | ||
| 884 | { | ||
| 885 | struct stat s; | ||
| 886 | dev_t mountDevice; | ||
| 887 | FILE *mountTable; | ||
| 888 | struct mntent *mountEntry; | ||
| 889 | |||
| 890 | if (stat(name, &s) != 0) | ||
| 891 | return 0; | ||
| 892 | |||
| 893 | if ((s.st_mode & S_IFMT) == S_IFBLK) | ||
| 894 | mountDevice = s.st_rdev; | ||
| 895 | else | ||
| 896 | mountDevice = s.st_dev; | ||
| 897 | |||
| 898 | |||
| 899 | if ((mountTable = setmntent(table, "r")) == 0) | ||
| 900 | return 0; | ||
| 901 | |||
| 902 | while ((mountEntry = getmntent(mountTable)) != 0) { | ||
| 903 | if (strcmp(name, mountEntry->mnt_dir) == 0 | ||
| 904 | || strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */ | ||
| 905 | break; | ||
| 906 | if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */ | ||
| 907 | break; | ||
| 908 | if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */ | ||
| 909 | break; | ||
| 910 | } | ||
| 911 | endmntent(mountTable); | ||
| 912 | return mountEntry; | ||
| 913 | } | ||
| 914 | |||
| 915 | #endif | ||
| 916 | |||
| 917 | |||
| 918 | |||
| 919 | #if !defined BB_MTAB && (defined BB_MOUNT || defined BB_DF ) | ||
| 920 | extern void whine_if_fstab_is_missing() | ||
| 921 | { | ||
| 922 | struct stat statBuf; | ||
| 923 | if (stat("/etc/fstab", &statBuf) < 0) | ||
| 924 | fprintf(stderr, "/etc/fstab file missing -- install one to name /dev/root.\n\n"); | ||
| 925 | } | ||
| 926 | #endif | ||
| 927 | |||
| 928 | |||
| 871 | /* END CODE */ | 929 | /* END CODE */ |
| 872 | 930 | ||
| 931 | |||
