Skip to content

Commit 554be32

Browse files
committed
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 <[email protected]>
1 parent 02b72b1 commit 554be32

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

bin/df/df.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,12 @@ main(int argc, char *argv[])
128128
/*
129129
* POSIX specifically discusses the behavior of
130130
* both -k and -P. It states that the blocksize should
131-
* be set to 1024. Thus, if this occurs, simply break
132-
* rather than clobbering the old blocksize.
131+
* be set to 1024.
133132
*/
134-
if (kflag)
133+
if (kflag) {
134+
setenv("BLOCKSIZE", "1024", 1);
135135
break;
136+
}
136137
setenv("BLOCKSIZE", "512", 1);
137138
hflag = 0;
138139
break;
@@ -154,7 +155,7 @@ main(int argc, char *argv[])
154155
break;
155156
case 'k':
156157
kflag++;
157-
setenv("BLOCKSIZE", "1024", 1);
158+
setenv("BLOCKSIZE", "1k", 1);
158159
hflag = 0;
159160
break;
160161
case 'l':

0 commit comments

Comments
 (0)