Fix ExtentsFileBuffer.Read for sparse files with holes #291
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.
Fix for ExtentsFileBuffer.Read, which reads a portion of the contents of a single file in an ext file system.
The old code relied on a private method FindExtent which, given the next logical block number to read in the file, sometimes returned the extent containing that block but sometimes returned a prior extent. This logic was sufficient for non-sparse files without "holes" but could not properly handle sparse files. In the presence of holes, the Read method could fall into an infinite loop trying to read the file but never making progress.
The new code redefines FindExtent to return the extent containing a given logical block or, if none, the first extent beyond it. Given this information, the Read method is guaranteed to always make forward progress.
This pull request also fixes a problem in which the high-order bit of the Extent.NumBlocks field is misinterpreted. That bit is used as a flag by the Linux kernel to indicate an unwritten extent, and should not be considered part of the actual block count.