hidden sector count fixes for fat12_16_dbr, fat32_dbr, exfat_dbr and ntfs_dbr #219
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.
Before this change, fat12_16_dbr, fat32_dbr, exfat_dbr and ntfs_dbr rely on the correct hidden sectors value, after this change, for EBIOS they will use the partition_table_entry.start_sector_ofs value passed by the MBR boot code in 32-bit 8(%si). This copies the behavior of ext2_3_4_dbr, which was already using this latter value.
This change fixes the No GRLDR failure reported by the GRUB2 boot code (typically installed by
bootlace.com --floppy /dev/sda1
) when trying to load GRLDR for FAT12, FAT16, FAT32, exFAT and NTFS filesystems.Before this change, the GRUB2 boot code used as partition and filesystem start offset the hidden sectors value in the boot sector (BPB) of the filesystem on the partition. However, this value is often incorrect, for example when creating the filesystem as a image file by the mkfs.vfat, mkfs.exfat and mkfs.ntfs Linux tools, this value is 0 by default, as the tool has no way to know at filesystem creation time where within the the disk image the partition image will be copied to. Also if the partition is moved after it was created, some tools don't update the hidden sectors value.
As explained in https://en.wikipedia.org/wiki/Volume_boot_record , the MBR boot code makes partition sector offset value available at boot time in 32-bit 8(%si) (as part of the MBR partition table entry), thus it can be used instead of the hidden sectors value.
However, on some very old systems 8(%si) may be incorrect. To prevent this change from breaking them, the 8(%si) value is only used if EBIOS is detected. On systems without EBIOS, the user has already taken care of setting sectors per track and number of heads in the boot sector (BPB) (because otherwise the system wouldn't boot), and the tool setting these values correctly has probably set hidden sectors correctly as well.
I've verified that these changes work end-to-end, for example with the attached FAT16 filesystem (with hidden sectors value 0) in hdfat16.bin.xz.zip:
Please note that ext2_3_4_dbr is already correct, it uses the 8(%si) value in
grub4dos/stage2/grldrstart.S
Line 1961 in 6dfb6d4