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

Function LinuxScan

rEFIt_UEFI/entry_scan/loader.cpp:1060–1287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1058}
1059
1060STATIC VOID LinuxScan(REFIT_VOLUME *Volume, UINT8 KernelScan, UINT8 Type, XStringW *CustomPath, XIcon *CustomImage)
1061{
1062 // When used for Regular Entries, all found entries will be added by AddLoaderEntry()
1063 // When used for Custom Entries (detected by CustomPath!=NULL), CustomPath+CustomImage will be set to the first entry found and execution will stop
1064 // Scanning is adjusted according to Type: OSTYPE_LIN will scan for linux loaders, OSTYPE_LINEFI will scan for linux kernels, unspecified will scan for both
1065 UINTN Index;
1066 EFI_GUID *PartGUID;
1067
1068 // check for linux loaders
1069 if (Type != OSTYPE_LINEFI) { // OSTYPE_LIN or unspecified
1070 //
1071 //----- Test common linux name and path like /EFI/ubuntu/grubx64.efi
1072 REFIT_DIR_ITER DirIter;
1073 EFI_FILE_INFO *DirEntry = NULL;
1074 DirIterOpen(Volume->RootDir, L"\\EFI", &DirIter);
1075 while (DirIterNext(&DirIter, 1, L"*", &DirEntry)) {
1076 if (DirEntry->FileName[0] == '.') {
1077 //DBG("Skip dot entries: %ls\n", DirEntry->FileName);
1078 continue;
1079 }
1080 XStringW File = SWPrintf("EFI\\%ls\\grubx64.efi", DirEntry->FileName);
1081 XStringW OSName = XStringW().takeValueFrom(DirEntry->FileName); // this is folder name, for example "ubuntu"
1082 OSName.lowerAscii(); // lowercase for icon name and title (first letter in title will be capitalized later)
1083 if (FileExists(Volume->RootDir, File)) {
1084 // check if nonstandard icon mapping is needed
1085 for (Index = 0; Index < LinuxIconMappingCount; ++Index) {
1086 if (StrCmp(OSName.wc_str(),LinuxIconMapping[Index].DirectoryName) == 0) {
1087 OSName = XStringW().takeValueFrom(LinuxIconMapping[Index].IconName);
1088 break;
1089 }
1090 }
1091 if (!CustomPath) {
1092 DBG(" found entry %ls,linux\n", OSName.wc_str());
1093 }
1094 XStringW LoaderTitle = OSName.subString(0,1); // capitalize first letter for title
1095 LoaderTitle.upperAscii();
1096 LoaderTitle += OSName.subString(1, OSName.length()) + L" Linux"_XSW;
1097 // Very few linux icons exist in IconNames, but these few may be preloaded, so check that first
1098 XIcon ImageX = ThemeX.GetIcon(L"os_"_XSW + OSName); //will the image be destroyed or rewritten by next image after the cycle end?
1099 if (ImageX.isEmpty()) {
1100 // no preloaded icon, try to load from dir
1101 ImageX.LoadXImage(ThemeX.ThemeDir, L"os_"_XSW + OSName);
1102 }
1103 if (CustomPath) {
1104 *CustomPath = File;
1105 if (CustomImage) {
1106 *CustomImage = ImageX;
1107 }
1108 DirIterClose(&DirIter);
1109 return;
1110 }
1111 AddLoaderEntry(File, NullXString8Array, L""_XSW, LoaderTitle, Volume, L""_XSW,
1112 (ImageX.isEmpty() ? NULL : &ImageX), OSTYPE_LIN, OSFLAG_NODEFAULTARGS);
1113 } //anyway continue search other entries
1114 }
1115 DirIterClose(&DirIter);
1116
1117 // check for non-standard grub path

Callers 2

ScanLoaderFunction · 0.85
AddCustomEntryFunction · 0.85

Calls 15

DirIterOpenFunction · 0.85
DirIterNextFunction · 0.85
SWPrintfFunction · 0.85
FileExistsFunction · 0.85
DirIterCloseFunction · 0.85
AddLoaderEntryFunction · 0.85
strguidFunction · 0.85
StrToLowerFunction · 0.85
TimeCmpFunction · 0.85
BasenameFunction · 0.85
lowerAsciiMethod · 0.80

Tested by

no test coverage detected