[FREELDR] Simplify code by using a AddReactOSArcDiskInfo() helper, and few extra...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 5 Jan 2019 18:25:35 +0000 (19:25 +0100)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 5 Jan 2019 18:39:32 +0000 (19:39 +0100)
- 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
boot/freeldr/freeldr/arch/arm/macharm.c
boot/freeldr/freeldr/arch/i386/hwdisk.c
boot/freeldr/freeldr/include/arch/archwsup.h
boot/freeldr/freeldr/ntldr/winldr.c

index cad4226..e4e4487 100644 (file)
@@ -25,6 +25,32 @@ ARC_DISK_SIGNATURE_EX reactos_arc_disk_info[32];
 #define TAG_HW_COMPONENT_DATA   'DCwH'
 #define TAG_HW_NAME             'mNwH'
 
 #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,
 VOID
 NTAPI
 FldrSetIdentifier(IN PCONFIGURATION_COMPONENT_DATA ComponentData,
index 8bf927d..8d4465f 100644 (file)
@@ -30,7 +30,6 @@ ULONG SecondLevelIcacheSize;
 ULONG SecondLevelIcacheFillSize;
 
 extern ULONG reactos_disk_count;
 ULONG SecondLevelIcacheFillSize;
 
 extern ULONG reactos_disk_count;
-extern ARC_DISK_SIGNATURE_EX reactos_arc_disk_info[];
 
 ULONG SizeBits[] =
 {
 
 ULONG SizeBits[] =
 {
@@ -142,12 +141,7 @@ ArmHwDetect(VOID)
     RamDiskInitialize();
 
     /* Fill out the ARC disk block */
     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 */
     ASSERT(reactos_disk_count == 1);
 
     /* Return the root node */
index af86f62..6123fc1 100644 (file)
@@ -38,9 +38,6 @@ typedef struct tagDISKCONTEXT
     ULONGLONG SectorNumber;
 } DISKCONTEXT;
 
     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 */
 static CHAR Hex[] = "0123456789abcdef";
 
 /* Data cache for BIOS disks pre-enumeration */
@@ -216,6 +213,7 @@ GetHarddiskInformation(UCHAR DriveNumber)
     ULONG i;
     ULONG Checksum;
     ULONG Signature;
     ULONG i;
     ULONG Checksum;
     ULONG Signature;
+    BOOLEAN ValidPartitionTable;
     CHAR ArcName[MAX_PATH];
     PARTITION_TABLE_ENTRY PartitionTableEntry;
     PCHAR Identifier = PcDiskIdentifier[DriveNumber - 0x80];
     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");
     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;
     }
 
         return;
     }
 
@@ -242,14 +242,11 @@ GetHarddiskInformation(UCHAR DriveNumber)
     Checksum = ~Checksum + 1;
     TRACE("Checksum: %x\n", Checksum);
 
     Checksum = ~Checksum + 1;
     TRACE("Checksum: %x\n", Checksum);
 
+    ValidPartitionTable = (Mbr->MasterBootRecordMagic == 0xAA55);
+
     /* Fill out the ARC disk block */
     /* 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);
 
     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[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);
 }
 
     Identifier[19] = 0;
     TRACE("Identifier: %s\n", Identifier);
 }
 
-BOOLEAN
-PcInitializeBootDevices(VOID)
+static UCHAR
+EnumerateHarddisks(OUT PBOOLEAN BootDriveReported)
 {
     UCHAR DiskCount, DriveNumber;
     ULONG i;
     BOOLEAN Changed;
 {
     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;
     DiskReportError(FALSE);
     DiskCount = 0;
     DriveNumber = 0x80;
@@ -333,7 +330,7 @@ PcInitializeBootDevices(VOID)
 
         /* Check if we have seen the boot drive */
         if (FrldrBootDrive == DriveNumber)
 
         /* Check if we have seen the boot drive */
         if (FrldrBootDrive == DriveNumber)
-            BootDriveReported = TRUE;
+            *BootDriveReported = TRUE;
 
         DiskCount++;
         DriveNumber++;
 
         DiskCount++;
         DriveNumber++;
@@ -345,6 +342,19 @@ PcInitializeBootDevices(VOID)
     TRACE("BIOS reports %d harddisk%s\n",
           (int)DiskCount, (DiskCount == 1) ? "" : "s");
 
     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));
 
     /* 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 */
         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 */
         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!
 
         FsRegisterDevice(BootPath, &DiskVtbl);
         DiskCount++; // This is not accounted for in the number of pre-enumerated BIOS drives!
index 2fe5edc..bbf50dc 100644 (file)
 
 /* PROTOTYPES ***************************************************************/
 
 
 /* PROTOTYPES ***************************************************************/
 
+VOID
+AddReactOSArcDiskInfo(
+    IN PSTR ArcName,
+    IN ULONG Signature,
+    IN ULONG Checksum,
+    IN BOOLEAN ValidPartitionTable);
+
 //
 // ARC Component Configuration Routines
 //
 //
 // ARC Component Configuration Routines
 //
index e776a84..e01c517 100644 (file)
@@ -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));
 
         /* 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.ArcName = PaToVa(ArcDiskSig->ArcName);
-        ArcDiskSig->DiskSignature.ValidPartitionTable = TRUE;
 
         /* Insert into the list */
         InsertTailList(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead,
 
         /* Insert into the list */
         InsertTailList(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead,