summaryrefslogtreecommitdiffstats
path: root/toolbox
diff options
context:
space:
mode:
authorBrian Swetland <swetland@google.com>2010-09-11 18:19:35 -0700
committerBrian Swetland <swetland@google.com>2010-09-11 18:19:35 -0700
commit09dd3e57b920c8f65cb486313a4c0f35b8cb9f46 (patch)
tree6a08264c1cb824143881da9ab3149786a900a2cc /toolbox
parent4012c0a46ab2ebdf6a1298bc4e85ed3368d1b8a4 (diff)
downloadsystem_core-09dd3e57b920c8f65cb486313a4c0f35b8cb9f46.zip
system_core-09dd3e57b920c8f65cb486313a4c0f35b8cb9f46.tar.gz
system_core-09dd3e57b920c8f65cb486313a4c0f35b8cb9f46.tar.bz2
make df more readable
Filesystem Size Used Free Blksize /dev 164M 32K 164M 4096 /system 442M 117M 325M 4096 /cache 492M 8M 483M 4096 /data 984M 59M 925M 4096 /mnt/sdcard 12G 27M 12G 32768 Change-Id: I9a84b7b84ae528ee5cf0b1e92a8bee032b87703b
Diffstat (limited to 'toolbox')
-rw-r--r--toolbox/df.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/toolbox/df.c b/toolbox/df.c
index 90476bd..63940a1 100644
--- a/toolbox/df.c
+++ b/toolbox/df.c
@@ -6,6 +6,21 @@
static int ok = EXIT_SUCCESS;
+static void printsize(long long n)
+{
+ char unit = 'K';
+ n /= 1024;
+ if (n > 1024) {
+ n /= 1024;
+ unit = 'M';
+ }
+ if (n > 1024) {
+ n /= 1024;
+ unit = 'G';
+ }
+ printf("%4lld%c", n, unit);
+}
+
static void df(char *s, int always) {
struct statfs st;
@@ -14,18 +29,19 @@ static void df(char *s, int always) {
ok = EXIT_FAILURE;
} else {
if (st.f_blocks == 0 && !always)
- return;
-
- printf("%s: %lldK total, %lldK used, %lldK available (block size %d)\n",
- s,
- ((long long)st.f_blocks * (long long)st.f_bsize) / 1024,
- ((long long)(st.f_blocks - (long long)st.f_bfree) * st.f_bsize) / 1024,
- ((long long)st.f_bfree * (long long)st.f_bsize) / 1024,
- (int) st.f_bsize);
+ return;
+ printf("%-20s ", s);
+ printsize((long long)st.f_blocks * (long long)st.f_bsize);
+ printf(" ");
+ printsize((long long)(st.f_blocks - (long long)st.f_bfree) * st.f_bsize);
+ printf(" ");
+ printsize((long long)st.f_bfree * (long long)st.f_bsize);
+ printf(" %d\n", (int) st.f_bsize);
}
}
int df_main(int argc, char *argv[]) {
+ printf("Filesystem Size Used Free Blksize\n");
if (argc == 1) {
char s[2000];
FILE *f = fopen("/proc/mounts", "r");