Skip to content

df: add a fallback path for statfs with a mount table#12072

Open
Gelbpunkt wants to merge 1 commit intouutils:mainfrom
Gelbpunkt:df-fallback-statfs-with-mounts
Open

df: add a fallback path for statfs with a mount table#12072
Gelbpunkt wants to merge 1 commit intouutils:mainfrom
Gelbpunkt:df-fallback-statfs-with-mounts

Conversation

@Gelbpunkt
Copy link
Copy Markdown

There are situations where the mount table would not contain an entry for /, so df /usr would fail if there was not a mount entry for / or /usr. GNU coreutils however behave a little different here: it seems like they also use the statfs fallback to find the filesystem that the path is on and then print the last mountpoint in the mount table that is on the same filesystem. Add such a fallback.

Fixes #11780

@Gelbpunkt
Copy link
Copy Markdown
Author

This now matches GNU coreutils:

/ # df /usr
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/nvme0n1p2 490150872 162162432 303016716  35% /mnt/pmbootstrap/packages
/ # /tmp/coreutils df /usr
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/nvme0n1p2 490150872 162162432 303016716  35% /mnt/pmbootstrap/packages

I also tried just always using the fallback codepath, but it wouldn't match GNU coreutils in output since it cannot consider the mount table. The behavior for GNU coreutils is inferred based on observations and strace, I haven't actually looked at the source code.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 29, 2026

Merging this PR will improve performance by 4.62%

⚡ 1 improved benchmark
✅ 310 untouched benchmarks
⏩ 46 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation df_deep_directory 368.3 µs 352.1 µs +4.62%

Comparing Gelbpunkt:df-fallback-statfs-with-mounts (96ddd7c) with main (5aade31)2

Open in CodSpeed

Footnotes

  1. 46 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.

  2. No successful run was found on main (dd72eca) during the generation of this report, so 5aade31 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 29, 2026

GNU testsuite comparison:

GNU test failed: tests/df/over-mount-device. tests/df/over-mount-device is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/tail/pid-pipe. tests/tail/pid-pipe is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)

There are situations where the mount table would not contain
an entry for /, so df /usr would fail if there was not a mount
entry for / or /usr. GNU coreutils however behave a little
different here: it seems like they also use the statfs fallback
to find the filesystem that the path is on and then print the
last mountpoint in the mount table that is on the same filesystem.
Add such a fallback.
@Gelbpunkt Gelbpunkt force-pushed the df-fallback-statfs-with-mounts branch from 57c7fc6 to 96ddd7c Compare April 29, 2026 09:23
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 does not look for filesystem that directory is on

1 participant