Repository navigation
Conversation
A PFS volume with sub-partitions (a partition grown with HIOCADDSUB) was
always reported as damaged, even right after pfsFormat, and repairing it
damaged it for real:
- pfsBitmapReadPartition() added the 4MB APA area of the main partition
to the bitmap address of every subpart. A sub-partition's bitmap starts
at its zone 1, so for subparts >= 1 fsck read and changed blocks that
are not bitmap ("not marked as used").
- fsckCompareBitmap() looked up subpart i in the computed bitmap at zone
offset i instead of ZoneMap[i], so subparts >= 1 were compared with the
wrong part of it ("bitmap unmatch"), and Replace wrote that part back.
Also clear the whole ZoneSizes/ZoneMap arrays instead of 16 bytes.
Tested with a host build of fsck (as in pfsshell) on volumes made by
pfsshell mkpart with sub-partitions: before, NOT CLEAN right after the
format; now clean, and leaked or unmarked zones in a sub-partition are
found and fixed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- fsckFillInode() stored the size of the remaining data zones into number_segdesg (overwritten two lines later) instead of limiting the file size. The cut file kept its old size, beyond its zones, and could not be read. The size is now limited to the data zones that are left. - When the next SEGI could not be read, fsckFillInode() was called with NULL (which crashed before a NULL check was added, and since then did nothing), and the cache entry of the previous descriptor had already been released. Keep the previous descriptor and cut the file there. - fsckCheckZones() marked zones in the computed bitmap while looking for an overlap. When an extent overlapped, its first zones stayed marked although the file is cut before that extent, so they stayed allocated without an owner. Check the whole extent first, then mark it. Also release the bitmap buffer on that early return. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reserved zones (APA area, superblock, bitmap, log, root) were marked in one pass over the cache buffer, but only its first 512 bytes (4096 zones) were written as the first bitmap sector; the following sectors were refilled with the fragment pattern. With more than 4096 reserved zones (small zones on a large main partition) the rest stayed free in the bitmap, and with more than 8192 the loop wrote past the 1KB buffer. Fill and mark every bitmap sector separately. The output is unchanged when 4096 or fewer zones are reserved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the end of the partition list is not a multiple of the smallest partition size (lists made by other tools), no free block can align it and the outer while loop never ends. Return -EINVAL instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The main partition loop read sizesMB[-1] in its increment step when no size fitted, and the sub-partition loops read sizesMB[-1] before checking useIndex < 0 after -ENOSPC. - maxIndex became 9 (past the array) when the driver's maximum partition size was not in the list; take the largest listed size not above it. - A size of 0 MB passed the "% 128" check and walked below index 0. - An unexpected error from HIOCADDSUB was counted as an added sub-partition; stop instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
This PR fixes bugs in the HDD modules that I found while testing PFS volumes that have sub-partitions (partitions grown with HIOCADDSUB). The biggest one is in fsck: it reported every such volume as damaged, and its repair then damaged the volume for real.
fsck: check the bitmaps of sub-partitions at the right place
pfsBitmapReadPartition()added the 4MB APA area of the main partition to the bitmap address of every subpart. A sub-partition's bitmap starts at its zone 1, so for subparts >= 1 fsck read, and could "fix", blocks that are not bitmap ("not marked as used").fsckCompareBitmap()looked up subpartiin the computed bitmap at zone offsetiinstead ofZoneMap[i], so subparts >= 1 were compared with the wrong part of it ("bitmap unmatch"), and Replace wrote that wrong part back.ZoneSizes/ZoneMapare now cleared completely, not just their first 16 bytes.fsck: fix "Remove rest of file"
fsckFillInode()wrote the size of the remaining data zones intonumber_segdesg, which is overwritten two lines later, instead of limiting the file size. The cut file kept a size beyond its zones and could not be read. The size is now limited to the data zones that are left.fsckFillInode()was called with NULL, and the previous descriptor had already been released. fsck now keeps the previous descriptor and cuts the file there.fsckCheckZones()marked zones while it was still looking for an overlap. When an extent overlapped, its first zones stayed marked even though the file is cut before that extent, so they stayed allocated without an owner. It now checks the whole extent first and marks it afterwards. The bitmap buffer is also released on that early return.libpfs: mark all reserved zones in
pfsFormatSub()Only the first bitmap sector (4096 zones) got the reserved bits. With more reserved zones (small zones on a large main partition), the rest stayed free, and with more than 8192 the loop wrote past the 1KB buffer. Each bitmap sector is now filled and marked separately. The output is the same when 4096 or fewer zones are reserved.
apa: no endless loop in
hddAddPartitionHere()If the end of the partition list is not a multiple of the smallest partition size (lists made by other tools), it can never be aligned and the loop never ends. The function now returns
-EINVAL.libhdd: out-of-bounds reads in
hddMakeFilesystem()/hddExpandFilesystem()sizesMB[-1]was read when no size fitted, and after-ENOSPC.maxIndexbecame 9 when the driver's maximum size was not in the list. It now takes the largest listed size not above the maximum.HIOCADDSUBerror was counted as an added sub-partition. It now stops instead.Testing
fsck.irx,ps2hdd.irx,ps2fs.irxandlibhdd.abuild with the current toolchain.pfsshell mkpartwith sub-partitions and with files written by pfsshell:🤖 Generated with Claude Code