mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
[PR #487] [MERGED] Fix miscalculation of NTFS mount file sizes inside WSL #510
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/bootandy/dust/pull/487
Author: @frendsick
Created: 4/19/2025
Status: ✅ Merged
Merged: 4/20/2025
Merged by: @bootandy
Base:
master← Head:fix/wsl-ntfs-calculate-allocated-blocks📝 Commits (6)
7102f12fix: Limit file size based on the file system I/O block size1b618c0fix: Take possible file pre-allocation into accountde7eba1refactor: Reduce indenting with early return07546e6refactor: Fix clippy::manual_div_ceil1b92853fix: Use target_size instead of max_size33ffc2bfix: Take possible pre-allocation for a file into account📊 Changes
1 file changed (+26 additions, -9 deletions)
View changed files
📝
src/platform.rs(+26 -9)📄 Description
The std::fs::Metadata struct sometimes contains incorrect information on how many blocks are allocated to a certain file on an NTFS mount. When that happens, the struct could have an unfathomably large block count that is unrelated to the file's real size.
The proposed fix determines how much space could be allocated to a certain file using
md.blksize(). As far as I know, a file should only have up to one extra operating system block or page allocated for it, typically an extra 4 KB at most. The fixed code uses the same calculation as before by default (reported_size = md.blocks() * get_block_size()), but uses themax_sizewhen it is smaller than thereported_size. Themax_sizeshould be smaller than thereported_sizeonly when the metadata reports too many blocks or when the file system pre-allocates more data for a file than is necessary based on the OS page size.Here is an example of how the current version of
dustcalculates that my C:\Users folder contains 9057 PB of data, whereas the proposed fixed version shows the correct amount of data, or at least very close to it.fixes #295
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.