Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the FAT media descriptor match everywhere.
In a FAT12 or FAT16 filesystem, the first entry's first byte must match the media descriptor given in the BPB (BIOS Parameter Block, part of the boot sector). This gives a kind of check of the disk geometry: on an unpartitioned disk (like a floppy or ZIP disk), the BPB can be read with the wrong geometry, but to properly locate the FAT, the geometry must be correct. Many OSs don't check that these match, but a few do, such as FreeBSD (both in the kernel msdos filesystem driver, and in fsck_msdosfs). If they don't match, the mount will fail with an unhelpful error message. Previously, the media descriptor was 0xf8 in the BPB, but 0xf0 in the FAT. This patch changes them to 0xf0 everywhere. There were different values used for different disk geometries before disk addressing was reformed in the 90s, but since then only 0xf0 and 0xf8 are in common use. Typically, 0xf0 is used for a filesystem within an unpartitioned medium (such as a floppy disk), and 0xf8 is used for a filesystem within a partition (such as a hard disk). Since the UF2 bootloader emulates an unpartitioned removable medium, 0xf0 seemed appropriate. See also the description of the media descriptor, offset 0x15, at https://en.wikipedia.org/w/index.php?title=Design_of_the_FAT_file_system&oldid=920681387#BIOS_Parameter_Block particularly the last few paragraphs which note that it must match the FAT ID.
- Loading branch information