summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorEric Andersen1999-11-06 06:07:27 +0000
committerEric Andersen1999-11-06 06:07:27 +0000
commit29d2e362dedf42d60ffebf6756144fb5449e753a (patch)
tree57ba26bdcf5dae8deb91a3d1a9b47bcc140689a0 /coreutils
parentbc3419069494fac078b316ce3a2f6a232c763c3e (diff)
downloadbusybox-29d2e362dedf42d60ffebf6756144fb5449e753a.zip
busybox-29d2e362dedf42d60ffebf6756144fb5449e753a.tar.gz
Fixed ln, df, and removed redundant stuff from mtab.
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/df.c54
-rw-r--r--coreutils/ln.c33
2 files changed, 24 insertions, 63 deletions
diff --git a/coreutils/df.c b/coreutils/df.c
index 94b6b82..a84a330 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -38,6 +38,7 @@ static int df(char *device, const char *mountPoint)
struct statfs s;
long blocks_used;
long blocks_percent_used;
+ struct fstab* fstabItem;
if (statfs(mountPoint, &s) != 0) {
perror(mountPoint);
@@ -48,9 +49,12 @@ static int df(char *device, const char *mountPoint)
blocks_used = s.f_blocks - s.f_bfree;
blocks_percent_used = (long)
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
- if (strcmp(device, "/dev/root") == 0)
- device = (getfsfile("/"))->fs_spec;
-
+ /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
+ if (strcmp (device, "/dev/root") == 0) {
+ fstabItem = getfsfile ("/");
+ if (fstabItem != NULL)
+ device = fstabItem->fs_spec;
+ }
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
device,
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
@@ -63,52 +67,14 @@ static int df(char *device, const char *mountPoint)
return 0;
}
-/*
- * Given a block device, find the mount table entry if that block device
- * is mounted.
- *
- * Given any other file (or directory), find the mount table entry for its
- * filesystem.
- */
-extern struct mntent *findMountPoint(const char *name, const char *table)
-{
- struct stat s;
- dev_t mountDevice;
- FILE *mountTable;
- struct mntent *mountEntry;
-
- if (stat(name, &s) != 0)
- return 0;
-
- if ((s.st_mode & S_IFMT) == S_IFBLK)
- mountDevice = s.st_rdev;
- else
- mountDevice = s.st_dev;
-
-
- if ((mountTable = setmntent(table, "r")) == 0)
- return 0;
-
- while ((mountEntry = getmntent(mountTable)) != 0) {
- if (strcmp(name, mountEntry->mnt_dir) == 0
- || strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */
- break;
- if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */
- break;
- if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */
- break;
- }
- endmntent(mountTable);
- return mountEntry;
-}
-
-
-
extern int df_main(int argc, char **argv)
{
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
+ /* Only compiled in if BB_MTAB is not defined */
+ whine_if_fstab_is_missing();
+
if (argc > 1) {
struct mntent *mountEntry;
int status;
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 1e30e2b..62496fb 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -27,23 +27,21 @@
#include <errno.h>
-static const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n"
-"\n"
-"\tAdd a new name that refers to the same file as \"original-name\"\n"
-"\n"
-"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n"
-"\t-f:\tRemove existing destination files.\n";
+static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n"
+"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n"
+"\nOptions:\n"
+"\t-s\tmake symbolic links instead of hard links\n"
+"\t-f\tremove existing destination files\n";
static int symlinkFlag = FALSE;
static int removeoldFlag = FALSE;
-static const char *destName;
extern int ln_main(int argc, char **argv)
{
int status;
- char newdestName[NAME_MAX];
+ static char* linkName;
if (argc < 3) {
usage (ln_usage);
@@ -69,30 +67,27 @@ extern int ln_main(int argc, char **argv)
}
- destName = argv[argc - 1];
+ linkName = argv[argc - 1];
- if ((argc > 3) && !(isDirectory(destName))) {
- fprintf(stderr, "%s: not a directory\n", destName);
+ if ((argc > 3) && !(isDirectory(linkName))) {
+ fprintf(stderr, "%s: not a directory\n", linkName);
exit (FALSE);
}
while (argc-- >= 2) {
- strcpy(newdestName, destName);
- strcat(newdestName, (*argv)+(strlen(*(++argv))));
-
if (removeoldFlag==TRUE ) {
- status = ( unlink(newdestName) && errno != ENOENT );
+ status = ( unlink(linkName) && errno != ENOENT );
if ( status != 0 ) {
- perror(newdestName);
+ perror(linkName);
exit( FALSE);
}
}
if ( symlinkFlag==TRUE)
- status = symlink(*argv, newdestName);
+ status = symlink(*argv, linkName);
else
- status = link(*argv, newdestName);
+ status = link(*argv, linkName);
if ( status != 0 ) {
- perror(newdestName);
+ perror(linkName);
exit( FALSE);
}
}