Skip to content

disk_space: Support btrfs backend #2159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

bpeetz
Copy link

@bpeetz bpeetz commented May 18, 2025

Btrfs is too smart for the statvfs based backend (i.e., only counting blocks leads to wrong numbers).

For example, a btrfs disk with a lot of de-duplicated blocks (via the copy on write mechanism) might have a drastically over-reported disk usage.

The btrfs backend is currently implemented by parsing the output of the btrfs filesystem usage --raw command. This is suboptimal, as this now relies on the command output not changing.

Vendoring the algorithm used internally by the btrfs command does not seem to be a reasonable alternative, considering that the code1 is rather complex, low level and would require semi-constant maintenance. Additionally, the c code would need bindings to be usable from rust.

I assume, that the btrfs command output will stay rather similar in the future, as a lot of tools rely on directly parsing it (see the various scripts in the issue, this commit fixes).

Fixes: #1654

Btrfs is too smart for the statvfs based backend (i.e., only counting
blocks leads to wrong numbers).

For example, a btrfs disk with a lot of de-duplicated blocks (via the copy
on write mechanism) might have a drastically over-reported disk usage.

The btrfs backend is currently implemented by parsing the output of the
`btrfs filesystem usage --raw` command. This is suboptimal, as this now
relies on the command output not changing.

Vendoring the algorithm used internally by the `btrfs` command does not
seem to be a reasonable alternative, considering that the code[1] is
rather complex, low level and would require semi-constant maintenance.
Additionally, the c code would need bindings to be usable from rust.

I assume, that the `btrfs` command output will stay rather similar in
the future, as a lot of tools rely on directly parsing it (see the
various scripts in the issue, this commit fixes).

[1]: https://github.com/kdave/btrfs-progs/blob/eeab081e9d9fbdf4583122ed1caedf541383cf2d/cmds/filesystem-usage.c#L442

Fixes: greshake#1654
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.

Disk space on btrfs file systems
1 participant