Performs detailed search for Startup Disk or last Clover boot volume * by looking for gEfiAppleBootGuid:efi-boot-device-data and BootCampHD RT vars. * Returns MainMenu entry index or -1 if not found. */
| 1158 | * Returns MainMenu entry index or -1 if not found. |
| 1159 | */ |
| 1160 | INTN |
| 1161 | FindStartupDiskVolume ( |
| 1162 | REFIT_MENU_SCREEN *MainMenu |
| 1163 | ) |
| 1164 | { |
| 1165 | INTN Index; |
| 1166 | // LEGACY_ENTRY *LegacyEntry; |
| 1167 | // LOADER_ENTRY *LoaderEntry; |
| 1168 | // REFIT_VOLUME *Volume; |
| 1169 | REFIT_VOLUME *DiskVolume; |
| 1170 | BOOLEAN IsPartitionVolume; |
| 1171 | XStringW LoaderPath; |
| 1172 | XStringW EfiBootVolumeStr; |
| 1173 | |
| 1174 | |
| 1175 | // DBG("FindStartupDiskVolume ...\n"); |
| 1176 | |
| 1177 | |
| 1178 | // |
| 1179 | // search RT vars for efi-boot-device-data |
| 1180 | // and try to find that volume |
| 1181 | // |
| 1182 | GetEfiBootDeviceFromNvram (); |
| 1183 | if (gEfiBootVolume == NULL) { |
| 1184 | // DBG(" - [!] EfiBootVolume not found\n"); |
| 1185 | return -1; |
| 1186 | } |
| 1187 | |
| 1188 | DbgHeader("FindStartupDiskVolume"); |
| 1189 | // DBG("FindStartupDiskVolume searching ...\n"); |
| 1190 | |
| 1191 | // |
| 1192 | // Check if gEfiBootVolume is disk or partition volume |
| 1193 | // |
| 1194 | EfiBootVolumeStr = FileDevicePathToXStringW(gEfiBootVolume); |
| 1195 | IsPartitionVolume = NULL != FindDevicePathNodeWithType (gEfiBootVolume, MEDIA_DEVICE_PATH, 0); |
| 1196 | DBG(" - Volume: %ls = %ls\n", IsPartitionVolume ? L"partition" : L"disk", EfiBootVolumeStr.wc_str()); |
| 1197 | |
| 1198 | // |
| 1199 | // 1. gEfiBootVolume + gEfiBootLoaderPath |
| 1200 | // PciRoot(0x0)/.../Sata(...)/HD(...)/\EFI\BOOT\XXX.EFI - set by Clover |
| 1201 | // |
| 1202 | if (gEfiBootLoaderPath != NULL) { |
| 1203 | DBG(" - searching for that partition and loader '%ls'\n", gEfiBootLoaderPath); |
| 1204 | for (Index = 0; ((Index < (INTN)MainMenu->Entries.size()) && (MainMenu->Entries[Index].Row == 0)); ++Index) { |
| 1205 | if (MainMenu->Entries[Index].getLOADER_ENTRY()) { |
| 1206 | LOADER_ENTRY& LoaderEntry = *MainMenu->Entries[Index].getLOADER_ENTRY(); |
| 1207 | REFIT_VOLUME* Volume = LoaderEntry.Volume; |
| 1208 | LoaderPath = LoaderEntry.LoaderPath; |
| 1209 | if (Volume != NULL && BootVolumeDevicePathEqual(gEfiBootVolume, Volume->DevicePath)) { |
| 1210 | DBG(" checking '%ls'\n", DevicePathToXStringW(Volume->DevicePath).wc_str()); |
| 1211 | DBG(" '%ls'\n", LoaderPath.wc_str()); |
| 1212 | // case insensitive cmp |
| 1213 | if ( LoaderPath.equalIC(gEfiBootLoaderPath) ) { |
| 1214 | // that's the one |
| 1215 | DBG(" - found entry %lld. '%ls', Volume '%ls', '%ls'\n", Index, LoaderEntry.Title.s(), Volume->VolName.wc_str(), LoaderPath.wc_str()); |
| 1216 | return Index; |
| 1217 | } |
no test coverage detected