nex_squid/crates
mula.liu d74420f24a Ask NTFS for stored bytes, not for allocated clusters
`FileStandardInfo.AllocationSize` turned out to be the wrong question. Measured
against `fsutil` and `compact` on a real Windows 10 volume:

- it returns the cluster-rounded logical length for ordinary files, including
  1 GiB files extended by `SetEndOfFile` (NTFS does hand over the whole tail,
  and free space moves accordingly) and sub-cluster files living in `$MFT`;
- it reported the full 8 MiB for a file `compact` accounts as 1,572,864 stored
  bytes, i.e. it is blind to NTFS compression, which is the one way Windows
  really does hide size on disk;
- `FSCTL_QUERY_ALLOCATED_RANGES` reported that same compressed file as fully
  allocated, so "which clusters exist" is not "what do they weigh".

`GetCompressedFileSizeW` answers 1,572,864, matching `compact` byte for byte.
It takes the path we already hold instead of a handle, so it is one query per
file rather than a `CreateFileW` pair, and it keeps answering while another
process holds the file open exclusively — the normal state of a cache file.
That also removes the `ALLOCATION_PROBE_MIN` cutoff: it existed to avoid a
handle per small file, and small files on a compressed volume need the honest
number just as much.

Guard the zero answer behind `FILE_ATTRIBUTE_COMPRESSED`/`SPARSE_FILE` (free
from the `Metadata` we already have) so a deleted-but-still-open file cannot
zero out a total the user is about to act on, and read `GetLastError` to tell
failure from a genuine 4 GiB-minus-one length.

Tests: each platform now gets the fixture that provokes its own divergence —
POSIX holes for `st_blocks`, and a `compact`-compressed file for the Windows
path. The old Windows sparse fixture proved nothing: extending a file does not
hole out on NTFS, and `FSCTL_SET_SPARSE` is refused outright on this volume
(`ERROR_INVALID_FUNCTION`), as is `FSCTL_SET_COMPRESSION`
(`ERROR_ACCESS_DENIED`) even for a file we created ourselves.
2026-10-15 17:25:17 +08:00
..
squid-cli squid 0.1.0: macOS 磁盘清理(CLI + TUI) 2026-10-13 17:00:50 +08:00
squid-core Ask NTFS for stored bytes, not for allocated clusters 2026-10-15 17:25:17 +08:00
squid-engine Stop matching path separators in suffixes 2026-10-15 16:51:00 +08:00
squid-platform Windows: real platform layer, recycle-bin trash backend, cross-compile CI 2026-10-15 14:56:55 +08:00
squid-rules Windows: safety layer, rule engine fixes, and 30 built-in cleanup rules 2026-10-15 15:23:19 +08:00
squid-stats Windows: real platform layer, recycle-bin trash backend, cross-compile CI 2026-10-15 14:56:55 +08:00
squid-tui Windows: real platform layer, recycle-bin trash backend, cross-compile CI 2026-10-15 14:56:55 +08:00