[hackers] [ubase][PATCH] df: Fix value in Avail column

From: Mattias Andrée <maandree_AT_kth.se>
Date: Tue, 12 Nov 2019 17:24:34 +0100

Free df(1) POSIX man page:

       <total space>
                 [...] <space used>, <space free>, plus any space reserved
                 by the system not normally available to a user.

       <space free>
                 [...] for the creation of new files by unprivileged users, [...]

Note, Capacity remains unchanged because it shall be

       <space used>/(<space used> + <space free>)

and it is maid explicitly clear that <space used> + <space free> shall not be <total space>:

       [...] This percentage may be greater than 100 if <space free> is less than zero [...]

Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
---
 df.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/df.c b/df.c
index 4d595d6..245cca3 100644
--- a/df.c
+++ b/df.c
_AT_@ -65,8 +65,8 @@ mnt_show(const char *fsname, const char *dir)
 
 	bs = s.f_frsize / blksize;
 	total = s.f_blocks * bs;
-	avail = s.f_bfree * bs;
-	used = total - avail;
+	avail = s.f_bavail * bs;
+	used = total - s.f_bfree * bs;
 
 	if (used + avail) {
 		capacity = (used * 100) / (used + avail);
-- 
2.24.0
Received on Tue Nov 12 2019 - 17:24:34 CET

This archive was generated by hypermail 2.3.0 : Tue Nov 12 2019 - 17:36:24 CET