]> git.ipfire.org Git - thirdparty/systemd.git/commit
compress: write sparse files when decompressing to regular files
authornoxiouz <atiurin@proton.me>
Tue, 7 Apr 2026 20:32:52 +0000 (21:32 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 8 Apr 2026 22:44:23 +0000 (23:44 +0100)
commit9bd72b612b76fab62ff6275c48ec19ced918e662
tree7d973053c743933143699fcede37d9fd3df22b30
parentbb93fdaaf3b3e47360d8f136e7137cdb352dd9ed
compress: write sparse files when decompressing to regular files

Core dumps are often very sparse, containing large zero-filled regions
whose actual disk usage can be significantly reduced by preserving
holes. Previously, decompress_stream() always wrote dense output,
expanding all zero regions into allocated disk blocks.

Each decompression backend (xz, lz4, zstd) now auto-detects whether the
output fd is suitable for sparse writes via a shared should_sparse()
helper. The check requires both S_ISREG (regular file) and !O_APPEND,
since O_APPEND causes write() to ignore the file position set by
lseek(), which would collapse the holes and corrupt the output. For
pipes, sockets, and append-mode files, dense writes are preserved via
loop_write_full() with USEC_INFINITY timeout, matching the original
behavior. After sparse decompression, finalize_sparse() sets the final
file size to account for any trailing holes.

This is transparent to callers — all public signatures are unchanged.
coredumpctl benefits automatically:
- coredumpctl debug: temp file in /var/tmp is now sparse
- coredumpctl dump -o file: output file is now sparse
- coredumpctl dump > file: redirected stdout is now sparse
- coredumpctl dump | ...: pipe output unchanged (dense)
- coredumpctl dump >> file: append mode, falls back to dense

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-developed-by: Codex (GPT-5) <noreply@openai.com>
src/basic/compress.c
src/test/test-compress.c