aboutsummaryrefslogtreecommitdiff
path: root/coreutils/df.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/df.c')
-rw-r--r--coreutils/df.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/coreutils/df.c b/coreutils/df.c
index 4076b5fec..50dccac52 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -91,8 +91,6 @@ static unsigned long kscale(unsigned long b, unsigned long bs)
91int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 91int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
92int df_main(int argc UNUSED_PARAM, char **argv) 92int 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;
@@ -208,6 +206,11 @@ int df_main(int argc UNUSED_PARAM, char **argv)
208 } 206 }
209 207
210 device = mount_entry->mnt_fsname; 208 device = mount_entry->mnt_fsname;
209
210 /* GNU coreutils 6.10 skips certain mounts, try to be compatible */
211 if (ENABLE_FEATURE_SKIP_ROOTFS && strcmp(device, "rootfs") == 0)
212 continue;
213
211 mount_point = mount_entry->mnt_dir; 214 mount_point = mount_entry->mnt_dir;
212 fs_type = mount_entry->mnt_type; 215 fs_type = mount_entry->mnt_type;
213 216
@@ -222,26 +225,31 @@ int df_main(int argc UNUSED_PARAM, char **argv)
222 s.f_frsize = s.f_bsize; 225 s.f_frsize = s.f_bsize;
223 226
224 if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) { 227 if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) {
228 unsigned long long blocks_used;
229 unsigned long long blocks_total;
230 unsigned blocks_percent_used;
231
225 if (opt & OPT_INODE) { 232 if (opt & OPT_INODE) {
226 s.f_blocks = s.f_files; 233 s.f_blocks = s.f_files;
227 s.f_bavail = s.f_bfree = s.f_ffree; 234 s.f_bavail = s.f_bfree = s.f_ffree;
228 s.f_frsize = 1; 235 s.f_frsize = 1;
229
230 if (df_disp_hr) 236 if (df_disp_hr)
231 df_disp_hr = 1; 237 df_disp_hr = 1;
232 } 238 }
233 blocks_used = s.f_blocks - s.f_bfree; 239 blocks_used = s.f_blocks - s.f_bfree;
234 blocks_percent_used = 0; 240 blocks_total = blocks_used + s.f_bavail;
235 if (blocks_used + s.f_bavail) { 241 blocks_percent_used = blocks_total; /* 0% if blocks_total == 0, else... */
236 blocks_percent_used = (blocks_used * 100ULL 242 if (blocks_total != 0) {
237 + (blocks_used + s.f_bavail)/2 243 /* Downscale sizes for narrower division */
238 ) / (blocks_used + s.f_bavail); 244 unsigned u;
245 while (blocks_total >= INT_MAX / 101) {
246 blocks_total >>= 1;
247 blocks_used >>= 1;
248 }
249 u = (unsigned)blocks_used * 100u + (unsigned)blocks_total / 2;
250 blocks_percent_used = u / (unsigned)blocks_total;
239 } 251 }
240 252
241 /* GNU coreutils 6.10 skips certain mounts, try to be compatible. */
242 if (ENABLE_FEATURE_SKIP_ROOTFS && strcmp(device, "rootfs") == 0)
243 continue;
244
245#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY 253#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
246 if (strcmp(device, "/dev/root") == 0) { 254 if (strcmp(device, "/dev/root") == 0) {
247 /* Adjusts device to be the real root device, 255 /* Adjusts device to be the real root device,