Skip to content

Conversation

@ankushT369
Copy link

@ankushT369 ankushT369 commented Nov 29, 2025

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.

[BUG: 290710]

@github-actions
Copy link

github-actions bot commented Nov 29, 2025

Thank you for taking the time to contribute to FreeBSD!
All issues resolved.

@ankushT369
Copy link
Author

@bsdimp, @concussious can you review this ?

Copy link
Member

@jlduran jlduran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I believe this change is compatible with df. I would like to land D54016, and add a few more tests.

Changes that should ideally land before this PR:

  • Land D54016
  • Add a -k and -k -P test

bin/df/df.c Outdated
/*
* 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
Copy link
Member

@jlduran jlduran Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the last sentence Thus, if this occurs, simply break rather than clobbering the old blocksize. should be removed.

if (kflag) {
setenv("BLOCKSIZE", "1024", 1);
break;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this } needs to be indented using 3 horizontal tabulation characters.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should i make these changes and squash it here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok final :

  1. Remove this one : Thus, if this occurs, simply break ather than clobbering the old blocksize.
  2. and this } needs to be indented using 3 horizontal tabulation characters.

@ankushT369
Copy link
Author

@jlduran can u review this ?? I think I did 3 horizontal tab indent this part by mistake is it ok ?

if (kflag) {
    setenv("BLOCKSIZE", "1024", 1);

bin/df/df.c Outdated
*/
if (kflag) {
setenv("BLOCKSIZE", "1024", 1);
if (kflag) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes in indentation are not needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there anything can I do to fix this back?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I usually do is copy over the original file, open it split-screen and copy it back.

@jlduran
Copy link
Member

jlduran commented Dec 5, 2025

@jlduran can u review this ?? I think I did 3 horizontal tab indent this part by mistake is it ok ?

if (kflag) {
    setenv("BLOCKSIZE", "1024", 1);

No, those changes should be reverted.

@ankushT369
Copy link
Author

I did this :

What I usually do is copy over the original file, open it split-screen and copy it back.

@ankushT369
Copy link
Author

@jlduran is it ok now ?

@concussious
Copy link
Contributor

So, this is changing the behavior to match POSIX? By 1k do you mean 1024 or 1000?

@ankushT369
Copy link
Author

ankushT369 commented Dec 5, 2025

So, this is changing the behavior to match POSIX? By 1k do you mean 1024 or 1000?

by 1k I mean 1024

@concussious
Copy link
Contributor

Then please use ISO IEC designation, that's KiB, not K.

@ankushT369
Copy link
Author

ankushT369 commented Dec 5, 2025

Then please use ISO IEC designation, that's KiB, not K.

but what I found:
According to POSIX standards, "1K" or "1k" is used to refer to 1024 bytes (or units), rather than 1000, in the context of disk space measurement utilities like df.

@jlduran
Copy link
Member

jlduran commented Dec 5, 2025

I guess this is fine by me, if @concussious or @bsdimp have further suggestions, they have the last word.
In my opinion, the title of the commit should be changed to indicate that it only changes the title (just the title) of df's output when using the -k flag to match -m and -g flags. Ideally it should be squashed into one commit.
Thank you!

@ankushT369
Copy link
Author

@jlduran ok I do have to squash into 1 commit ?? can you help me out with the title of commit ?

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]>
@jlduran
Copy link
Member

jlduran commented Dec 5, 2025

@jlduran ok I do have to squash into 1 commit ?? can you help me out with the title of commit ?

I'm terrible at commit titles, something along the lines of:

df: Fix -k flag consistency with other BLOCKSIZE flags

@concussious
Copy link
Contributor

Then please use ISO IEC designation, that's KiB, not K.

but what I found: According to POSIX standards, "1K" or "1k" is used to refer to 1024 bytes (or units), rather than 1000, in the context of disk space measurement utilities like df.

Yes, and we should use 1024. The international standard for referring to 1024 that is called KiB. K or k is ambiguous because macOS and storage manufacturers refer to k as 1000. When scaled to modern infrastructure, measured in PiB, it's a 12.5% difference, hundreds of terabytes.

We use KiB widely in the tree already:

cd src; git grep KiB | wc -l
    593

I even fixed this in our upstream already:

llvm/llvm-project@44a7ecd

So, if we're changing the display text, the current proposed change is a regression. 1024 is specific, KiB is specific, but K or k is just not specific.

https://physics.nist.gov/cuu/Units/binary.html

@concussious
Copy link
Contributor

Then please use ISO IEC designation, that's KiB, not K.

but what I found: According to POSIX standards, "1K" or "1k" is used to refer to 1024 bytes (or units), rather than 1000, in the context of disk space measurement utilities like df.

Actually, do you have a link?

@ankushT369
Copy link
Author

Then please use ISO IEC designation, that's KiB, not K.

but what I found: According to POSIX standards, "1K" or "1k" is used to refer to 1024 bytes (or units), rather than 1000, in the context of disk space measurement utilities like df.

Yes, and we should use 1024. The international standard for referring to 1024 that is called KiB. K or k is ambiguous because macOS and storage manufacturers refer to k as 1000. When scaled to modern infrastructure, measured in PiB, it's a 12.5% difference, hundreds of terabytes.

We use KiB widely in the tree already:

cd src; git grep KiB | wc -l
    593

I even fixed this in our upstream already:

llvm/llvm-project@44a7ecd

So, if we're changing the display text, the current proposed change is a regression. 1024 is specific, KiB is specific, but K or k is just not specific.

https://physics.nist.gov/cuu/Units/binary.html

i see 'k' is kind of ambiguous

@ankushT369
Copy link
Author

Then please use ISO IEC designation, that's KiB, not K.

but what I found: According to POSIX standards, "1K" or "1k" is used to refer to 1024 bytes (or units), rather than 1000, in the context of disk space measurement utilities like df.

Actually, do you have a link?

https://unix.stackexchange.com/questions/179274/what-does-1k-blocks-column-mean-in-the-output-of-df

@concussious
Copy link
Contributor

concussious commented Dec 5, 2025

Then please use ISO IEC designation, that's KiB, not K.

but what I found: According to POSIX standards, "1K" or "1k" is used to refer to 1024 bytes (or units), rather than 1000, in the context of disk space measurement utilities like df.

Actually, do you have a link?

https://unix.stackexchange.com/questions/179274/what-does-1k-blocks-column-mean-in-the-output-of-df

This kind of stuff is very low level, very old, and has a lot of dependencies. When were talking about this, you must go to the actual spec, not stack exchange or Gemini. Here is the spec:

https://pubs.opengroup.org/onlinepubs/9699919799/

It is very specific about output, but does not mention how to refer to it.

Edit: the most recent version: https://pubs.opengroup.org/onlinepubs/9799919799/

@concussious
Copy link
Contributor

I spoke with some of the other committers, and we couldn't get a consensus to change it. Thank you for your submission Ankush!

@bsdimp
Copy link
Member

bsdimp commented Dec 6, 2025

I beg to differ. I'd planned on landing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants