Repository navigation
ext4: preserve sparse file offsets and zero unwritten extents on read - #458
Merged
Merged
Conversation
Read logical ranges instead of concatenating physical extents. Holes and unwritten extents read as zeros without touching the backend, the exact byte prefix, cursor and backend error are preserved on short or invalid reads, and overlapping, unsorted or overflowing mappings are rejected. Sorted extents let the read loop stop at the first extent past the window, and a backend that reports io.EOF together with a complete read, as io.ReaderAt allows, is treated as success. Add independent byte-oracle, seek, unwritten-boundary and backend-fault regressions, plus a real-image regression built with mkfs.ext4 -d from a sparse source and extended with an unwritten extent by debugfs; it skips when e2fsprogs is not installed. Document the sparse read semantics in ext4.md. No writer, extent parser or module dependency changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
File.Readin the ext4 driver walked the extents as if they formed one contiguousbyte stream. A file with a hole (a logical block range without an extent) therefore
returned data from the wrong offset, and after #430 any read that touched a hole
failed with
read offset ... falls outside extent. Uninitialized extents(
ee_len > 32768) returned whatever the disk blocks contain instead of zeros.Change
Readnow resolves the requested logical byte range against the extent map:violation is reported as a corrupt mapping instead of being read through;
backend error are preserved;
sorted);
io.EOFtogether with a complete read, asio.ReaderAtallows, is treated as success.
No writer, extent parser or dependency changes.
Writekeeps the check from #430.Tests
filesystem/ext4/file_sparse_read_test.goadds:including seeks;
io.EOFwith afull read) with a fault-injecting
backend.Storage;mkfs.ext4 -dfrom a sparse source, an unwritten extentadded with
debugfs fallocate, garbage written into the unwritten blocks, verifiedwith
e2fsck -f -n. It skips whenmkfs.ext4,debugfsore2fsckis missing,so the macOS and Windows CI legs are unaffected.
With the previous
Readrestored, all seven new tests fail.Docs
filesystem/ext4/ext4.mddocuments the read semantics for holes, uninitializedextents and extent ordering.
Verification
go test ./filesystem/ext4/on Linux with Go 1.25 and e2fsprogs 1.47.2: okgolangci-lint run ./...(v2 config, 0 issues),go buildandmake vetonmacOS,
GOOS=windowscross build and lint: ok