Skip to content

fix: report allocated disk usage for sparse files (#182)#191

Merged
chenquan merged 1 commit into
masterfrom
fix/182-sparse-file-allocated-size
Jul 18, 2026
Merged

fix: report allocated disk usage for sparse files (#182)#191
chenquan merged 1 commit into
masterfrom
fix/182-sparse-file-allocated-size

Conversation

@chenquan

Copy link
Copy Markdown
Owner

diskusage reported each file's apparent/logical size via fs.FileInfo.Size(). For sparse files such as Docker Desktop's Docker.raw that is the max-allocatable limit (~1 TB) rather than the bytes actually on disk (~30 GB), causing diskusage to disagree wildly with du on the same path.

Use allocated blocks (st_blocks * 512) on linux/darwin and GetCompressedFileSizeW on Windows, matching du's default behavior. For non-sparse files the result is unchanged (block-rounding only).

Fixes #182

diskusage reported each file's apparent/logical size via
fs.FileInfo.Size(). For sparse files such as Docker Desktop's
Docker.raw that is the max-allocatable limit (~1 TB) rather than the
bytes actually on disk (~30 GB), causing diskusage to disagree wildly
with `du` on the same path.

Use allocated blocks (st_blocks * 512) on linux/darwin and
GetCompressedFileSizeW on Windows, matching `du`'s default behavior.
For non-sparse files the result is unchanged (block-rounding only).

Fixes #182

Co-Authored-By: Claude <noreply@anthropic.com>
@chenquan
chenquan merged commit 214a61a into master Jul 18, 2026
2 checks passed
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.

docker.raw file size vs diskusage report discrepancy

1 participant