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 /coreutils | |
| 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.
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/df.c | 54 | ||||
| -rw-r--r-- | coreutils/ln.c | 33 |
2 files changed, 24 insertions, 63 deletions
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 | } |
