Skip to content
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

Wrong Allocated Size for Sparse Files if Read from Cache File #184

Closed
spacekpe opened this issue Dec 12, 2021 · 4 comments
Closed

Wrong Allocated Size for Sparse Files if Read from Cache File #184

spacekpe opened this issue Dec 12, 2021 · 4 comments

Comments

@spacekpe
Copy link

Hello,

and thank you for an awesome software and all the work you put into it over the years!

Here is a bug report about the latest version:

Version:

  • qdirstat 1.8
  • qt5-base 5.15.2

Observed behavior:

  • Sparse files are detected correctly when scanning filesystem from GUI
  • Apparent and allocated sparse file sizes seem to be written correctly to .qdirstat.cache.gz file generated from GUI
  • GUI displays incorrect Allocated size when reading cache file generated by itself

Reproducer:

  • generate sparse file
dd if=/dev/zero of=sparse count=1 seek=100 bs=1M
  • generate cache file of the directory either in GUI or using
qdirstat-cache-writer .
  • load the cache file into the GUI

  • Screenshot of "live scan" - sizes are okay:
    screenshot-ok-live

  • Screenshot of cache read - allocated size is incorrect:
    screenshot-bad-cache

  • cache file to reproduce the problem:
    .qdirstat.cache.gz

Please let me know what other information you need.

@shundhammer
Copy link
Owner

shundhammer commented Dec 12, 2021

You are right; good catch!

For a moment I thought it's a problem of the cache writer to write incorrect numbers of blocks to the cache for sparse files, but AFAICS that's actually correct:

[sh @ balrog] ~/tmp 6 % zcat work-test-sparse.cache.gz
[qdirstat 1.0 cache file]
# Do not edit!
#
# Type	path		size	mtime		<optional fields>

D /work/test/sparse	4K	0x5ee8e19d
F	sparse-8k-zero	8K	0x5ee8e19d	blocks: 0
F	sparse-8k	8K	0x5ee8e1a2	blocks: 8
F	sparse-zero.bin	1000M	0x56b499f6	blocks: 0
F	sparse-1MB.bin	1001M	0x56b49a1c	blocks: 2048

(Using the sparse/ subdirectory from QDirStat's test data at https://github.com/shundhammer/qdirstat/tree/master/test/data)

work-test-sparse-live

Reading back those data from a cache file shows "allocated: 0 Bytes" for all sparse files which is wrong for sparse-8k and sparse-1MB.bin:

work-test-sparse-cached

@shundhammer
Copy link
Owner

This affects only sparse files when read from a cache file. Non-sparse files are displayed correctly.

@shundhammer shundhammer changed the title allocated size not read correctly from cache Wrong Allocated Size for Sparse Files if Read from Cache File Dec 12, 2021
@shundhammer
Copy link
Owner

shundhammer commented Dec 12, 2021

The fix was adding the missing case in the FileInfo item constructor for cached items: If there is a blocks: field for this item in the cache file, it is now correctly used to initialize the item's internal _allocatedSize field.

cached-sparse-files-fixed

Petr, thanks for finding and reporting this!

@spacekpe
Copy link
Author

Wow, thank was fast! Thank you!

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

No branches or pull requests

2 participants