Repository navigation
Fix librbf raw I/O, segmented line reads, and write-only file deletion - #83
Merged
Merged
Conversation
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.
Summary
This PR fixes four independent bugs in librbf and adds a regression test for
each. The fixes address incorrect byte counts and file positions during reads
and writes, plus a crash when deleting a write-only file.
=================================================
Problem:
_os9_read() checked whether a raw path was already at EOF, but did not limit a
request that crossed the end of the disk. For example, requesting 32 bytes with
only 16 remaining reported 32 bytes read and advanced the tracked file position
16 bytes past EOF. A read starting at EOF also returned EOS_EOF without resetting
the requested byte count to zero.
Fix:
Clamp the raw read size to the number of bytes remaining in the disk image. Set
the returned byte count to zero when the position is at or beyond EOF.
Regression test: test_os9_raw_read_end_of_disk
the buffer and position unchanged.
============================================================
Problem:
When _os9_readln() encountered a carriage return, it set the returned byte count
to the number of bytes read from the current allocation segment. Bytes already
read from earlier segments were omitted. The buffer and file position reflected
the complete line, but the reported length did not.
Fix:
Include bytes accumulated from earlier segments when calculating the returned
line length.
Regression test: test_os9_readln_across_segments
another segment.
second.
the position is immediately after the carriage return.
Before the fix, this test returned a length of 3 instead of 9.
============================================================
Problem:
_os9_freefile() reopened the target file with FAM_READ to obtain its allocation
information. For a write-only file, the open failed with a permission error, but
the helper continued using the invalid path, causing a crash.
Fix:
Pass the already-open parent path and the target's file-descriptor sector number
to _os9_freefile(). Read the target's descriptor through that path and release
its data allocations using the parent path's bitmap. This removes the dependency
on read permission for the target.
Regression test: test_os9_delete_write_only_file
all data clusters were released.
The write-only deletion path crashed before the fix.
===============================================
Problem:
The raw-path branch of _os9_write() returned the actual number of bytes written
but did not update path->filepos. Consequently, _os9_gs_pos() reported the old
offset, and a following _os9_read() sought back to that stale position.
Fix:
Advance the tracked position by the actual byte count returned by fwrite().
Regression test: test_os9_raw_write_position
position correctly.
Validation