diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/df.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/coreutils/df.c b/coreutils/df.c index 4076b5fec..1ed09d015 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -91,8 +91,6 @@ static unsigned long kscale(unsigned long b, unsigned long bs) | |||
91 | int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 91 | int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
92 | int df_main(int argc UNUSED_PARAM, char **argv) | 92 | int df_main(int argc UNUSED_PARAM, char **argv) |
93 | { | 93 | { |
94 | unsigned long blocks_used; | ||
95 | unsigned blocks_percent_used; | ||
96 | unsigned long df_disp_hr = 1024; | 94 | unsigned long df_disp_hr = 1024; |
97 | int status = EXIT_SUCCESS; | 95 | int status = EXIT_SUCCESS; |
98 | unsigned opt; | 96 | unsigned opt; |
@@ -222,20 +220,29 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
222 | s.f_frsize = s.f_bsize; | 220 | s.f_frsize = s.f_bsize; |
223 | 221 | ||
224 | if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) { | 222 | if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) { |
223 | unsigned long long blocks_used; | ||
224 | unsigned long long blocks_total; | ||
225 | unsigned blocks_percent_used; | ||
226 | |||
225 | if (opt & OPT_INODE) { | 227 | if (opt & OPT_INODE) { |
226 | s.f_blocks = s.f_files; | 228 | s.f_blocks = s.f_files; |
227 | s.f_bavail = s.f_bfree = s.f_ffree; | 229 | s.f_bavail = s.f_bfree = s.f_ffree; |
228 | s.f_frsize = 1; | 230 | s.f_frsize = 1; |
229 | |||
230 | if (df_disp_hr) | 231 | if (df_disp_hr) |
231 | df_disp_hr = 1; | 232 | df_disp_hr = 1; |
232 | } | 233 | } |
233 | blocks_used = s.f_blocks - s.f_bfree; | 234 | blocks_used = s.f_blocks - s.f_bfree; |
234 | blocks_percent_used = 0; | 235 | blocks_total = blocks_used + s.f_bavail; |
235 | if (blocks_used + s.f_bavail) { | 236 | blocks_percent_used = blocks_total; /* 0% if blocks_total == 0, else... */ |
236 | blocks_percent_used = (blocks_used * 100ULL | 237 | if (blocks_total != 0) { |
237 | + (blocks_used + s.f_bavail)/2 | 238 | /* Downscale sizes for narrower division */ |
238 | ) / (blocks_used + s.f_bavail); | 239 | unsigned u; |
240 | while (blocks_total >= INT_MAX / 101) { | ||
241 | blocks_total >>= 1; | ||
242 | blocks_used >>= 1; | ||
243 | } | ||
244 | u = (unsigned)blocks_used * 100u + (unsigned)blocks_total / 2; | ||
245 | blocks_percent_used = u / (unsigned)blocks_total; | ||
239 | } | 246 | } |
240 | 247 | ||
241 | /* GNU coreutils 6.10 skips certain mounts, try to be compatible. */ | 248 | /* GNU coreutils 6.10 skips certain mounts, try to be compatible. */ |