summaryrefslogtreecommitdiffstats
path: root/toolbox
diff options
context:
space:
mode:
authorBrian Swetland <swetland@google.com>2010-09-11 18:42:53 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-09-11 18:42:53 -0700
commit14200b4c3b04ccdcd45420fa9394fb6412728906 (patch)
tree40c5326ea3b3eab4afcfff0bbde1cf9d778c81f3 /toolbox
parent0dd00036d2a292d96376fbbd22bdc89580f4559c (diff)
parent5833769d9aa41dfb28a74c665fda0fca9c321fc1 (diff)
downloadcore-14200b4c3b04ccdcd45420fa9394fb6412728906.tar.gz
core-14200b4c3b04ccdcd45420fa9394fb6412728906.tar.bz2
core-14200b4c3b04ccdcd45420fa9394fb6412728906.zip
am 5833769d: am 09dd3e57: make df more readable
Merge commit '5833769d9aa41dfb28a74c665fda0fca9c321fc1' * commit '5833769d9aa41dfb28a74c665fda0fca9c321fc1': make df more readable
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 90476bdc8..63940a153 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");