aboutsummaryrefslogtreecommitdiff
path: root/coreutils/df.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-06-13 08:02:45 +0000
committerEric Andersen <andersen@codepoet.org>2001-06-13 08:02:45 +0000
commitf429baca868b7f62ffdeefbfce41abd677f97876 (patch)
tree64925420925deb361a2024b9b362e5c987334124 /coreutils/df.c
parent17822cd60aaf9333a9895494edcf03a0037de54c (diff)
downloadbusybox-w32-f429baca868b7f62ffdeefbfce41abd677f97876.tar.gz
busybox-w32-f429baca868b7f62ffdeefbfce41abd677f97876.tar.bz2
busybox-w32-f429baca868b7f62ffdeefbfce41abd677f97876.zip
I reworked make_human_readable_str so it now has a sane interface,
and then fixed up df, du, and ls to use the new interface. I also fixed up some formatting issues in ls while I was in there. -Erik
Diffstat (limited to 'coreutils/df.c')
-rw-r--r--coreutils/df.c31
1 files changed, 8 insertions, 23 deletions
diff --git a/coreutils/df.c b/coreutils/df.c
index df6874433..6a81086cb 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -32,7 +32,7 @@
32 32
33extern const char mtab_file[]; /* Defined in utility.c */ 33extern const char mtab_file[]; /* Defined in utility.c */
34#ifdef BB_FEATURE_HUMAN_READABLE 34#ifdef BB_FEATURE_HUMAN_READABLE
35static unsigned long df_disp_hr = KILOBYTE; 35static unsigned long df_disp_hr = 1;
36#endif 36#endif
37 37
38static int do_df(char *device, const char *mount_point) 38static int do_df(char *device, const char *mount_point)
@@ -40,9 +40,6 @@ static int do_df(char *device, const char *mount_point)
40 struct statfs s; 40 struct statfs s;
41 long blocks_used; 41 long blocks_used;
42 long blocks_percent_used; 42 long blocks_percent_used;
43#ifdef BB_FEATURE_HUMAN_READABLE
44 long base;
45#endif
46 43
47 if (statfs(mount_point, &s) != 0) { 44 if (statfs(mount_point, &s) != 0) {
48 perror_msg("%s", mount_point); 45 perror_msg("%s", mount_point);
@@ -65,27 +62,15 @@ static int do_df(char *device, const char *mount_point)
65 return FALSE; 62 return FALSE;
66 } 63 }
67#ifdef BB_FEATURE_HUMAN_READABLE 64#ifdef BB_FEATURE_HUMAN_READABLE
68 switch (df_disp_hr) {
69 case MEGABYTE:
70 base = KILOBYTE;
71 break;
72 case KILOBYTE:
73 base = 1;
74 break;
75 default:
76 base = 0;
77 }
78 printf("%-20s %9s ", device, 65 printf("%-20s %9s ", device,
79 make_human_readable_str((unsigned long)(s.f_blocks * 66 make_human_readable_str(s.f_blocks, s.f_bsize/KILOBYTE, df_disp_hr));
80 (s.f_bsize/(double)KILOBYTE)), base)); 67
81 printf("%9s ", 68 printf("%9s ",
82 make_human_readable_str((unsigned long)( 69 make_human_readable_str( (s.f_blocks - s.f_bfree), s.f_bsize/KILOBYTE, df_disp_hr));
83 (s.f_blocks - s.f_bfree) * 70
84 (s.f_bsize/(double)KILOBYTE)), base));
85 printf("%9s %3ld%% %s\n", 71 printf("%9s %3ld%% %s\n",
86 make_human_readable_str((unsigned long)(s.f_bavail * 72 make_human_readable_str(s.f_bavail, s.f_bsize/KILOBYTE, df_disp_hr),
87 (s.f_bsize/(double)KILOBYTE)), base), 73 blocks_percent_used, mount_point);
88 blocks_percent_used, mount_point);
89#else 74#else
90 printf("%-20s %9ld %9ld %9ld %3ld%% %s\n", 75 printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
91 device, 76 device,
@@ -119,7 +104,7 @@ extern int df_main(int argc, char **argv)
119 strcpy(disp_units_hdr, " Size"); 104 strcpy(disp_units_hdr, " Size");
120 break; 105 break;
121 case 'm': 106 case 'm':
122 df_disp_hr = MEGABYTE; 107 df_disp_hr = KILOBYTE;
123 strcpy(disp_units_hdr, "1M-blocks"); 108 strcpy(disp_units_hdr, "1M-blocks");
124 break; 109 break;
125#endif 110#endif