git: 539547151678 - main - df: Fix -k flag consistency with other BLOCKSIZE flags
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 09 Jan 2026 20:17:25 UTC
The branch main has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=539547151678c63903dddda214b16b177cf418b8
commit 539547151678c63903dddda214b16b177cf418b8
Author: Ankush Mondal <mondalankush9851@gmail.com>
AuthorDate: 2025-11-29 11:15:30 +0000
Commit: Warner Losh <imp@FreeBSD.org>
CommitDate: 2026-01-09 20:17:12 +0000
df: Fix -k flag consistency with other BLOCKSIZE flags
This patch resolves inconsistent behavior between the -k option and
other related flags, including -P. Previously, using -k resulted in
output displayed in 1024-byte blocks, which did not align with the
behavior of similar options such as -m and -g, where output is shown in
1M-blocks and 1G-blocks respectively.
The updated implementation ensures that -k now correctly displays sizes
in 1K-blocks. In addition, the patch incorporates the POSIX requirement
that when both -k -P are specified, the block size must be explicitly
forced to 1024-blocks.
Together, these changes make the behavior of -k consistent, predictable,
and compliant with the standard.
Signed-off-by: Ankush Mondal <mondalankush9851@gmail.com>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1906
---
bin/df/df.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/bin/df/df.c b/bin/df/df.c
index db5b8b18beae..12478d23a2ea 100644
--- a/bin/df/df.c
+++ b/bin/df/df.c
@@ -128,11 +128,12 @@ main(int argc, char *argv[])
/*
* POSIX specifically discusses the behavior of
* both -k and -P. It states that the blocksize should
- * be set to 1024. Thus, if this occurs, simply break
- * rather than clobbering the old blocksize.
+ * be set to 1024.
*/
- if (kflag)
+ if (kflag) {
+ setenv("BLOCKSIZE", "1024", 1);
break;
+ }
setenv("BLOCKSIZE", "512", 1);
hflag = 0;
break;
@@ -154,7 +155,7 @@ main(int argc, char *argv[])
break;
case 'k':
kflag++;
- setenv("BLOCKSIZE", "1024", 1);
+ setenv("BLOCKSIZE", "1k", 1);
hflag = 0;
break;
case 'l':