[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.
This commit is contained in:
Hermès Bélusca-Maïto 2019-01-05 19:25:35 +01:00
parent 655d24d9eb
commit 5053f1f571
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
5 changed files with 67 additions and 33 deletions

View 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'
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,

View file

@ -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 */

View file

@ -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!

View file

@ -22,6 +22,13 @@
/* PROTOTYPES ***************************************************************/
VOID
AddReactOSArcDiskInfo(
IN PSTR ArcName,
IN ULONG Signature,
IN ULONG Checksum,
IN BOOLEAN ValidPartitionTable);
//
// ARC Component Configuration Routines
//

View 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));
/* 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,