aboutsummaryrefslogtreecommitdiff
path: root/df.c
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>1999-11-06 06:07:27 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>1999-11-06 06:07:27 +0000
commit610e4739f7561cb7b2a2e7417052db14e32fd256 (patch)
tree57ba26bdcf5dae8deb91a3d1a9b47bcc140689a0 /df.c
parent210df30f0012b40ce819c119ca00ad31ef76d8b8 (diff)
downloadbusybox-w32-610e4739f7561cb7b2a2e7417052db14e32fd256.tar.gz
busybox-w32-610e4739f7561cb7b2a2e7417052db14e32fd256.tar.bz2
busybox-w32-610e4739f7561cb7b2a2e7417052db14e32fd256.zip
Fixed ln, df, and removed redundant stuff from mtab.
git-svn-id: svn://busybox.net/trunk/busybox@81 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'df.c')
-rw-r--r--df.c54
1 files changed, 10 insertions, 44 deletions
diff --git a/df.c b/df.c
index 94b6b8231..a84a330d8 100644
--- a/df.c
+++ b/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 */
73extern 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
107extern int df_main(int argc, char **argv) 70extern 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;