https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3a7fe56a5d5033bcb5e8733fe49e7f24b9a2def3
commit 3a7fe56a5d5033bcb5e8733fe49e7f24b9a2def3 Author: Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org> AuthorDate: Sun Sep 22 18:41:44 2024 +0200 Commit: Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org> CommitDate: Mon Sep 30 12:11:15 2024 +0200 [FREELDR] Change GEOMETRY "Sectors" to "SectorsPerTrack" and introduce a new "Sectors" field (#7379) ---- Thanks to the following testers! - Dmitry Borisov (@disean) for testing on NEC PC-98 emulator; - Justin Miller (@DarkFire01) for testing on UEFI platform; - Stanislav Motylkov (@binarymaster) for testing on Xbox emulator (xemu), both livecd and bootcd. ---- "SectorsPerTrack" is for the legacy Cylinders/Heads/Sectors(PerTrack) scheme. - On BIOS-based PCs, INT 13h can return (for LBA-only drives) an invalid geometry, like: C/H/S = (-1)/(-1)/(-1). This is also what happens in our hwide.c driver (see IdentifyDevice() for ATAPI devices): https://github.com/reactos/reactos/blob/db419efbf26c78e39fb57bcaf4f9e4d915d0c96e/boot/freeldr/freeldr/arch/drivers/hwide.c#L918-L928 as well as on VirtualBox for CD-ROMs: https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Devices/PC/BIOS/disk.c#L155 - Therefore, we cannot reliably calculate a valid total number of sectors by multiplying the Cylinders*Heads*SectorsPerTrack values. In addition, such a multiplication could overflow a 32-bit ULONG. Thus, a separate ULONGLONG Sectors member is required to hold such a value, that is retrieved differently. For example for ATAPI devices, our hwide.c driver does return a valid TotalSectors value, even though CHS values are invalid. Other platforms, like UEFI, just work using logical block addressing (LBA) values (see EFI_BLOCK_IO_MEDIA). - uefidisk.c : Per the spec, EFI_BLOCK_IO_MEDIA::LastBlock contains "The last LBA on the device. [...] For ATA devices, this is reported in IDENTIFY DEVICE data words 60-61 (i.e., Total number of user addressable logical sectors) _minus one_. For SCSI devices, this is reported in the READ CAPACITY parameter data 'Returned Logical Block Address field' _minus one_." In other words, LastBlock is a zero-based LBA index quantity. The corresponding total number of valid "sectors"/blocks of the device is therefore, (LastBlock + 1). - Cleanup some old disabled code. --- boot/freeldr/freeldr/arch/i386/hwdisk.c | 2 +- boot/freeldr/freeldr/arch/i386/pc/machpc.c | 22 ++------ boot/freeldr/freeldr/arch/i386/pc/pcdisk.c | 40 +++++++-------- boot/freeldr/freeldr/arch/i386/pc/pchw.c | 4 +- boot/freeldr/freeldr/arch/i386/pc98/pc98disk.c | 70 +++++++++++++++----------- boot/freeldr/freeldr/arch/i386/pc98/pc98hw.c | 6 +-- boot/freeldr/freeldr/arch/i386/xbox/machxbox.c | 13 ++--- boot/freeldr/freeldr/arch/i386/xbox/xboxdisk.c | 3 +- boot/freeldr/freeldr/arch/uefi/uefidisk.c | 13 ++--- boot/freeldr/freeldr/include/arch/pc/machpc.h | 1 - boot/freeldr/freeldr/include/disk.h | 21 ++++---- 11 files changed, 92 insertions(+), 103 deletions(-) diff --git a/boot/freeldr/freeldr/arch/i386/hwdisk.c b/boot/freeldr/freeldr/arch/i386/hwdisk.c index 421fd38d48c..c804137491e 100644 --- a/boot/freeldr/freeldr/arch/i386/hwdisk.c +++ b/boot/freeldr/freeldr/arch/i386/hwdisk.c @@ -137,7 +137,7 @@ DiskOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId) } SectorOffset = 0; - SectorCount = (ULONGLONG)Geometry.Cylinders * Geometry.Heads * Geometry.Sectors; + SectorCount = Geometry.Sectors; } Context = FrLdrTempAlloc(sizeof(DISKCONTEXT), TAG_HW_DISK_CONTEXT); diff --git a/boot/freeldr/freeldr/arch/i386/pc/machpc.c b/boot/freeldr/freeldr/arch/i386/pc/machpc.c index 639895ec25b..fff1673feb4 100644 --- a/boot/freeldr/freeldr/arch/i386/pc/machpc.c +++ b/boot/freeldr/freeldr/arch/i386/pc/machpc.c @@ -121,13 +121,10 @@ PcGetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize) { PCM_PARTIAL_RESOURCE_LIST PartialResourceList; PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry; - // EXTENDED_GEOMETRY ExtGeometry; GEOMETRY Geometry; ULONG Size; - // - // Initialize returned size - // + /* Initialize returned size */ *pSize = 0; /* Set 'Configuration Data' value */ @@ -155,22 +152,11 @@ PcGetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize) DiskGeometry = (PVOID)(((ULONG_PTR)PartialResourceList) + sizeof(CM_PARTIAL_RESOURCE_LIST)); /* Get the disk geometry */ -#if 0 // This is somehow replaced by what PcDiskGetDriveGeometry() does internally. - ExtGeometry.Size = sizeof(EXTENDED_GEOMETRY); - if (DiskGetExtendedDriveParameters(DriveNumber, &ExtGeometry, ExtGeometry.Size)) - { - DiskGeometry->BytesPerSector = ExtGeometry.BytesPerSector; - DiskGeometry->NumberOfCylinders = ExtGeometry.Cylinders; - DiskGeometry->SectorsPerTrack = ExtGeometry.SectorsPerTrack; - DiskGeometry->NumberOfHeads = ExtGeometry.Heads; - } - else -#endif if (PcDiskGetDriveGeometry(DriveNumber, &Geometry)) { DiskGeometry->BytesPerSector = Geometry.BytesPerSector; DiskGeometry->NumberOfCylinders = Geometry.Cylinders; - DiskGeometry->SectorsPerTrack = Geometry.Sectors; + DiskGeometry->SectorsPerTrack = Geometry.SectorsPerTrack; DiskGeometry->NumberOfHeads = Geometry.Heads; } else @@ -186,9 +172,7 @@ PcGetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize) DiskGeometry->SectorsPerTrack, DiskGeometry->BytesPerSector); - // - // Return configuration data - // + /* Return configuration data */ *pSize = Size; return PartialResourceList; } diff --git a/boot/freeldr/freeldr/arch/i386/pc/pcdisk.c b/boot/freeldr/freeldr/arch/i386/pc/pcdisk.c index 28e7fd66a76..1bd498e6730 100644 --- a/boot/freeldr/freeldr/arch/i386/pc/pcdisk.c +++ b/boot/freeldr/freeldr/arch/i386/pc/pcdisk.c @@ -443,8 +443,12 @@ InitDriveGeometry( Cylinders++; DiskDrive->Geometry.Cylinders = Cylinders; DiskDrive->Geometry.Heads = RegsOut.b.dh + 1; - DiskDrive->Geometry.Sectors = RegsOut.b.cl & 0x3F; - DiskDrive->Geometry.BytesPerSector = 512; /* Just assume 512 bytes per sector */ + DiskDrive->Geometry.SectorsPerTrack = RegsOut.b.cl & 0x3F; + DiskDrive->Geometry.BytesPerSector = 512; /* Just assume 512 bytes per sector */ + + DiskDrive->Geometry.Sectors = (ULONGLONG)DiskDrive->Geometry.Cylinders * + DiskDrive->Geometry.Heads * + DiskDrive->Geometry.SectorsPerTrack; TRACE("Regular Int13h(0x%x) returned:\n" "Cylinders : 0x%x\n" @@ -454,7 +458,7 @@ InitDriveGeometry( DriveNumber, DiskDrive->Geometry.Cylinders, DiskDrive->Geometry.Heads, - DiskDrive->Geometry.Sectors, RegsOut.b.cl, + DiskDrive->Geometry.SectorsPerTrack, RegsOut.b.cl, DiskDrive->Geometry.BytesPerSector); return Success; @@ -645,40 +649,35 @@ PcDiskReadLogicalSectorsCHS( ULONG RetryCount; DriveGeometry = DiskDrive->Geometry; - if (DriveGeometry.Sectors == 0 || DriveGeometry.Heads == 0) + if (DriveGeometry.SectorsPerTrack == 0 || DriveGeometry.Heads == 0) return FALSE; while (SectorCount > 0) { /* * Calculate the physical disk offsets. - * Note: DriveGeometry.Sectors < 64 + * Note: DriveGeometry.SectorsPerTrack < 64 */ - PhysicalSector = 1 + (UCHAR)(SectorNumber % DriveGeometry.Sectors); - PhysicalHead = (UCHAR)((SectorNumber / DriveGeometry.Sectors) % DriveGeometry.Heads); - PhysicalTrack = (ULONG)((SectorNumber / DriveGeometry.Sectors) / DriveGeometry.Heads); + PhysicalSector = 1 + (UCHAR)(SectorNumber % DriveGeometry.SectorsPerTrack); + PhysicalHead = (UCHAR)((SectorNumber / DriveGeometry.SectorsPerTrack) % DriveGeometry.Heads); + PhysicalTrack = (ULONG)((SectorNumber / DriveGeometry.SectorsPerTrack) / DriveGeometry.Heads); /* Calculate how many sectors we need to read this round */ if (PhysicalSector > 1) { - if (SectorCount >= (DriveGeometry.Sectors - (PhysicalSector - 1))) - NumberOfSectorsToRead = (DriveGeometry.Sectors - (PhysicalSector - 1)); - else - NumberOfSectorsToRead = SectorCount; + NumberOfSectorsToRead = min(SectorCount, + (DriveGeometry.SectorsPerTrack - (PhysicalSector - 1))); } else { - if (SectorCount >= DriveGeometry.Sectors) - NumberOfSectorsToRead = DriveGeometry.Sectors; - else - NumberOfSectorsToRead = SectorCount; + NumberOfSectorsToRead = min(SectorCount, DriveGeometry.SectorsPerTrack); } /* Make sure the read is within the geometry boundaries */ if ((PhysicalHead >= DriveGeometry.Heads) || (PhysicalTrack >= DriveGeometry.Cylinders) || - ((NumberOfSectorsToRead + PhysicalSector) > (DriveGeometry.Sectors + 1)) || - (PhysicalSector > DriveGeometry.Sectors)) + ((NumberOfSectorsToRead + PhysicalSector) > (DriveGeometry.SectorsPerTrack + 1)) || + (PhysicalSector > DriveGeometry.SectorsPerTrack)) { DiskError("Disk read exceeds drive geometry limits.", 0); return FALSE; @@ -817,8 +816,9 @@ PcDiskGetDriveGeometry(UCHAR DriveNumber, PGEOMETRY Geometry) /* Extended geometry has been initialized, return it */ Geometry->Cylinders = DiskDrive->ExtGeometry.Cylinders; Geometry->Heads = DiskDrive->ExtGeometry.Heads; - Geometry->Sectors = DiskDrive->ExtGeometry.SectorsPerTrack; + Geometry->SectorsPerTrack = DiskDrive->ExtGeometry.SectorsPerTrack; Geometry->BytesPerSector = DiskDrive->ExtGeometry.BytesPerSector; + Geometry->Sectors = DiskDrive->ExtGeometry.Sectors; } else /* Fall back to legacy BIOS geometry */ @@ -845,7 +845,7 @@ PcDiskGetCacheableBlockCount(UCHAR DriveNumber) if (DiskDrive->Int13ExtensionsSupported) return 64; else - return DiskDrive->Geometry.Sectors; + return DiskDrive->Geometry.SectorsPerTrack; } /* EOF */ diff --git a/boot/freeldr/freeldr/arch/i386/pc/pchw.c b/boot/freeldr/freeldr/arch/i386/pc/pchw.c index 4e8249dd99f..e0e24da5108 100644 --- a/boot/freeldr/freeldr/arch/i386/pc/pchw.c +++ b/boot/freeldr/freeldr/arch/i386/pc/pchw.c @@ -394,7 +394,7 @@ DetectBiosDisks(PCONFIGURATION_COMPONENT_DATA SystemKey, { Int13Drives[i].DriveSelect = DriveNumber; Int13Drives[i].MaxCylinders = Geometry.Cylinders - 1; - Int13Drives[i].SectorsPerTrack = (USHORT)Geometry.Sectors; + Int13Drives[i].SectorsPerTrack = (USHORT)Geometry.SectorsPerTrack; Int13Drives[i].MaxHeads = (USHORT)Geometry.Heads - 1; Int13Drives[i].NumberDrives = DiskCount; @@ -402,7 +402,7 @@ DetectBiosDisks(PCONFIGURATION_COMPONENT_DATA SystemKey, DriveNumber, Geometry.Cylinders - 1, Geometry.Heads - 1, - Geometry.Sectors, + Geometry.SectorsPerTrack, Geometry.BytesPerSector); } } diff --git a/boot/freeldr/freeldr/arch/i386/pc98/pc98disk.c b/boot/freeldr/freeldr/arch/i386/pc98/pc98disk.c index 71a21e36267..9eef9d45f71 100644 --- a/boot/freeldr/freeldr/arch/i386/pc98/pc98disk.c +++ b/boot/freeldr/freeldr/arch/i386/pc98/pc98disk.c @@ -268,11 +268,11 @@ Pc98DiskReadLogicalSectorsCHS( { /* * Calculate the physical disk offsets. - * Note: DriveGeometry.Sectors < 64 + * Note: DriveGeometry.SectorsPerTrack < 64 */ - PhysicalSector = (UCHAR)(SectorNumber % DriveGeometry.Sectors); - PhysicalHead = (UCHAR)((SectorNumber / DriveGeometry.Sectors) % DriveGeometry.Heads); - PhysicalTrack = (ULONG)((SectorNumber / DriveGeometry.Sectors) / DriveGeometry.Heads); + PhysicalSector = (UCHAR)(SectorNumber % DriveGeometry.SectorsPerTrack); + PhysicalHead = (UCHAR)((SectorNumber / DriveGeometry.SectorsPerTrack) % DriveGeometry.Heads); + PhysicalTrack = (ULONG)((SectorNumber / DriveGeometry.SectorsPerTrack) / DriveGeometry.Heads); /* Floppy sectors value always start at 1 */ if (DiskDrive->Type & DRIVE_FDD) @@ -281,24 +281,19 @@ Pc98DiskReadLogicalSectorsCHS( /* Calculate how many sectors we need to read this round */ if (PhysicalSector > 1) { - if (SectorCount >= (DriveGeometry.Sectors - (PhysicalSector - 1))) - NumberOfSectorsToRead = (DriveGeometry.Sectors - (PhysicalSector - 1)); - else - NumberOfSectorsToRead = SectorCount; + NumberOfSectorsToRead = min(SectorCount, + (DriveGeometry.SectorsPerTrack - (PhysicalSector - 1))); } else { - if (SectorCount >= DriveGeometry.Sectors) - NumberOfSectorsToRead = DriveGeometry.Sectors; - else - NumberOfSectorsToRead = SectorCount; + NumberOfSectorsToRead = min(SectorCount, DriveGeometry.SectorsPerTrack); } /* Make sure the read is within the geometry boundaries */ if ((PhysicalHead >= DriveGeometry.Heads) || (PhysicalTrack >= DriveGeometry.Cylinders) || - ((NumberOfSectorsToRead + PhysicalSector) > (DriveGeometry.Sectors + 1)) || - (PhysicalSector > DriveGeometry.Sectors)) + ((NumberOfSectorsToRead + PhysicalSector) > (DriveGeometry.SectorsPerTrack + 1)) || + (PhysicalSector > DriveGeometry.SectorsPerTrack)) { DiskError("Disk read exceeds drive geometry limits.", 0); return FALSE; @@ -439,7 +434,7 @@ InitScsiDrive( DiskDrive->Geometry.Cylinders = RegsOut.w.cx; DiskDrive->Geometry.Heads = RegsOut.b.dh; - DiskDrive->Geometry.Sectors = RegsOut.b.dl; + DiskDrive->Geometry.SectorsPerTrack = RegsOut.b.dl; DiskDrive->Geometry.BytesPerSector = RegsOut.w.bx; DiskDrive->LBASupported = FALSE; DiskDrive->IsRemovable = FALSE; @@ -454,7 +449,7 @@ InitScsiDrive( /* CD-ROM */ DiskDrive->Geometry.Cylinders = 0xFFFF; DiskDrive->Geometry.Heads = 0xFFFF; - DiskDrive->Geometry.Sectors = 0xFFFF; + DiskDrive->Geometry.SectorsPerTrack = 0xFFFF; DiskDrive->Geometry.BytesPerSector = 2048; DiskDrive->Type = DRIVE_CDROM; DiskDrive->LBASupported = TRUE; @@ -465,7 +460,7 @@ InitScsiDrive( /* Magneto-optical drive */ DiskDrive->Geometry.Cylinders = 0xFFFF; DiskDrive->Geometry.Heads = 8; - DiskDrive->Geometry.Sectors = 32; + DiskDrive->Geometry.SectorsPerTrack = 32; DiskDrive->Geometry.BytesPerSector = 512; DiskDrive->Type = DRIVE_MO; DiskDrive->LBASupported = TRUE; @@ -483,6 +478,10 @@ InitScsiDrive( return FALSE; } + DiskDrive->Geometry.Sectors = (ULONGLONG)DiskDrive->Geometry.Cylinders * + DiskDrive->Geometry.Heads * + DiskDrive->Geometry.SectorsPerTrack; + DiskDrive->DaUa = DaUa; DiskDrive->Type |= DRIVE_SCSI; DiskDrive->Initialized = TRUE; @@ -495,7 +494,7 @@ InitScsiDrive( DaUa, DiskDrive->Geometry.Cylinders, DiskDrive->Geometry.Heads, - DiskDrive->Geometry.Sectors, + DiskDrive->Geometry.SectorsPerTrack, DiskDrive->Geometry.BytesPerSector); return TRUE; @@ -513,8 +512,10 @@ InitIdeDrive( { DiskDrive->Geometry.Cylinders = DeviceUnit->Cylinders; DiskDrive->Geometry.Heads = DeviceUnit->Heads; - DiskDrive->Geometry.Sectors = DeviceUnit->Sectors; + DiskDrive->Geometry.SectorsPerTrack = DeviceUnit->Sectors; DiskDrive->Geometry.BytesPerSector = DeviceUnit->SectorSize; + DiskDrive->Geometry.Sectors = DeviceUnit->TotalSectors; + DiskDrive->DaUa = 0xFF; DiskDrive->IdeUnitNumber = UnitNumber; DiskDrive->Type = DRIVE_IDE | DRIVE_CDROM; @@ -530,7 +531,7 @@ InitIdeDrive( UnitNumber, DiskDrive->Geometry.Cylinders, DiskDrive->Geometry.Heads, - DiskDrive->Geometry.Sectors, + DiskDrive->Geometry.SectorsPerTrack, DiskDrive->Geometry.BytesPerSector); return TRUE; @@ -582,8 +583,13 @@ InitHardDrive( DiskDrive->Geometry.Cylinders = RegsOut.w.cx; DiskDrive->Geometry.Heads = RegsOut.b.dh; - DiskDrive->Geometry.Sectors = RegsOut.b.dl; + DiskDrive->Geometry.SectorsPerTrack = RegsOut.b.dl; DiskDrive->Geometry.BytesPerSector = RegsOut.w.bx; + + DiskDrive->Geometry.Sectors = (ULONGLONG)DiskDrive->Geometry.Cylinders * + DiskDrive->Geometry.Heads * + DiskDrive->Geometry.SectorsPerTrack; + DiskDrive->DaUa = DaUa; DiskDrive->Type = DRIVE_IDE; DiskDrive->LBASupported = FALSE; @@ -598,7 +604,7 @@ InitHardDrive( DaUa, DiskDrive->Geometry.Cylinders, DiskDrive->Geometry.Heads, - DiskDrive->Geometry.Sectors, + DiskDrive->Geometry.SectorsPerTrack, DiskDrive->Geometry.BytesPerSector); return TRUE; @@ -647,14 +653,14 @@ InitFloppyDrive( /* 320 kB 2DD */ DiskDrive->Geometry.Cylinders = 80; DiskDrive->Geometry.Heads = 2; - DiskDrive->Geometry.Sectors = 16; + DiskDrive->Geometry.SectorsPerTrack = 16; } else { /* 1 MB 2HD */ DiskDrive->Geometry.Cylinders = 77; DiskDrive->Geometry.Heads = 2; - DiskDrive->Geometry.Sectors = 26; + DiskDrive->Geometry.SectorsPerTrack = 26; } break; @@ -664,21 +670,21 @@ InitFloppyDrive( /* 1.44 MB 2HD */ DiskDrive->Geometry.Cylinders = 80; DiskDrive->Geometry.Heads = 2; - DiskDrive->Geometry.Sectors = 18; + DiskDrive->Geometry.SectorsPerTrack = 18; } else if (DeviceAddress == 0x70 || DeviceAddress == 0xF0) { /* 720/640 kB 2DD */ DiskDrive->Geometry.Cylinders = 80; DiskDrive->Geometry.Heads = 2; - DiskDrive->Geometry.Sectors = 8; + DiskDrive->Geometry.SectorsPerTrack = 8; } else { /* 1.2 MB 2HC */ DiskDrive->Geometry.Cylinders = 80; DiskDrive->Geometry.Heads = 2; - DiskDrive->Geometry.Sectors = 15; + DiskDrive->Geometry.SectorsPerTrack = 15; } break; @@ -686,7 +692,7 @@ InitFloppyDrive( /* 1.25 MB 2HD */ DiskDrive->Geometry.Cylinders = 77; DiskDrive->Geometry.Heads = 2; - DiskDrive->Geometry.Sectors = 8; + DiskDrive->Geometry.SectorsPerTrack = 8; break; default: @@ -695,6 +701,10 @@ InitFloppyDrive( } DiskDrive->Geometry.BytesPerSector = BytesPerSector; + DiskDrive->Geometry.Sectors = (ULONGLONG)DiskDrive->Geometry.Cylinders * + DiskDrive->Geometry.Heads * + DiskDrive->Geometry.SectorsPerTrack; + DiskDrive->DaUa = DaUa; DiskDrive->Type = DRIVE_FDD; DiskDrive->LBASupported = FALSE; @@ -709,7 +719,7 @@ InitFloppyDrive( DaUa, DiskDrive->Geometry.Cylinders, DiskDrive->Geometry.Heads, - DiskDrive->Geometry.Sectors, + DiskDrive->Geometry.SectorsPerTrack, DiskDrive->Geometry.BytesPerSector); return TRUE; @@ -898,5 +908,5 @@ Pc98DiskGetCacheableBlockCount(UCHAR DriveNumber) if (DiskDrive->LBASupported) return 64; else - return DiskDrive->Geometry.Sectors; + return DiskDrive->Geometry.SectorsPerTrack; } diff --git a/boot/freeldr/freeldr/arch/i386/pc98/pc98hw.c b/boot/freeldr/freeldr/arch/i386/pc98/pc98hw.c index 98264eec03c..6cff3e86400 100644 --- a/boot/freeldr/freeldr/arch/i386/pc98/pc98hw.c +++ b/boot/freeldr/freeldr/arch/i386/pc98/pc98hw.c @@ -349,7 +349,7 @@ Pc98GetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize) { DiskGeometry->BytesPerSector = Geometry.BytesPerSector; DiskGeometry->NumberOfCylinders = Geometry.Cylinders; - DiskGeometry->SectorsPerTrack = Geometry.Sectors; + DiskGeometry->SectorsPerTrack = Geometry.SectorsPerTrack; DiskGeometry->NumberOfHeads = Geometry.Heads; } else @@ -423,7 +423,7 @@ DetectBiosDisks( { Int13Drives[i].DriveSelect = DriveNumber; Int13Drives[i].MaxCylinders = Geometry.Cylinders - 1; - Int13Drives[i].SectorsPerTrack = (USHORT)Geometry.Sectors; + Int13Drives[i].SectorsPerTrack = (USHORT)Geometry.SectorsPerTrack; Int13Drives[i].MaxHeads = (USHORT)Geometry.Heads - 1; Int13Drives[i].NumberDrives = DiskCount; @@ -431,7 +431,7 @@ DetectBiosDisks( DriveNumber, Geometry.Cylinders - 1, Geometry.Heads - 1, - Geometry.Sectors, + Geometry.SectorsPerTrack, Geometry.BytesPerSector); } } diff --git a/boot/freeldr/freeldr/arch/i386/xbox/machxbox.c b/boot/freeldr/freeldr/arch/i386/xbox/machxbox.c index 97b38062d84..6c0b094f49b 100644 --- a/boot/freeldr/freeldr/arch/i386/xbox/machxbox.c +++ b/boot/freeldr/freeldr/arch/i386/xbox/machxbox.c @@ -95,13 +95,10 @@ XboxGetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize) { PCM_PARTIAL_RESOURCE_LIST PartialResourceList; PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry; - //EXTENDED_GEOMETRY ExtGeometry; GEOMETRY Geometry; ULONG Size; - // - // Initialize returned size - // + /* Initialize returned size */ *pSize = 0; /* Set 'Configuration Data' value */ @@ -129,13 +126,11 @@ XboxGetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize) DiskGeometry = (PVOID)(((ULONG_PTR)PartialResourceList) + sizeof(CM_PARTIAL_RESOURCE_LIST)); /* Get the disk geometry */ - //ExtGeometry.Size = sizeof(EXTENDED_GEOMETRY); - if (XboxDiskGetDriveGeometry(DriveNumber, &Geometry)) { DiskGeometry->BytesPerSector = Geometry.BytesPerSector; DiskGeometry->NumberOfCylinders = Geometry.Cylinders; - DiskGeometry->SectorsPerTrack = Geometry.Sectors; + DiskGeometry->SectorsPerTrack = Geometry.SectorsPerTrack; DiskGeometry->NumberOfHeads = Geometry.Heads; } else @@ -151,9 +146,7 @@ XboxGetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize) DiskGeometry->SectorsPerTrack, DiskGeometry->BytesPerSector); - // - // Return configuration data - // + /* Return configuration data */ *pSize = Size; return PartialResourceList; } diff --git a/boot/freeldr/freeldr/arch/i386/xbox/xboxdisk.c b/boot/freeldr/freeldr/arch/i386/xbox/xboxdisk.c index 06e7e2d6691..4afdc99c398 100644 --- a/boot/freeldr/freeldr/arch/i386/xbox/xboxdisk.c +++ b/boot/freeldr/freeldr/arch/i386/xbox/xboxdisk.c @@ -112,8 +112,9 @@ XboxDiskGetDriveGeometry(UCHAR DriveNumber, PGEOMETRY Geometry) Geometry->Cylinders = DeviceUnit->Cylinders; Geometry->Heads = DeviceUnit->Heads; - Geometry->Sectors = DeviceUnit->Sectors; + Geometry->SectorsPerTrack = DeviceUnit->Sectors; Geometry->BytesPerSector = DeviceUnit->SectorSize; + Geometry->Sectors = DeviceUnit->TotalSectors; return TRUE; } diff --git a/boot/freeldr/freeldr/arch/uefi/uefidisk.c b/boot/freeldr/freeldr/arch/uefi/uefidisk.c index 98d19b346f1..c7e89e92cea 100644 --- a/boot/freeldr/freeldr/arch/uefi/uefidisk.c +++ b/boot/freeldr/freeldr/arch/uefi/uefidisk.c @@ -185,7 +185,7 @@ UefiDiskOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId) } SectorOffset = 0; - SectorCount = (ULONGLONG)Geometry.Cylinders * Geometry.Heads * Geometry.Sectors; + SectorCount = Geometry.Sectors; } Context = FrLdrTempAlloc(sizeof(DISKCONTEXT), TAG_HW_DISK_CONTEXT); @@ -577,10 +577,11 @@ UefiDiskGetDriveGeometry(UCHAR DriveNumber, PGEOMETRY Geometry) UefiDriveNumber = InternalUefiDisk[DriveNumber - FIRST_BIOS_DISK].UefiRootNumber; GlobalSystemTable->BootServices->HandleProtocol(handles[UefiDriveNumber], &bioGuid, (void**)&bio); - Geometry->Cylinders = 1; // Not relevant for the UEFI BIO protocol - Geometry->Heads = 1; // Not relevant for the UEFI BIO protocol - Geometry->Sectors = bio->Media->LastBlock; // Number of sectors per track - Geometry->BytesPerSector = bio->Media->BlockSize; // Number of bytes per sector + Geometry->Cylinders = 1; // Not relevant for the UEFI BIO protocol + Geometry->Heads = 1; // Not relevant for the UEFI BIO protocol + Geometry->SectorsPerTrack = (bio->Media->LastBlock + 1); + Geometry->BytesPerSector = bio->Media->BlockSize; + Geometry->Sectors = (bio->Media->LastBlock + 1); return TRUE; } @@ -592,5 +593,5 @@ UefiDiskGetCacheableBlockCount(UCHAR DriveNumber) TRACE("UefiDiskGetCacheableBlockCount: DriveNumber: %d\n", UefiDriveNumber); GlobalSystemTable->BootServices->HandleProtocol(handles[UefiDriveNumber], &bioGuid, (void**)&bio); - return bio->Media->LastBlock; + return (bio->Media->LastBlock + 1); } diff --git a/boot/freeldr/freeldr/include/arch/pc/machpc.h b/boot/freeldr/freeldr/include/arch/pc/machpc.h index 2263d75778c..0f68027eef3 100644 --- a/boot/freeldr/freeldr/include/arch/pc/machpc.h +++ b/boot/freeldr/freeldr/include/arch/pc/machpc.h @@ -58,7 +58,6 @@ extern ULONG FrldrBootPartition; LONG DiskReportError(BOOLEAN bShowError); BOOLEAN DiskResetController(UCHAR DriveNumber); -// BOOLEAN DiskGetExtendedDriveParameters(UCHAR DriveNumber, PVOID Buffer, USHORT BufferSize); BOOLEAN PcDiskReadLogicalSectors(UCHAR DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer); BOOLEAN PcDiskGetDriveGeometry(UCHAR DriveNumber, PGEOMETRY DriveGeometry); diff --git a/boot/freeldr/freeldr/include/disk.h b/boot/freeldr/freeldr/include/disk.h index b08993a5e8f..ec12a8f4b31 100644 --- a/boot/freeldr/freeldr/include/disk.h +++ b/boot/freeldr/freeldr/include/disk.h @@ -21,19 +21,22 @@ #include <reactos/rosioctl.h> +/* FreeLoader-specific disk geometry structure */ typedef struct _GEOMETRY { - ULONG Cylinders; // Number of cylinders on the disk - ULONG Heads; // Number of heads on the disk - ULONG Sectors; // Number of sectors per track - ULONG BytesPerSector; // Number of bytes per sector - + ULONG Cylinders; ///< Number of cylinders on the disk + ULONG Heads; ///< Number of heads on the disk + ULONG SectorsPerTrack; ///< Number of sectors per track + ULONG BytesPerSector; ///< Number of bytes per sector + ULONGLONG Sectors; ///< Total number of disk sectors/LBA blocks } GEOMETRY, *PGEOMETRY; +#include <pshpack1.h> + /* - * Extended disk geometry (Int13 / ah=48h) + * Extended disk geometry (Int13 / AH=48h) + * See also ntdddisk.h DISK_EX_INT13_INFO */ -#include <pshpack1.h> typedef struct _EXTENDED_GEOMETRY { USHORT Size; @@ -44,7 +47,6 @@ typedef struct _EXTENDED_GEOMETRY ULONGLONG Sectors; USHORT BytesPerSector; ULONG PDPTE; - } EXTENDED_GEOMETRY, *PEXTENDED_GEOMETRY; /* @@ -63,7 +65,6 @@ typedef struct _PARTITION_TABLE_ENTRY UCHAR EndCylinder; // Ending cylinder# (low order bits of cylinder #) ULONG SectorCountBeforePartition; // Number of sectors preceding the partition ULONG PartitionSectorCount; // Number of sectors in the partition - } PARTITION_TABLE_ENTRY, *PPARTITION_TABLE_ENTRY; /* @@ -76,8 +77,8 @@ typedef struct _MASTER_BOOT_RECORD USHORT Reserved; /* 0x1BC */ PARTITION_TABLE_ENTRY PartitionTable[4]; /* 0x1BE */ USHORT MasterBootRecordMagic; /* 0x1FE */ - } MASTER_BOOT_RECORD, *PMASTER_BOOT_RECORD; + #include <poppack.h> /*