| 1009 | } |
| 1010 | |
| 1011 | static VOID ScanExtendedPartition(REFIT_VOLUME *WholeDiskVolume, MBR_PARTITION_INFO *MbrEntry) |
| 1012 | { |
| 1013 | EFI_STATUS Status; |
| 1014 | REFIT_VOLUME *Volume; |
| 1015 | UINT32 ExtBase, ExtCurrent, NextExtCurrent; |
| 1016 | UINTN i; |
| 1017 | UINTN LogicalPartitionIndex = 4; |
| 1018 | UINT8 *SectorBuffer; |
| 1019 | BOOLEAN Bootable; |
| 1020 | MBR_PARTITION_INFO *EMbrTable; |
| 1021 | |
| 1022 | ExtBase = MbrEntry->StartLBA; |
| 1023 | SectorBuffer = (__typeof__(SectorBuffer))AllocateAlignedPages (EFI_SIZE_TO_PAGES (512), WholeDiskVolume->BlockIO->Media->IoAlign); |
| 1024 | |
| 1025 | for (ExtCurrent = ExtBase; ExtCurrent; ExtCurrent = NextExtCurrent) { |
| 1026 | // read current EMBR |
| 1027 | Status = WholeDiskVolume->BlockIO->ReadBlocks(WholeDiskVolume->BlockIO, |
| 1028 | WholeDiskVolume->BlockIO->Media->MediaId, |
| 1029 | ExtCurrent, 512, SectorBuffer); |
| 1030 | if (EFI_ERROR(Status)) |
| 1031 | break; |
| 1032 | if (*((UINT16 *)(SectorBuffer + 510)) != 0xaa55) |
| 1033 | break; |
| 1034 | EMbrTable = (MBR_PARTITION_INFO *)(SectorBuffer + 446); |
| 1035 | |
| 1036 | // scan logical partitions in this EMBR |
| 1037 | NextExtCurrent = 0; |
| 1038 | for (i = 0; i < 4; i++) { |
| 1039 | if ((EMbrTable[i].Flags != 0x00 && EMbrTable[i].Flags != 0x80) || |
| 1040 | EMbrTable[i].StartLBA == 0 || EMbrTable[i].Size == 0) |
| 1041 | break; |
| 1042 | if (IS_EXTENDED_PART_TYPE(EMbrTable[i].Type)) { |
| 1043 | // set next ExtCurrent |
| 1044 | NextExtCurrent = ExtBase + EMbrTable[i].StartLBA; |
| 1045 | break; |
| 1046 | } else { |
| 1047 | |
| 1048 | // found a logical partition |
| 1049 | Volume = new REFIT_VOLUME; |
| 1050 | Volume->DiskKind = WholeDiskVolume->DiskKind; |
| 1051 | Volume->IsMbrPartition = TRUE; |
| 1052 | Volume->MbrPartitionIndex = LogicalPartitionIndex++; |
| 1053 | Volume->VolName = SWPrintf("Partition %llu", Volume->MbrPartitionIndex + 1); |
| 1054 | Volume->BlockIO = WholeDiskVolume->BlockIO; |
| 1055 | Volume->BlockIOOffset = ExtCurrent + EMbrTable[i].StartLBA; |
| 1056 | Volume->WholeDiskBlockIO = WholeDiskVolume->BlockIO; |
| 1057 | Volume->WholeDiskDeviceHandle = WholeDiskVolume->DeviceHandle; |
| 1058 | |
| 1059 | Bootable = FALSE; |
| 1060 | ScanVolumeBootcode(Volume, &Bootable); |
| 1061 | if (!Bootable) |
| 1062 | Volume->HasBootCode = FALSE; |
| 1063 | |
| 1064 | Volumes.AddReference(Volume, false); |
| 1065 | // AddListElement((VOID ***) &Volumes, &VolumesCount, Volume); |
| 1066 | } |
| 1067 | } |
| 1068 | } |
no test coverage detected