Part 6 of 12 is up. This one is about ProDOS, and the short version is that the DOS 3.3 checks can't just be pointed at it, but the principle carries over: what the files claim about themselves has to agree with what the volume says is allocated.
ProDOS thinks in 512-byte blocks, not 256-byte sectors. On a 140K image each block is two sectors, and in a DOS-order image the pair isn't adjacent, so the program carries a small lookup table. Block 19, for example, is track 2 (19 // 8) with a remainder of 3, which lands on sectors 0x9 and 0x8.
Three things in the post that are easy to get backwards:
Index blocks split their pointers. The low bytes of all 256 pointers sit in the first half of the block and the high bytes in the second half. It looks odd, but it was done for the 6502, whose index registers can only reach 256 bytes at a time.
In the volume bitmap, a set bit means free (same as DOS 3.3), but bit 7 is the lowest-numbered block. That's the reverse of the DOS 3.3 numbering, so the code can't be copied across.
Stray bits past the end of the volume get flagged. Garbage in the unused tail of the bitmap block once made CATALOG report 681 blocks free on a 144-block disk.
Then the ownership check: the program maps every block that a file, directory or the bitmap itself owns, and compares that against the bitmap in both directions. A block a file owns that the bitmap calls free is a hard signal, and it's one of the things that makes a disk BAD. A block marked allocated that nothing owns is only noted, since it's usually lost space from an interrupted write.
Part 7 is the first repair engine: when you've read the same disk five times and the reads disagree, how do you decide what the disk says?
https://norsewanderer.com/blog/BlogDSK6.html
Prepare ye to plunder!
Michael Heilemann - The Norseman/The Viking