]> code.delx.au - refind/blobdiff - refind/main.c
Limit length of firmware description string in Info screen, to avoid
[refind] / refind / main.c
index 4f0b0b7fb6d187e4e67b68673900259ddf404007..dcbb1fdead5f654eb49ccba13454541f6250d79d 100644 (file)
@@ -49,6 +49,7 @@
 #include "icns.h"
 #include "menu.h"
 #include "mok.h"
+#include "gpt.h"
 #include "security_policy.h"
 #include "../include/Handle.h"
 #include "../include/refit_call_wrapper.h"
@@ -143,6 +144,8 @@ REFIT_CONFIG GlobalConfig = { FALSE, FALSE, 0, 0, 0, DONT_CHANGE_TEXT_MODE, 20,
 
 EFI_GUID GlobalGuid = EFI_GLOBAL_VARIABLE;
 
+GPT_DATA *gPartitions = NULL;
+
 // Structure used to hold boot loader filenames and time stamps in
 // a linked list; used to sort entries within a directory.
 struct LOADER_LIST {
@@ -157,9 +160,11 @@ struct LOADER_LIST {
 
 static VOID AboutrEFInd(VOID)
 {
+    CHAR16 *FirmwareVendor;
+
     if (AboutMenu.EntryCount == 0) {
         AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
-        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.7.8.4");
+        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.7.9.5");
         AddMenuInfoLine(&AboutMenu, L"");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012-2014 Roderick W. Smith");
@@ -176,7 +181,9 @@ static VOID AboutrEFInd(VOID)
 #else
         AddMenuInfoLine(&AboutMenu, L" Platform: unknown");
 #endif
-        AddMenuInfoLine(&AboutMenu, PoolPrint(L" Firmware: %s %d.%02d", ST->FirmwareVendor, ST->FirmwareRevision >> 16,
+        FirmwareVendor = StrDuplicate(ST->FirmwareVendor);
+        LimitStringLength(FirmwareVendor, 65); // More than ~65 causes empty info page on 800x600 display
+        AddMenuInfoLine(&AboutMenu, PoolPrint(L" Firmware: %s %d.%02d", FirmwareVendor, ST->FirmwareRevision >> 16,
                                               ST->FirmwareRevision & ((1 << 16) - 1)));
         AddMenuInfoLine(&AboutMenu, PoolPrint(L" Screen Output: %s", egScreenDescription()));
         AddMenuInfoLine(&AboutMenu, L"");
@@ -1091,7 +1098,7 @@ static BOOLEAN ShouldScan(REFIT_VOLUME *Volume, CHAR16 *Path) {
    UINTN    i = 0;
    BOOLEAN  ScanIt = TRUE;
 
-   if (IsIn(Volume->VolName, GlobalConfig.DontScanVolumes))
+   if ((IsIn(Volume->VolName, GlobalConfig.DontScanVolumes)) || (IsIn(Volume->PartName, GlobalConfig.DontScanVolumes)))
       return FALSE;
 
    if ((StriCmp(Path, SelfDirPath) == 0) && (Volume->DeviceHandle == SelfVolume->DeviceHandle))
@@ -1110,7 +1117,7 @@ static BOOLEAN ShouldScan(REFIT_VOLUME *Volume, CHAR16 *Path) {
    VolName = NULL;
 
    // See if Volume is in GlobalConfig.DontScanDirs....
-   while ((DontScanDir = FindCommaDelimited(GlobalConfig.DontScanDirs, i++)) && ScanIt) {
+   while (ScanIt && (DontScanDir = FindCommaDelimited(GlobalConfig.DontScanDirs, i++))) {
       SplitVolumeAndFilename(&DontScanDir, &VolName);
       CleanUpPathNameSlashes(DontScanDir);
       VolumeNumberToName(Volume, &VolName);
@@ -1124,6 +1131,7 @@ static BOOLEAN ShouldScan(REFIT_VOLUME *Volume, CHAR16 *Path) {
       MyFreePool(DontScanDir);
       MyFreePool(VolName);
       DontScanDir = NULL;
+      VolName = NULL;
    } // while()
 
    return ScanIt;
@@ -1224,6 +1232,26 @@ static BOOLEAN IsSymbolicLink(REFIT_VOLUME *Volume, CHAR16 *Path, EFI_FILE_INFO
    return (DirEntry->FileSize != FileSize2);
 } // BOOLEAN IsSymbolicLink()
 
+// Returns TRUE if a file with the same name as the original but with
+// ".efi.signed" is also present in the same directory. Ubuntu is using
+// this filename as a signed version of the original unsigned kernel, and
+// there's no point in cluttering the display with two kernels that will
+// behave identically on non-SB systems, or when one will fail when SB
+// is active.
+static BOOLEAN HasSignedCounterpart(IN REFIT_VOLUME *Volume, IN CHAR16 *Path, IN CHAR16 *Filename) {
+   CHAR16 *NewFile = NULL;
+   BOOLEAN retval = FALSE;
+
+   MergeStrings(&NewFile, Path, 0);
+   MergeStrings(&NewFile, Filename, L'\\');
+   MergeStrings(&NewFile, L".efi.signed", 0);
+   if (FileExists(Volume->RootDir, NewFile))
+      retval = TRUE;
+   MyFreePool(NewFile);
+
+   return retval;
+} // BOOLEAN HasSignedCounterpart()
+
 // Scan an individual directory for EFI boot loader files and, if found,
 // add them to the list. Exception: Ignores FALLBACK_FULLNAME, which is picked
 // up in ScanEfiFiles(). Sorts the entries within the loader directory so that
@@ -1251,6 +1279,7 @@ static BOOLEAN ScanLoaderDir(IN REFIT_VOLUME *Volume, IN CHAR16 *Path, IN CHAR16
               (StriCmp(DirEntry->FileName, FALLBACK_BASENAME) == 0 && (StriCmp(Path, L"EFI\\BOOT") == 0)) ||
               StriSubCmp(L"shell", DirEntry->FileName) ||
               IsSymbolicLink(Volume, Path, DirEntry) || /* is symbolic link */
+              HasSignedCounterpart(Volume, Path, DirEntry->FileName) || /* a file with same name plus ".efi.signed" is present */
               FilenameIn(Volume, Path, DirEntry->FileName, GlobalConfig.DontScanFiles))
                 continue;   // skip this
 
@@ -1307,11 +1336,11 @@ static VOID ScanEfiFiles(REFIT_VOLUME *Volume) {
    BOOLEAN                 ScanFallbackLoader = TRUE;
    BOOLEAN                 FoundBRBackup = FALSE;
 
-   MatchPatterns = StrDuplicate(LOADER_MATCH_PATTERNS);
-   if (GlobalConfig.ScanAllLinux)
-      MergeStrings(&MatchPatterns, LINUX_MATCH_PATTERNS, L',');
-
    if ((Volume->RootDir != NULL) && (Volume->VolName != NULL) && (Volume->IsReadable)) {
+      MatchPatterns = StrDuplicate(LOADER_MATCH_PATTERNS);
+      if (GlobalConfig.ScanAllLinux)
+         MergeStrings(&MatchPatterns, LINUX_MATCH_PATTERNS, L',');
+
       // check for Mac OS X boot loader
       if (ShouldScan(Volume, L"System\\Library\\CoreServices")) {
          StrCpy(FileName, MACOSX_LOADER_PATH);
@@ -1333,7 +1362,8 @@ static VOID ScanEfiFiles(REFIT_VOLUME *Volume) {
       // check for Microsoft boot loader/menu
       if (ShouldScan(Volume, L"EFI\\Microsoft\\Boot")) {
          StrCpy(FileName, L"EFI\\Microsoft\\Boot\\bkpbootmgfw.efi");
-         if (FileExists(Volume->RootDir, FileName) &&  !FilenameIn(Volume, Directory, L"bkpbootmgfw.efi", GlobalConfig.DontScanFiles)) {
+         if (FileExists(Volume->RootDir, FileName) &&  !FilenameIn(Volume, Directory, L"bkpbootmgfw.efi",
+             GlobalConfig.DontScanFiles)) {
             AddLoaderEntry(FileName, L"Microsoft EFI boot (Boot Repair backup)", Volume);
             FoundBRBackup = TRUE;
             if (DuplicatesFallback(Volume, FileName))
@@ -2165,7 +2195,7 @@ static VOID ScanForBootloaders(VOID) {
 //       PauseForKey();
 //    }
 
-   ScanVolumes();
+//   ScanVolumes();
 
    // scan for loaders and tools, add them to the menu
    for (i = 0; i < NUM_SCAN_OPTIONS; i++) {
@@ -2486,7 +2516,7 @@ efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
        CopyMem(GlobalConfig.ScanFor, "ihebocm   ", NUM_SCAN_OPTIONS);
     SetConfigFilename(ImageHandle);
     ReadConfig(GlobalConfig.ConfigFilename);
-    ScanVolumes();
+//    ScanVolumes();
 
     InitScreen();
     WarnIfLegacyProblems();
@@ -2498,6 +2528,7 @@ efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     // further bootstrap (now with config available)
     MokProtocol = SecureBootSetup();
     LoadDrivers();
+    ScanVolumes();
     ScanForBootloaders();
     ScanForTools();
     SetupScreen();
@@ -2521,6 +2552,7 @@ efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
         // The Escape key triggers a re-scan operation....
         if (MenuExit == MENU_EXIT_ESCAPE) {
+            MenuExit = 0;
             RescanAll();
             continue;
         }