https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5053f1f5715b1a7ec9c36…
commit 5053f1f5715b1a7ec9c36720f9b7ce1a5b87041c
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sat Jan 5 19:25:35 2019 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Jan 5 19:39:32 2019 +0100
[FREELDR] Simplify code by using a AddReactOSArcDiskInfo() helper, and few extra
additions.
- Introduce the AddReactOSArcDiskInfo() helper to get rid of the
duplicated reactos_arc_disk_info usage scattered amongst different
files.
- GetHarddiskInformation(): If we cannot read the disk that has been
enumerated by the BIOS, return a default identifier string.
- GetHarddiskInformation(): The last character of the disk identifier
string corresponds to whether its MBR is "valid"/has the 0xAA55
signature (use 'A') or whether it's not (use 'X'). Tested on
Windows.
- Split PcInitializeBootDevices() in two: the first part of this
function that enumerates hard disks from the BIOS is now moved into
EnumerateHarddisks().
- The 'ValidPartitionTable' field of the ARC disk signature records must
be initialized with correct value that is specified in the different
AddReactOSArcDiskInfo() calls.
---
boot/freeldr/freeldr/arch/archwsup.c | 26 +++++++++++++
boot/freeldr/freeldr/arch/arm/macharm.c | 8 +---
boot/freeldr/freeldr/arch/i386/hwdisk.c | 56 ++++++++++++++++------------
boot/freeldr/freeldr/include/arch/archwsup.h | 7 ++++
boot/freeldr/freeldr/ntldr/winldr.c | 3 +-
5 files changed, 67 insertions(+), 33 deletions(-)
diff --git a/boot/freeldr/freeldr/arch/archwsup.c b/boot/freeldr/freeldr/arch/archwsup.c
index cad4226168..e4e44875b4 100644
--- a/boot/freeldr/freeldr/arch/archwsup.c
+++ b/boot/freeldr/freeldr/arch/archwsup.c
@@ -25,6 +25,32 @@ ARC_DISK_SIGNATURE_EX reactos_arc_disk_info[32];
#define TAG_HW_COMPONENT_DATA 'DCwH'
#define TAG_HW_NAME 'mNwH'
+VOID
+AddReactOSArcDiskInfo(
+ IN PSTR ArcName,
+ IN ULONG Signature,
+ IN ULONG Checksum,
+ IN BOOLEAN ValidPartitionTable)
+{
+ ASSERT(reactos_disk_count <
sizeof(reactos_arc_disk_info)/sizeof(reactos_arc_disk_info[0]));
+
+ /* Fill out the ARC disk block */
+
+ reactos_arc_disk_info[reactos_disk_count].DiskSignature.Signature = Signature;
+ reactos_arc_disk_info[reactos_disk_count].DiskSignature.CheckSum = Checksum;
+ reactos_arc_disk_info[reactos_disk_count].DiskSignature.ValidPartitionTable =
ValidPartitionTable;
+
+ strcpy(reactos_arc_disk_info[reactos_disk_count].ArcName, ArcName);
+ reactos_arc_disk_info[reactos_disk_count].DiskSignature.ArcName =
+ reactos_arc_disk_info[reactos_disk_count].ArcName;
+
+ reactos_disk_count++;
+}
+
+//
+// ARC Component Configuration Routines
+//
+
VOID
NTAPI
FldrSetIdentifier(IN PCONFIGURATION_COMPONENT_DATA ComponentData,
diff --git a/boot/freeldr/freeldr/arch/arm/macharm.c
b/boot/freeldr/freeldr/arch/arm/macharm.c
index 8bf927d1b9..8d4465f8d7 100644
--- a/boot/freeldr/freeldr/arch/arm/macharm.c
+++ b/boot/freeldr/freeldr/arch/arm/macharm.c
@@ -30,7 +30,6 @@ ULONG SecondLevelIcacheSize;
ULONG SecondLevelIcacheFillSize;
extern ULONG reactos_disk_count;
-extern ARC_DISK_SIGNATURE_EX reactos_arc_disk_info[];
ULONG SizeBits[] =
{
@@ -142,12 +141,7 @@ ArmHwDetect(VOID)
RamDiskInitialize();
/* Fill out the ARC disk block */
- reactos_arc_disk_info[reactos_disk_count].DiskSignature.Signature = 0xBADAB00F;
- reactos_arc_disk_info[reactos_disk_count].DiskSignature.CheckSum = 0xDEADBABE;
- strcpy(reactos_arc_disk_info[reactos_disk_count].ArcName, "ramdisk(0)");
- reactos_arc_disk_info[reactos_disk_count].DiskSignature.ArcName =
- reactos_arc_disk_info[reactos_disk_count].ArcName;
- reactos_disk_count++;
+ AddReactOSArcDiskInfo("ramdisk(0)", 0xBADAB00F, 0xDEADBABE, TRUE);
ASSERT(reactos_disk_count == 1);
/* Return the root node */
diff --git a/boot/freeldr/freeldr/arch/i386/hwdisk.c
b/boot/freeldr/freeldr/arch/i386/hwdisk.c
index af86f62382..6123fc1d13 100644
--- a/boot/freeldr/freeldr/arch/i386/hwdisk.c
+++ b/boot/freeldr/freeldr/arch/i386/hwdisk.c
@@ -38,9 +38,6 @@ typedef struct tagDISKCONTEXT
ULONGLONG SectorNumber;
} DISKCONTEXT;
-extern ULONG reactos_disk_count;
-extern ARC_DISK_SIGNATURE_EX reactos_arc_disk_info[];
-
static CHAR Hex[] = "0123456789abcdef";
/* Data cache for BIOS disks pre-enumeration */
@@ -216,6 +213,7 @@ GetHarddiskInformation(UCHAR DriveNumber)
ULONG i;
ULONG Checksum;
ULONG Signature;
+ BOOLEAN ValidPartitionTable;
CHAR ArcName[MAX_PATH];
PARTITION_TABLE_ENTRY PartitionTableEntry;
PCHAR Identifier = PcDiskIdentifier[DriveNumber - 0x80];
@@ -224,6 +222,8 @@ GetHarddiskInformation(UCHAR DriveNumber)
if (!MachDiskReadLogicalSectors(DriveNumber, 0ULL, 1, DiskReadBuffer))
{
ERR("Reading MBR failed\n");
+ /* We failed, use a default identifier */
+ sprintf(Identifier, "BIOSDISK%d", DriveNumber - 0x80 + 1);
return;
}
@@ -242,14 +242,11 @@ GetHarddiskInformation(UCHAR DriveNumber)
Checksum = ~Checksum + 1;
TRACE("Checksum: %x\n", Checksum);
+ ValidPartitionTable = (Mbr->MasterBootRecordMagic == 0xAA55);
+
/* Fill out the ARC disk block */
- reactos_arc_disk_info[reactos_disk_count].DiskSignature.Signature = Signature;
- reactos_arc_disk_info[reactos_disk_count].DiskSignature.CheckSum = Checksum;
- sprintf(ArcName, "multi(0)disk(0)rdisk(%lu)", reactos_disk_count);
- strcpy(reactos_arc_disk_info[reactos_disk_count].ArcName, ArcName);
- reactos_arc_disk_info[reactos_disk_count].DiskSignature.ArcName =
- reactos_arc_disk_info[reactos_disk_count].ArcName;
- reactos_disk_count++;
+ sprintf(ArcName, "multi(0)disk(0)rdisk(%u)", DriveNumber - 0x80);
+ AddReactOSArcDiskInfo(ArcName, Signature, Checksum, ValidPartitionTable);
sprintf(ArcName, "multi(0)disk(0)rdisk(%u)partition(0)", DriveNumber -
0x80);
FsRegisterDevice(ArcName, &DiskVtbl);
@@ -287,21 +284,21 @@ GetHarddiskInformation(UCHAR DriveNumber)
Identifier[15] = Hex[(Signature >> 4) & 0x0F];
Identifier[16] = Hex[Signature & 0x0F];
Identifier[17] = '-';
- Identifier[18] = 'A'; // FIXME: Not always 'A' ...
+ Identifier[18] = (ValidPartitionTable ? 'A' : 'X');
Identifier[19] = 0;
TRACE("Identifier: %s\n", Identifier);
}
-BOOLEAN
-PcInitializeBootDevices(VOID)
+static UCHAR
+EnumerateHarddisks(OUT PBOOLEAN BootDriveReported)
{
UCHAR DiskCount, DriveNumber;
ULONG i;
BOOLEAN Changed;
- BOOLEAN BootDriveReported = FALSE;
- CHAR BootPath[MAX_PATH];
- /* Count the number of visible drives */
+ *BootDriveReported = FALSE;
+
+ /* Count the number of visible harddisk drives */
DiskReportError(FALSE);
DiskCount = 0;
DriveNumber = 0x80;
@@ -333,7 +330,7 @@ PcInitializeBootDevices(VOID)
/* Check if we have seen the boot drive */
if (FrldrBootDrive == DriveNumber)
- BootDriveReported = TRUE;
+ *BootDriveReported = TRUE;
DiskCount++;
DriveNumber++;
@@ -345,6 +342,19 @@ PcInitializeBootDevices(VOID)
TRACE("BIOS reports %d harddisk%s\n",
(int)DiskCount, (DiskCount == 1) ? "" : "s");
+ return DiskCount;
+}
+
+BOOLEAN
+PcInitializeBootDevices(VOID)
+{
+ UCHAR DiskCount;
+ BOOLEAN BootDriveReported = FALSE;
+ ULONG i;
+ CHAR BootPath[MAX_PATH];
+
+ DiskCount = EnumerateHarddisks(&BootDriveReported);
+
/* Get the drive we're booting from */
MachDiskGetBootPath(BootPath, sizeof(BootPath));
@@ -373,17 +383,15 @@ PcInitializeBootDevices(VOID)
TRACE("Signature: %x\n", Signature);
/* Calculate the MBR checksum */
- for (i = 0; i < 2048 / sizeof(ULONG); i++) Checksum += Buffer[i];
+ for (i = 0; i < 2048 / sizeof(ULONG); i++)
+ {
+ Checksum += Buffer[i];
+ }
Checksum = ~Checksum + 1;
TRACE("Checksum: %x\n", Checksum);
/* Fill out the ARC disk block */
- reactos_arc_disk_info[reactos_disk_count].DiskSignature.Signature = Signature;
- reactos_arc_disk_info[reactos_disk_count].DiskSignature.CheckSum = Checksum;
- strcpy(reactos_arc_disk_info[reactos_disk_count].ArcName, BootPath);
- reactos_arc_disk_info[reactos_disk_count].DiskSignature.ArcName =
- reactos_arc_disk_info[reactos_disk_count].ArcName;
- reactos_disk_count++;
+ AddReactOSArcDiskInfo(BootPath, Signature, Checksum, TRUE);
FsRegisterDevice(BootPath, &DiskVtbl);
DiskCount++; // This is not accounted for in the number of pre-enumerated BIOS
drives!
diff --git a/boot/freeldr/freeldr/include/arch/archwsup.h
b/boot/freeldr/freeldr/include/arch/archwsup.h
index 2fe5edc1a8..bbf50dcbfe 100644
--- a/boot/freeldr/freeldr/include/arch/archwsup.h
+++ b/boot/freeldr/freeldr/include/arch/archwsup.h
@@ -22,6 +22,13 @@
/* PROTOTYPES ***************************************************************/
+VOID
+AddReactOSArcDiskInfo(
+ IN PSTR ArcName,
+ IN ULONG Signature,
+ IN ULONG Checksum,
+ IN BOOLEAN ValidPartitionTable);
+
//
// ARC Component Configuration Routines
//
diff --git a/boot/freeldr/freeldr/ntldr/winldr.c b/boot/freeldr/freeldr/ntldr/winldr.c
index e776a84024..e01c5174ca 100644
--- a/boot/freeldr/freeldr/ntldr/winldr.c
+++ b/boot/freeldr/freeldr/ntldr/winldr.c
@@ -151,9 +151,8 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
/* Copy the data over */
RtlCopyMemory(ArcDiskSig, &reactos_arc_disk_info[i],
sizeof(ARC_DISK_SIGNATURE_EX));
- /* Set the ARC Name pointer and mark the partition table as valid */
+ /* Set the ARC Name pointer */
ArcDiskSig->DiskSignature.ArcName = PaToVa(ArcDiskSig->ArcName);
- ArcDiskSig->DiskSignature.ValidPartitionTable = TRUE;
/* Insert into the list */
InsertTailList(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead,