@@ -431,30 +431,24 @@ 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 }
459453 }
460454 }
@@ -499,49 +493,51 @@ BOOLEAN
499493UefiInitializeBootDevices (VOID )
500494{
501495 ULONG i = 0 ;
496+ PMASTER_BOOT_RECORD Mbr ;
497+ PULONG Buffer ;
498+ ULONG ChecksumSize = 512 ;
499+ ULONG Checksum = 0 ;
500+ ULONG Signature ;
502501
503502 DiskReadBufferSize = EFI_PAGE_SIZE ;
504503 DiskReadBuffer = MmAllocateMemoryWithType (DiskReadBufferSize , LoaderFirmwareTemporary );
505504 UefiSetupBlockDevices ();
506505 UefiSetBootpath ();
507506
508- /* Add it, if it's a cdrom */
507+ /* Add it */
509508 GlobalSystemTable -> BootServices -> HandleProtocol (handles [UefiBootRootIdentifier ], & bioGuid , (void * * )& bio );
510- if (bio -> Media -> RemovableMedia == TRUE && bio -> Media -> BlockSize == 2048 )
509+
510+ /* Read the MBR */
511+ if (!MachDiskReadLogicalSectors (FrldrBootDrive , 16ULL , 1 , DiskReadBuffer ))
511512 {
512- PMASTER_BOOT_RECORD Mbr ;
513- PULONG Buffer ;
514- ULONG Checksum = 0 ;
515- ULONG Signature ;
513+ ERR ("Reading MBR failed\n" );
514+ return FALSE;
515+ }
516516
517- /* Read the MBR */
518- if (!MachDiskReadLogicalSectors (FrldrBootDrive , 16ULL , 1 , DiskReadBuffer ))
519- {
520- ERR ("Reading MBR failed\n" );
521- return FALSE;
522- }
517+ Buffer = (ULONG * )DiskReadBuffer ;
518+ Mbr = (PMASTER_BOOT_RECORD )DiskReadBuffer ;
523519
524- Buffer = ( ULONG * ) DiskReadBuffer ;
525- Mbr = ( PMASTER_BOOT_RECORD ) DiskReadBuffer ;
520+ Signature = Mbr -> Signature ;
521+ TRACE ( "Signature: %x\n" , Signature ) ;
526522
527- Signature = Mbr -> Signature ;
528- TRACE ( "Signature: %x\n" , Signature ) ;
523+ if ( bio -> Media -> BlockSize == 2048 )
524+ ChecksumSize = bio -> Media -> BlockSize ;
529525
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 );
526+ /* Calculate the MBR checksum */
527+ for (i = 0 ; i < ChecksumSize / sizeof (ULONG ); i ++ )
528+ {
529+ Checksum += Buffer [i ];
530+ }
531+ Checksum = ~Checksum + 1 ;
532+ TRACE ("Checksum: %x\n" , Checksum );
537533
538- /* Fill out the ARC disk block */
539- AddReactOSArcDiskInfo (FrLdrBootPath , Signature , Checksum , TRUE);
534+ /* Fill out the ARC disk block */
535+ AddReactOSArcDiskInfo (FrLdrBootPath , Signature , Checksum , TRUE);
536+
537+ FsRegisterDevice (FrLdrBootPath , & UefiDiskVtbl );
538+ PcBiosDiskCount ++ ; // This is not accounted for in the number of pre-enumerated BIOS drives!
539+ TRACE ("Additional boot drive detected: 0x%02X\n" , (int )FrldrBootDrive );
540540
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- }
545541 return TRUE;
546542}
547543
0 commit comments