FORMAT created a bad filesystem

Here is a disk image. I was beginning to make another test image for SSDSCAN and got lazy and asked FORMAT.COM to lay it out for me instead of laying it out by hand.

building.img.bz2

(You can easily reverify the filesystem was created initially bad by running FORMAT C: again).

The critical part of the image:

00000200   EB 3C 90 46  52 44 4F 53  34 2E 31 00  02 08 01 00
00000210   02 00 02 FF  1F F8 03 00  20 00 04 00  01 00 00 00
00000220   00 00 00 00  80 00 29 EF  1A 14 18 4E  4F 20 4E 41
00000230   4D 45 20 20  20 20 46 41  54 31 32 20  20 20

Number of reserved sectors: 1 Number of sectors per cluster: 8 Number of sectors per FAT: 3 Number of FATS: 2 Number of sectors in filesystem: 8191

Therefore: number of clusters is (8191 - 3 * 2 - 1) / 8 = 1023.

Maximum number of clusters with 3 sectors per FAT is (3 * 512 * 2 / 3) - 2 = 1022 SSDSCAN tried to recover FILE0400.CHK because it overran into the second FAT as part of the first and thought cluster 1024 was allocated (remember cluster numbers start at 2). You gave me quite the scare.

Microsoft says: Never make a filesystem with number of sectors per FAT too small.

The correct fix: detect this case and reduce "number of sectors in filesystem". Take the minimum of the value you would place and the limit value. The value can be found as follows:

FAT12: R + N * S + E / 16 + (S * 512 * 2 / 3) - 2 FAT16: R + N * S + E / 16 + (S * 512 / 2) - 2 FAT32: R + N * S + E / 16 + (S * 512 / 4) - 2

R: number of reserved sectors N: number of FATs S: number of Sectors per FAT E: number of root directory entries (a normal FAT32 will have E=0, which is indeed what gets written to the BPB).

Edited by Joshua Hudson