From 85f7e52b653f9e618ad57d511ed01db94ae3b2b3 Mon Sep 17 00:00:00 2001 From: srs5694 Date: Mon, 28 May 2012 22:20:53 -0400 Subject: [PATCH] Added "dont_scan_dirs" option to configuration file. --- NEWS.txt | 6 ++++++ docs/refind/todo.html | 5 +++++ refind.conf-sample | 12 ++++++++++++ refind/config.c | 12 +++++++++--- refind/global.h | 1 + refind/lib.c | 19 ++++++++++++++++++- refind/lib.h | 1 + refind/main.c | 30 ++++++++++++++++-------------- 8 files changed, 68 insertions(+), 18 deletions(-) diff --git a/NEWS.txt b/NEWS.txt index 5c89c5e..9b23337 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,3 +1,9 @@ +0.4.2 (?/??/2012): +------------------ + +- Added "dont_scan_dirs" configuration file option, which adds directories + to a "blacklist" of directories that are NOT scanned for boot loaders. + 0.4.1 (5/25/2012): ------------------ diff --git a/docs/refind/todo.html b/docs/refind/todo.html index 952e74e..7e7356b 100644 --- a/docs/refind/todo.html +++ b/docs/refind/todo.html @@ -276,6 +276,11 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com

  • I'd like to give the user the ability to set custom options on a single-boot basis, similar to what's possible in GRUB.
  • +
  • A GUI configuration tool would be nice, but it's low on my personal + priority list. If you'd like to contribute, I prefer something + written in a cross-platform GUI toolkit, so that a single code base + can be used on any of the major OSes.
  • +
  • Improvements to the EFI drivers: diff --git a/refind.conf-sample b/refind.conf-sample index 7e78555..bfdeaa1 100644 --- a/refind.conf-sample +++ b/refind.conf-sample @@ -115,6 +115,18 @@ timeout 20 # #also_scan_dirs boot,EFI/linux/kernels +# Directories that should NOT be scanned for boot loaders. By default, +# rEFInd doesn't scan its own directory or the EFI/tools directory. +# You can "blacklist" additional directories with this option, which +# takes a list of directory names as options. You might do this to +# keep EFI/boot/bootx64.efi out of the menu if that's a duplicate of +# another boot loader or to exclude a directory that holds drivers +# or non-bootloader utilities provided by a hardware manufacturer. If +# a directory is listed both here and in also_scan_dirs, dont_scan_dirs +# takes precedence. +# +#dont_scan_dirs EFI/boot,EFI/Dell + # Scan for Linux kernels that lack a ".efi" filename extension. This is # useful for better integration with Linux distributions that provide # kernels with EFI stub loaders but that don't give those kernels filenames diff --git a/refind/config.c b/refind/config.c index 7e99dcf..63b0a22 100644 --- a/refind/config.c +++ b/refind/config.c @@ -284,7 +284,8 @@ static VOID HandleString(IN CHAR16 **TokenList, IN UINTN TokenCount, OUT CHAR16 } // static VOID HandleString() // Handle a parameter with a series of string arguments, to be added to a comma-delimited -// list +// list. Passes each token through the CleanUpPathNameSlashes() function to ensure +// consistency in subsequent comparisons of filenames. static VOID HandleStrings(IN CHAR16 **TokenList, IN UINTN TokenCount, OUT CHAR16 **Target) { UINTN i; @@ -292,8 +293,10 @@ static VOID HandleStrings(IN CHAR16 **TokenList, IN UINTN TokenCount, OUT CHAR16 FreePool(*Target); *Target = NULL; } // if - for (i = 1; i < TokenCount; i++) - MergeStrings(Target, TokenList[i], L','); + for (i = 1; i < TokenCount; i++) { + CleanUpPathNameSlashes(TokenList[i]); + MergeStrings(Target, TokenList[i], L','); + } } // static VOID HandleStrings() // read config file @@ -356,6 +359,9 @@ VOID ReadConfig(VOID) } else if (StriCmp(TokenList[0], L"also_scan_dirs") == 0) { HandleStrings(TokenList, TokenCount, &(GlobalConfig.AlsoScan)); + } else if ((StriCmp(TokenList[0], L"don't_scan_dirs") == 0) || (StriCmp(TokenList[0], L"dont_scan_dirs") == 0)) { + HandleStrings(TokenList, TokenCount, &(GlobalConfig.DontScan)); + } else if (StriCmp(TokenList[0], L"scan_driver_dirs") == 0) { HandleStrings(TokenList, TokenCount, &(GlobalConfig.DriverDirs)); diff --git a/refind/global.h b/refind/global.h index 678054b..b2b38b8 100644 --- a/refind/global.h +++ b/refind/global.h @@ -164,6 +164,7 @@ typedef struct { CHAR16 *SelectionBigFileName; CHAR16 *DefaultSelection; CHAR16 *AlsoScan; + CHAR16 *DontScan; CHAR16 *DriverDirs; CHAR16 *IconsDir; UINTN ShowTools[NUM_TOOLS]; diff --git a/refind/lib.c b/refind/lib.c index be95e0c..71f76c5 100644 --- a/refind/lib.c +++ b/refind/lib.c @@ -1200,7 +1200,8 @@ CHAR16 *FindLastDirName(IN CHAR16 *Path) { // Returns the directory portion of a pathname. For instance, // if FullPath is 'EFI\foo\bar.efi', this function returns the -// string 'EFI\foo'. +// string 'EFI\foo'. The calling function is responsible for +// freeing the returned string's memory. CHAR16 *FindPath(IN CHAR16* FullPath) { UINTN i, LastBackslash = 0; CHAR16 *PathOnly; @@ -1278,6 +1279,22 @@ CHAR16 *FindCommaDelimited(IN CHAR16 *InString, IN UINTN Index) { return (FoundString); } // CHAR16 *FindCommaDelimited() +// Returns TRUE if SmallString is an element in the comma-delimited List, +// FALSE otherwise. Performs comparison case-insensitively (except on +// buggy EFIs with case-sensitive StriCmp() functions). +BOOLEAN IsIn(IN CHAR16 *SmallString, IN CHAR16 *List) { + UINTN i = 0; + BOOLEAN Found = FALSE; + CHAR16 *OneElement; + + if (SmallString && List) { + while (!Found && (OneElement = FindCommaDelimited(List, i++))) { + if (StriCmp(OneElement, SmallString) == 0) + Found = TRUE; + } // while + } // if + return Found; +} // BOOLEAN IsIn() static EFI_GUID AppleRemovableMediaGuid = APPLE_REMOVABLE_MEDIA_PROTOCOL_GUID; diff --git a/refind/lib.h b/refind/lib.h index f7e9eda..17af8bd 100644 --- a/refind/lib.h +++ b/refind/lib.h @@ -104,6 +104,7 @@ CHAR16 *FindLastDirName(IN CHAR16 *Path); CHAR16 *FindPath(IN CHAR16* FullPath); CHAR16 *FindNumbers(IN CHAR16 *InString); CHAR16 *FindCommaDelimited(IN CHAR16 *InString, IN UINTN Index); +BOOLEAN IsIn(IN CHAR16 *SmallString, IN CHAR16 *List); BOOLEAN EjectMedia(VOID); diff --git a/refind/main.c b/refind/main.c index 1e4dfd1..66d51ff 100644 --- a/refind/main.c +++ b/refind/main.c @@ -87,7 +87,7 @@ static REFIT_MENU_ENTRY MenuEntryExit = { L"Exit rEFInd", TAG_EXIT, 1, 0, 0, static REFIT_MENU_SCREEN MainMenu = { L"Main Menu", NULL, 0, NULL, 0, NULL, 0, L"Automatic boot" }; static REFIT_MENU_SCREEN AboutMenu = { L"About", NULL, 0, NULL, 0, NULL, 0, NULL }; -REFIT_CONFIG GlobalConfig = { FALSE, FALSE, 0, 0, 20, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +REFIT_CONFIG GlobalConfig = { FALSE, FALSE, 0, 0, 20, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, {TAG_SHELL, TAG_ABOUT, TAG_SHUTDOWN, TAG_REBOOT, 0, 0, 0, 0, 0 }}; // Structure used to hold boot loader filenames and time stamps in @@ -106,7 +106,7 @@ static VOID AboutrEFInd(VOID) { if (AboutMenu.EntryCount == 0) { AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT); - AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.4.1"); + AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.4.1.1"); AddMenuInfoLine(&AboutMenu, L""); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer"); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012 Roderick W. Smith"); @@ -787,8 +787,8 @@ static VOID ScanLoaderDir(IN REFIT_VOLUME *Volume, IN CHAR16 *Path, IN CHAR16 *P CHAR16 FileName[256], *Extension; struct LOADER_LIST *LoaderList = NULL, *NewLoader; - if (!SelfDirPath || !Path || ((StriCmp(Path, SelfDirPath) == 0) && Volume->DeviceHandle != SelfVolume->DeviceHandle) || - (StriCmp(Path, SelfDirPath) != 0)) { + if ((!SelfDirPath || !Path || ((StriCmp(Path, SelfDirPath) == 0) && Volume->DeviceHandle != SelfVolume->DeviceHandle) || + (StriCmp(Path, SelfDirPath) != 0)) && (!IsIn(Path, GlobalConfig.DontScan))) { // look through contents of the directory DirIterOpen(Volume->RootDir, Path, &DirIter); while (DirIterNext(&DirIter, 2, Pattern, &DirEntry)) { @@ -844,20 +844,22 @@ static VOID ScanEfiFiles(REFIT_VOLUME *Volume) { if ((Volume->RootDir != NULL) && (Volume->VolName != NULL)) { // check for Mac OS X boot loader - StrCpy(FileName, MACOSX_LOADER_PATH); - if (FileExists(Volume->RootDir, FileName)) { - AddLoaderEntry(FileName, L"Mac OS X", Volume); - } + if (!IsIn(L"System\\Library\\CoreServices", GlobalConfig.DontScan)) { + StrCpy(FileName, MACOSX_LOADER_PATH); + if (FileExists(Volume->RootDir, FileName)) { + AddLoaderEntry(FileName, L"Mac OS X", Volume); + } - // check for XOM - StrCpy(FileName, L"System\\Library\\CoreServices\\xom.efi"); - if (FileExists(Volume->RootDir, FileName)) { - AddLoaderEntry(FileName, L"Windows XP (XoM)", Volume); - } + // check for XOM + StrCpy(FileName, L"System\\Library\\CoreServices\\xom.efi"); + if (FileExists(Volume->RootDir, FileName)) { + AddLoaderEntry(FileName, L"Windows XP (XoM)", Volume); + } + } // if Mac directory not in GlobalConfig.DontScan list // check for Microsoft boot loader/menu StrCpy(FileName, L"EFI\\Microsoft\\Boot\\Bootmgfw.efi"); - if (FileExists(Volume->RootDir, FileName)) { + if (FileExists(Volume->RootDir, FileName) && !IsIn(L"EFI\\Microsoft\\Boot", GlobalConfig.DontScan)) { AddLoaderEntry(FileName, L"Microsoft EFI boot", Volume); } -- 2.39.2