[PATCH] df: allow 1024 byte blocks when POSIXLY_CORRECT

Jan Fooken jan at faulty.computer
Thu May 15 08:11:39 UTC 2025


Hi,

while parsing the output of df I realised that the behaviour is a bit
different compared to the behaviour described by POSIX, especially when
it comes to handling the options -k and -P.

The current and previous revisions of the POSIX standard POSIX.1-2017
and POSIX.1-2024 both allow for using 1024 byte based blocks, when the
option -k is passed.  This patch implements this functionality even when
POSIXLY_CORRECT is set.  Furthermore, it aligns the behaviour of the
with the current df variant from GNU coreutils as of version 9.7.

Regarding the -P behaviour: The POSIX spec states to use 512 byte blocks
when it's passed and the current busybox version uses 1024 byte blocks
except when POSIXLY_CORRECT is set.  I think it would be a good idea to
follow POSIX.1 a bit more closely and use 512 byte blocks when -P is
passed and 1024 byte blocks when -Pk is passed regardless of the state
of POSIXLY_CORRECT.  What do you think?


Kind regards

Jan Fooken
---
 coreutils/df.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/coreutils/df.c b/coreutils/df.c
index 03aa78148..015994efb 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -155,6 +155,9 @@ int df_main(int argc UNUSED_PARAM, char **argv)
 			, &opt_t
 			IF_FEATURE_DF_FANCY(, &chp)
 	);
+	if (opt & OPT_KILO)
+		df_disp_hr = 1024;
+
 	if (opt & OPT_MEGA)
 		df_disp_hr = 1024*1024;
 
-- 
2.49.0



More information about the busybox mailing list