diff options
author | Eric Andersen | 2001-02-21 00:24:51 +0000 |
---|---|---|
committer | Eric Andersen | 2001-02-21 00:24:51 +0000 |
commit | 7c3e7ac9401ae238768ae2366728add1569052ad (patch) | |
tree | f927deb113d565038886aa13cecb5ae372465993 /coreutils/df.c | |
parent | 8d7bdc9deb754b8d52631aaf5d864a5584056b50 (diff) | |
download | busybox-7c3e7ac9401ae238768ae2366728add1569052ad.zip busybox-7c3e7ac9401ae238768ae2366728add1569052ad.tar.gz |
df was totally broken. So I fixed it.
-Erik
Diffstat (limited to 'coreutils/df.c')
-rw-r--r-- | coreutils/df.c | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/coreutils/df.c b/coreutils/df.c index 8f6ef98..80b7acb 100644 --- a/coreutils/df.c +++ b/coreutils/df.c @@ -39,6 +39,9 @@ static int df(char *device, const char *mountPoint) struct statfs s; long blocks_used; long blocks_percent_used; +#ifdef BB_FEATURE_HUMAN_READABLE + long divisor, base; +#endif if (statfs(mountPoint, &s) != 0) { perror_msg("%s", mountPoint); @@ -59,20 +62,38 @@ static int df(char *device, const char *mountPoint) find_real_root_device_name( device); } #ifdef BB_FEATURE_HUMAN_READABLE - printf("%-20s %9s %9s %9s %3ld%% %s\n", - device, - format((s.f_blocks * s.f_bsize), disp_hr), - format((s.f_blocks - s.f_bfree) * s.f_bsize, disp_hr), - format(s.f_bavail * s.f_bsize, disp_hr), + switch (disp_hr) { + case MEGABYTE: + fprintf(stderr, "got MEGABYTE\n"); + divisor = KILOBYTE; + base = KILOBYTE; + break; + case KILOBYTE: + fprintf(stderr, "got KILOBYTE\n"); + divisor = KILOBYTE; + base = 1; + break; + default: + fprintf(stderr, "got something else\n"); + divisor = KILOBYTE; + base = 0; + } + + printf("%-20s %9s ", device, + format((s.f_blocks * (s.f_bsize / divisor)), base)); + printf("%9s ", + format(((s.f_blocks - s.f_bfree) * + (s.f_bsize / divisor)), base)); + printf("%9s %3ld%% %s\n", + format((s.f_bavail * (s.f_bsize / divisor)), base), blocks_percent_used, mountPoint); #else printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", - device, - (long) (s.f_blocks * s.f_bsize) / KILOBYTE, - (long) ((s.f_blocks - s.f_bfree) * s.f_bsize) / KILOBYTE, - (long) (s.f_bavail * s.f_bsize) / KILOBYTE, - blocks_percent_used, mountPoint); - + device, + (long) (s.f_blocks * (s.f_bsize / KILOBYTE)), + (long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / KILOBYTE)), + (long) (s.f_bavail * (s.f_bsize / KILOBYTE)), + blocks_percent_used, mountPoint); #endif } |