am 09dd3e57: make df more readable
Merge commit '09dd3e57b920c8f65cb486313a4c0f35b8cb9f46' into gingerbread-plus-aosp * commit '09dd3e57b920c8f65cb486313a4c0f35b8cb9f46': make df more readable
This commit is contained in:
commit
5833769d9a
1 changed files with 24 additions and 8 deletions
32
toolbox/df.c
32
toolbox/df.c
|
|
@ -6,6 +6,21 @@
|
||||||
|
|
||||||
static int ok = EXIT_SUCCESS;
|
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) {
|
static void df(char *s, int always) {
|
||||||
struct statfs st;
|
struct statfs st;
|
||||||
|
|
||||||
|
|
@ -14,18 +29,19 @@ static void df(char *s, int always) {
|
||||||
ok = EXIT_FAILURE;
|
ok = EXIT_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
if (st.f_blocks == 0 && !always)
|
if (st.f_blocks == 0 && !always)
|
||||||
return;
|
return;
|
||||||
|
printf("%-20s ", s);
|
||||||
printf("%s: %lldK total, %lldK used, %lldK available (block size %d)\n",
|
printsize((long long)st.f_blocks * (long long)st.f_bsize);
|
||||||
s,
|
printf(" ");
|
||||||
((long long)st.f_blocks * (long long)st.f_bsize) / 1024,
|
printsize((long long)(st.f_blocks - (long long)st.f_bfree) * st.f_bsize);
|
||||||
((long long)(st.f_blocks - (long long)st.f_bfree) * st.f_bsize) / 1024,
|
printf(" ");
|
||||||
((long long)st.f_bfree * (long long)st.f_bsize) / 1024,
|
printsize((long long)st.f_bfree * (long long)st.f_bsize);
|
||||||
(int) st.f_bsize);
|
printf(" %d\n", (int) st.f_bsize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int df_main(int argc, char *argv[]) {
|
int df_main(int argc, char *argv[]) {
|
||||||
|
printf("Filesystem Size Used Free Blksize\n");
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
char s[2000];
|
char s[2000];
|
||||||
FILE *f = fopen("/proc/mounts", "r");
|
FILE *f = fopen("/proc/mounts", "r");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue