@@ -431,31 +431,27 @@ UefiSetupBlockDevices(VOID)
431431 }
432432 else if (handles [i ] == PublicBootHandle )
433433 {
434- ULONG increment = 0 ;
434+ ULONG increment = i ;
435435 ULONG i ;
436436
437- /* 3) Grab the offset into the array of handles and decrement per volume (valid partition) */
438- for ( increment = OffsetToBoot ; increment > 0 ; increment -- )
437+ GlobalSystemTable -> BootServices -> HandleProtocol ( handles [ increment ], & bioGuid , ( void * * ) & bio );
438+ if ( bio -> Media -> LogicalPartition == FALSE )
439439 {
440- GlobalSystemTable -> BootServices -> HandleProtocol (handles [increment ], & bioGuid , (void * * )& bio );
441- if (bio -> Media -> LogicalPartition == FALSE)
442- {
443- TRACE ("Found root at increment %u\n" , increment );
444- UefiBootRootIdentifier = increment ;
440+ TRACE ("Found root at increment %u\n" , increment );
441+ UefiBootRootIdentifier = increment ;
445442
446- for (i = 0 ; i <= PcBiosDiskCount ; ++ i )
443+ for (i = 0 ; i <= PcBiosDiskCount ; ++ i )
444+ {
445+ /* Now only of the root drive number is equal to this drive we found above */
446+ if (InternalUefiDisk [i ].UefiRootNumber == UefiBootRootIdentifier )
447447 {
448- /* Now only of the root drive number is equal to this drive we found above */
449- if (InternalUefiDisk [i ].UefiRootNumber == UefiBootRootIdentifier )
450- {
451- InternalUefiDisk [i ].IsThisTheBootDrive = TRUE;
452- PublicBootArcDisk = i ;
453- TRACE ("Found Boot drive\n" );
454- }
448+ InternalUefiDisk [i ].IsThisTheBootDrive = TRUE;
449+ PublicBootArcDisk = i ;
450+ TRACE ("Found Boot drive\n" );
455451 }
456-
457- break ;
458452 }
453+
454+ break ;
459455 }
460456 }
461457 }
@@ -499,49 +495,51 @@ BOOLEAN
499495UefiInitializeBootDevices (VOID )
500496{
501497 ULONG i = 0 ;
498+ PMASTER_BOOT_RECORD Mbr ;
499+ PULONG Buffer ;
500+ ULONG ChecksumSize = 512 ;
501+ ULONG Checksum = 0 ;
502+ ULONG Signature ;
502503
503504 DiskReadBufferSize = EFI_PAGE_SIZE ;
504505 DiskReadBuffer = MmAllocateMemoryWithType (DiskReadBufferSize , LoaderFirmwareTemporary );
505506 UefiSetupBlockDevices ();
506507 UefiSetBootpath ();
507508
508- /* Add it, if it's a cdrom */
509+ /* Add it */
509510 GlobalSystemTable -> BootServices -> HandleProtocol (handles [UefiBootRootIdentifier ], & bioGuid , (void * * )& bio );
510- if (bio -> Media -> RemovableMedia == TRUE && bio -> Media -> BlockSize == 2048 )
511+
512+ /* Read the MBR */
513+ if (!MachDiskReadLogicalSectors (FrldrBootDrive , 16ULL , 1 , DiskReadBuffer ))
511514 {
512- PMASTER_BOOT_RECORD Mbr ;
513- PULONG Buffer ;
514- ULONG Checksum = 0 ;
515- ULONG Signature ;
515+ ERR ("Reading MBR failed\n" );
516+ return FALSE;
517+ }
516518
517- /* Read the MBR */
518- if (!MachDiskReadLogicalSectors (FrldrBootDrive , 16ULL , 1 , DiskReadBuffer ))
519- {
520- ERR ("Reading MBR failed\n" );
521- return FALSE;
522- }
519+ Buffer = (ULONG * )DiskReadBuffer ;
520+ Mbr = (PMASTER_BOOT_RECORD )DiskReadBuffer ;
523521
524- Buffer = ( ULONG * ) DiskReadBuffer ;
525- Mbr = ( PMASTER_BOOT_RECORD ) DiskReadBuffer ;
522+ Signature = Mbr -> Signature ;
523+ TRACE ( "Signature: %x\n" , Signature ) ;
526524
527- Signature = Mbr -> Signature ;
528- TRACE ( "Signature: %x\n" , Signature ) ;
525+ if ( bio -> Media -> BlockSize == 2048 )
526+ ChecksumSize = bio -> Media -> BlockSize ;
529527
530- /* Calculate the MBR checksum */
531- for (i = 0 ; i < 2048 / sizeof (ULONG ); i ++ )
532- {
533- Checksum += Buffer [i ];
534- }
535- Checksum = ~Checksum + 1 ;
536- TRACE ("Checksum: %x\n" , Checksum );
528+ /* Calculate the MBR checksum */
529+ for (i = 0 ; i < ChecksumSize / sizeof (ULONG ); i ++ )
530+ {
531+ Checksum += Buffer [i ];
532+ }
533+ Checksum = ~Checksum + 1 ;
534+ TRACE ("Checksum: %x\n" , Checksum );
537535
538- /* Fill out the ARC disk block */
539- AddReactOSArcDiskInfo (FrLdrBootPath , Signature , Checksum , TRUE);
536+ /* Fill out the ARC disk block */
537+ AddReactOSArcDiskInfo (FrLdrBootPath , Signature , Checksum , TRUE);
538+
539+ FsRegisterDevice (FrLdrBootPath , & UefiDiskVtbl );
540+ PcBiosDiskCount ++ ; // This is not accounted for in the number of pre-enumerated BIOS drives!
541+ TRACE ("Additional boot drive detected: 0x%02X\n" , (int )FrldrBootDrive );
540542
541- FsRegisterDevice (FrLdrBootPath , & UefiDiskVtbl );
542- PcBiosDiskCount ++ ; // This is not accounted for in the number of pre-enumerated BIOS drives!
543- TRACE ("Additional boot drive detected: 0x%02X\n" , (int )FrldrBootDrive );
544- }
545543 return TRUE;
546544}
547545
0 commit comments