MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / ScanVolumeBootcode

Function ScanVolumeBootcode

rEFIt_UEFI/refit/lib.cpp:410–691  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

408//
409
410static VOID ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT BOOLEAN *Bootable)
411{
412 EFI_STATUS Status;
413 UINT8 *SectorBuffer;
414 UINTN i;
415 //MBR_PARTITION_INFO *MbrTable;
416 //BOOLEAN MbrTableFound;
417 UINTN BlockSize = 0;
418 CHAR16 volumeName[255];
419 CHAR8 tmp[64];
420 UINT32 VCrc32;
421 // CHAR16 *kind = NULL;
422
423 Volume->HasBootCode = FALSE;
424 Volume->LegacyOS->IconName.setEmpty();
425 Volume->LegacyOS->Name.setEmpty();
426 // Volume->BootType = BOOTING_BY_MBR; //default value
427 Volume->BootType = BOOTING_BY_EFI;
428 *Bootable = FALSE;
429
430 if ((Volume->BlockIO == NULL) || (!Volume->BlockIO->Media->MediaPresent))
431 return;
432 ZeroMem((CHAR8*)&tmp[0], 64);
433 BlockSize = Volume->BlockIO->Media->BlockSize;
434 if (BlockSize > 2048)
435 return; // our buffer is too small... the bred of thieve of cable
436 SectorBuffer = (__typeof__(SectorBuffer))AllocateAlignedPages(EFI_SIZE_TO_PAGES (2048), 16); //align to 16 byte?! Poher
437 ZeroMem((CHAR8*)&SectorBuffer[0], 2048);
438 // look at the boot sector (this is used for both hard disks and El Torito images!)
439 Status = Volume->BlockIO->ReadBlocks(Volume->BlockIO, Volume->BlockIO->Media->MediaId,
440 Volume->BlockIOOffset /*start lba*/,
441 2048, SectorBuffer);
442 if (!EFI_ERROR(Status) && (SectorBuffer[1] != 0)) {
443 // calc crc checksum of first 2 sectors - it's used later for legacy boot BIOS drive num detection
444 // note: possible future issues with AF 4K disks
445 *Bootable = TRUE;
446 Volume->HasBootCode = TRUE; //we assume that all CD are bootable
447 /* DBG("check SectorBuffer\n");
448 for (i=0; i<32; i++) {
449 DBG("%2hhX ", SectorBuffer[i]);
450 }
451 DBG("\n"); */
452 VCrc32 = GetCrc32(SectorBuffer, 512 * 2);
453 Volume->DriveCRC32 = VCrc32;
454 //gBS->CalculateCrc32 (SectorBuffer, 2 * 512, &Volume->DriveCRC32);
455 /* switch (Volume->DiskKind ) {
456 case DISK_KIND_OPTICAL:
457 kind = L"DVD";
458 break;
459 case DISK_KIND_INTERNAL:
460 kind = L"HDD";
461 break;
462 case DISK_KIND_EXTERNAL:
463 kind = L"USB";
464 break;
465 default:
466 break;
467 }

Callers 2

ScanVolumeFunction · 0.85
ScanExtendedPartitionFunction · 0.85

Calls 9

GetCrc32Function · 0.85
AsciiStrToUnicodeStrSFunction · 0.85
FindMemFunction · 0.70
ZeroMemFunction · 0.50
CompareMemFunction · 0.50
FreeAlignedPagesFunction · 0.50
setEmptyMethod · 0.45
notEmptyMethod · 0.45
wc_strMethod · 0.45

Tested by

no test coverage detected