From d5b4e42cace2321c6ad07329001cbbcc1fbf8134 Mon Sep 17 00:00:00 2001 From: kevans Date: Sun, 21 Apr 2019 03:22:57 +0000 Subject: [PATCH] MFC r337271, r337317: stand: i386: sector calculation fixes r337271: Some drives report a geometry that is inconsisetent with the total number of sectors reported through the BIOS. Cylinders * heads * sectors may not necessarily be equal to the total number of sectors reported through int13h function 48h. An example of this is when a Mediasonic HD3-U2B PATA to USB enclosure with a 80 GB disk is attached. Loader hangs at line 506 of stand/i386/libi386/biosdisk.c while attempting to read sectors beyond the end of the disk, sector 156906855. I discovered that the Mediasonic enclosure was reporting the disk with 9767 cylinders, 255 heads, 63 sectors/track. That's 156906855 sectors. However camcontrol and Windows 10 both report report the disk having 156301488 sectors, not the calculated value. At line 280 biosdisk.c sets the sectors to the higher of either bd->bd_sectors or the total calculated at line 276 (156906855) instead of the lower and correct value of 156301488 reported by int 13h 48h. This was tested on all three of my Mediasonic HD3-U2B PATA to USB enclosures. Instead of using the higher of bd_sectors (returned by int13h) or the calculated value, this patch uses the lower and safer of the values. r337317: In r337271, we limited the sector number to the lower of calculated number and CHS based number. However, on some systems, BIOS would report 0 in CHS fields, making the system to think there is 0 sectors. Add a check before comparing the calculated total with bd_sectors. --- stand/i386/libi386/biosdisk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stand/i386/libi386/biosdisk.c b/stand/i386/libi386/biosdisk.c index e8d210aabd7..c1e761af684 100644 --- a/stand/i386/libi386/biosdisk.c +++ b/stand/i386/libi386/biosdisk.c @@ -271,7 +271,7 @@ bd_int13probe(struct bdinfo *bd) total = (uint64_t)params.cylinders * params.heads * params.sectors_per_track; - if (bd->bd_sectors < total) + if (total > 0 && bd->bd_sectors > total) bd->bd_sectors = total; ret = 1; -- 2.45.0