Skip to content

Conversation

@naoNao89
Copy link
Contributor

@naoNao89 naoNao89 commented Nov 24, 2025

Fix Windows df incorrectly reporting 0 bytes available and 100% usage for all filesystems. The issue was caused by hardcoding bavail (blocks available to non-privileged processes) to 0 instead of using the actual free clusters from Windows API.

On Windows, all mounted filesystems displayed:

  • Avail: 0 bytes (always)
  • Use%: 100% (always)
  • --total flag: Completely broken aggregation

This made df output useless for Windows users.

Before (Broken)

Filesystem               Size  Used Avail Use%
\Device\HarddiskVolume2  256G  180G     0 100%
\Device\HarddiskVolume3  677G  494G     0 100%
\Device\HarddiskVolume4  1.9T  1.8T     0 100%
\Device\HarddiskVolume1   50M   35M     0 100%
\Device\HarddiskVolume8   11T  5.9T     0 100%

After (Fixed)

Filesystem               Size  Used Avail Use%
\Device\HarddiskVolume2  256G  180G  76G  70%
\Device\HarddiskVolume3  677G  494G 183G  73%
\Device\HarddiskVolume4  1.9T  1.8T 100G  95%
\Device\HarddiskVolume1   50M   35M  15M  70%
\Device\HarddiskVolume8   11T  5.9T 5.1T  54%

Windows API Context

The fix correctly implements POSIX semantics on Windows:

POSIX Windows Meaning
f_bfree lpNumberOfFreeClusters (no quota consideration) Total free clusters
f_bavail lpNumberOfFreeClusters (quota-aware) Free clusters available to user

Windows GetDiskFreeSpaceW() already respects disk quotas, making this fix semantically correct.

Fixes

Closes #7461

Related Issues

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@sylvestre
Copy link
Contributor

could you please add a test to make sure we don't regress in the future? thanks

@naoNao89 naoNao89 force-pushed the fix/df-windows-bavail branch from 9d81e88 to 57198e8 Compare November 25, 2025 23:27
@naoNao89
Copy link
Contributor Author

done assert!(fs_usage.bavail >= 0);

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)

@sylvestre
Copy link
Contributor

@naoNao89 i was thinking about tests/by-util/test_df.rs

@naoNao89 naoNao89 force-pushed the fix/df-windows-bavail branch 2 times, most recently from a388c9a to 94dd012 Compare November 26, 2025 23:50
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 27, 2025

CodSpeed Performance Report

Merging #9470 will not alter performance

Comparing naoNao89:fix/df-windows-bavail (586f6b7) with main (b9f97d4)

Summary

✅ 126 untouched
⏩ 6 skipped1

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@naoNao89 naoNao89 force-pushed the fix/df-windows-bavail branch from 94dd012 to 586f6b7 Compare November 27, 2025 00:39
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

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.

df: Incorrect avilable size and percent usage

2 participants