From 83d9696df1452690a2a7cb2c17208feaee3e411f Mon Sep 17 00:00:00 2001 From: srs5694 Date: Fri, 1 Feb 2013 11:34:45 -0500 Subject: [PATCH] Fine-tuning of loader detection code. --- NEWS.txt | 8 ++++++++ docs/refind/configfile.html | 2 +- libeg/image.c | 2 +- mok/guid.c | 1 - refind.conf-sample | 2 +- refind.inf | 1 + refind.spec | 2 +- refind/config.c | 3 ++- refind/config.h | 1 + refind/lib.c | 4 +--- refind/lib.h | 1 - refind/main.c | 33 +++++++++++++++------------------ 12 files changed, 32 insertions(+), 28 deletions(-) diff --git a/NEWS.txt b/NEWS.txt index f2d1578..a493913 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,6 +1,14 @@ 0.6.7 (?/??/2013): ------------------ +- Fixed bug that caused rEFInd to present an entry for itself as a + Microsoft OS if it was launched as EFI/Microsoft/Boot/bootmgfw.efi. + +- Fixed bug that caused dont_scan_volumes option to be added to + also_scan_dirst list. + +- Fixed dont_scan_volumes so that it works with OS X boot loaders. + - Fixed broken mixing of PNG and ICNS icons when using a user-specified icons directory -- previously, an ICNS file in the default directory would override a PNG file in the user-specified directory. diff --git a/docs/refind/configfile.html b/docs/refind/configfile.html index 4a05a9d..f6358ab 100644 --- a/docs/refind/configfile.html +++ b/docs/refind/configfile.html @@ -251,7 +251,7 @@ timeout 20 dont_scan_volumes or don't_scan_volumes filesystem label(s) - Adds the specified volume or volumes to a volume "blacklist"—these filesystems are not scanned for EFI boot loaders. This may be useful to keep unwanted EFI boot entries, such as for a Macintosh recovery partition, from appearing on the main list of boot loaders. + Adds the specified volume or volumes to a volume "blacklist"—these filesystems are not scanned for EFI boot loaders. This may be useful to keep unwanted EFI boot entries, such as for a Macintosh recovery partition, from appearing on the main list of boot loaders. The default value is Recovery HD, to keep the Mac recovery volume from appearing. (It should get its own tools icon instead—see the showtools token.) dont_scan_dirs or don't_scan_dirs diff --git a/libeg/image.c b/libeg/image.c index a688bdf..88829a5 100644 --- a/libeg/image.c +++ b/libeg/image.c @@ -204,7 +204,7 @@ EFI_STATUS egSaveFile(IN EFI_FILE* BaseDir OPTIONAL, IN CHAR16 *FileName, } Status = refit_call5_wrapper(BaseDir->Open, BaseDir, &FileHandle, FileName, - EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0); + EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0); if (EFI_ERROR(Status)) return Status; diff --git a/mok/guid.c b/mok/guid.c index b0e430f..155b8ed 100644 --- a/mok/guid.c +++ b/mok/guid.c @@ -6,7 +6,6 @@ #include "global.h" #include "guid.h" -#include // #ifndef BUILD_EFI // /* EFI has %g for this, so it's only needed in platform c */ diff --git a/refind.conf-sample b/refind.conf-sample index b7ccc2e..d96a1b8 100644 --- a/refind.conf-sample +++ b/refind.conf-sample @@ -195,7 +195,7 @@ timeout 20 # label, which you can obtain in an EFI shell by typing "vol", from # Linux by typing "blkid /dev/{devicename}", or by examining the # disk's label in various OSes' file browsers. -# The default is an empty list (all volumes are scanned). +# The default is "Recovery HD". # #dont_scan_volumes "Recovery HD" diff --git a/refind.inf b/refind.inf index e8e9d47..8619ec4 100644 --- a/refind.inf +++ b/refind.inf @@ -47,6 +47,7 @@ libeg/image.c libeg/load_bmp.c libeg/load_icns.c + libeg/lodepng.c libeg/screen.c libeg/text.c diff --git a/refind.spec b/refind.spec index 429e22b..d666622 100644 --- a/refind.spec +++ b/refind.spec @@ -1,6 +1,6 @@ Summary: EFI boot manager software Name: refind -Version: 0.6.6.6 +Version: 0.6.6.7 Release: 1%{?dist} Summary: EFI boot manager software License: GPLv3 diff --git a/refind/config.c b/refind/config.c index cc0a931..92ef5a6 100644 --- a/refind/config.c +++ b/refind/config.c @@ -361,6 +361,8 @@ VOID ReadConfig(CHAR16 *FileName) GlobalConfig.DontScanDirs = SelfPath; MyFreePool(GlobalConfig.DontScanFiles); GlobalConfig.DontScanFiles = StrDuplicate(DONT_SCAN_FILES); + MyFreePool(GlobalConfig.DontScanVolumes); + GlobalConfig.DontScanVolumes = StrDuplicate(DONT_SCAN_VOLUMES); } // if if (!FileExists(SelfDir, FileName)) { @@ -424,7 +426,6 @@ VOID ReadConfig(CHAR16 *FileName) HandleStrings(TokenList, TokenCount, &(GlobalConfig.AlsoScan)); } else if ((StriCmp(TokenList[0], L"don't_scan_volumes") == 0) || (StriCmp(TokenList[0], L"dont_scan_volumes") == 0)) { - HandleStrings(TokenList, TokenCount, &(GlobalConfig.AlsoScan)); // Note: Don't use HandleStrings() because it modifies slashes, which might be present in volume name MyFreePool(GlobalConfig.DontScanVolumes); GlobalConfig.DontScanVolumes = NULL; diff --git a/refind/config.h b/refind/config.h index 79acf21..a91b52f 100644 --- a/refind/config.h +++ b/refind/config.h @@ -80,6 +80,7 @@ typedef struct { #define CONFIG_FILE_NAME L"refind.conf" #define DONT_SCAN_FILES L"shim.efi,MokManager.efi,TextMode.efi,ebounce.efi,GraphicsConsole.efi" +#define DONT_SCAN_VOLUMES L"Recovery HD" #define ALSO_SCAN_DIRS L"boot" EFI_STATUS ReadFile(IN EFI_FILE_HANDLE BaseDir, CHAR16 *FileName, REFIT_FILE *File, UINTN *size); diff --git a/refind/lib.c b/refind/lib.c index bf2c2ef..66dbe00 100644 --- a/refind/lib.c +++ b/refind/lib.c @@ -48,6 +48,7 @@ #include "screen.h" #include "../include/refit_call_wrapper.h" #include "../include/RemovableMedia.h" +//#include "../include/UsbMass.h" #ifdef __MAKEWITH_GNUEFI #define EfiReallocatePool ReallocatePool @@ -92,9 +93,6 @@ UINTN VolumesCount = 0; // and identify its boot loader, and hence probable BIOS-mode OS installation #define SAMPLE_SIZE 69632 /* 68 KiB -- ReiserFS superblock begins at 64 KiB */ -// Default names for volume badges (mini-icon to define disk type) and icons -#define VOLUME_BADGE_NAMES L".VolumeBadge.icns,.VolumeBadge.png" -#define VOLUME_ICON_NAMES L".VolumeIcon.icns,.VolumeIcon.png" // functions diff --git a/refind/lib.h b/refind/lib.h index 4004c45..d0a4022 100644 --- a/refind/lib.h +++ b/refind/lib.h @@ -73,7 +73,6 @@ typedef struct { #define DISK_KIND_EXTERNAL (1) #define DISK_KIND_OPTICAL (2) -#define VOL_DONTSCAN 998 #define VOL_UNREADABLE 999 #define IS_EXTENDED_PART_TYPE(type) ((type) == 0x05 || (type) == 0x0f || (type) == 0x85) diff --git a/refind/main.c b/refind/main.c index fc5d062..ecb0825 100644 --- a/refind/main.c +++ b/refind/main.c @@ -134,7 +134,7 @@ static VOID AboutrEFInd(VOID) if (AboutMenu.EntryCount == 0) { AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT); - AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.6.6.6"); + AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.6.6.7"); AddMenuInfoLine(&AboutMenu, L""); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer"); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012 Roderick W. Smith"); @@ -904,9 +904,9 @@ static VOID CleanUpLoaderList(struct LOADER_LIST *LoaderList) { // Returns FALSE if the specified file/volume matches the GlobalConfig.DontScanDirs // or GlobalConfig.DontScanVolumes specification, or if Path points to a volume -// other than the one specified by Volume. Returns TRUE if none of these conditions -// is met -- that is, if the path is eligible for scanning. Also reduces *Path to a -// path alone, with no volume specification. +// other than the one specified by Volume, or if the specified path is SelfDir. +// Returns TRUE if none of these conditions is met -- that is, if the path is +// eligible for scanning. static BOOLEAN ShouldScan(REFIT_VOLUME *Volume, CHAR16 *Path) { CHAR16 *VolName = NULL, *DontScanDir; UINTN i = 0, VolNum; @@ -915,6 +915,9 @@ static BOOLEAN ShouldScan(REFIT_VOLUME *Volume, CHAR16 *Path) { if (IsIn(Volume->VolName, GlobalConfig.DontScanVolumes)) return FALSE; + if ((StriCmp(Path, SelfDirPath) == 0) && (Volume->DeviceHandle == SelfVolume->DeviceHandle)) + return FALSE; + while ((DontScanDir = FindCommaDelimited(GlobalConfig.DontScanDirs, i++)) && ScanIt) { SplitVolumeAndFilename(&DontScanDir, &VolName); CleanUpPathNameSlashes(DontScanDir); @@ -941,7 +944,7 @@ static BOOLEAN ShouldScan(REFIT_VOLUME *Volume, CHAR16 *Path) { // FALSE if the file is not identical to the fallback file OR if the file // IS the fallback file. Intended for use in excluding the fallback boot // loader when it's a duplicate of another boot loader. -BOOLEAN DuplicatesFallback(IN REFIT_VOLUME *Volume, IN CHAR16 *FileName) { +static BOOLEAN DuplicatesFallback(IN REFIT_VOLUME *Volume, IN CHAR16 *FileName) { CHAR8 *FileContents, *FallbackContents; EFI_FILE_HANDLE FileHandle, FallbackHandle; EFI_FILE_INFO *FileInfo, *FallbackInfo; @@ -1062,7 +1065,7 @@ static VOID ScanEfiFiles(REFIT_VOLUME *Volume) { REFIT_DIR_ITER EfiDirIter; EFI_FILE_INFO *EfiDirEntry; CHAR16 FileName[256], *Directory, *MatchPatterns, *VolName = NULL; - UINTN i, Length, VolNum; + UINTN i, Length; BOOLEAN ScanFallbackLoader = TRUE; // Print(L"Entering ScanEfiFiles(), GlobalConfig.ScanAllLinux = %s\n", GlobalConfig.ScanAllLinux ? L"TRUE" : L"FALSE"); @@ -1073,7 +1076,7 @@ static VOID ScanEfiFiles(REFIT_VOLUME *Volume) { if ((Volume->RootDir != NULL) && (Volume->VolName != NULL)) { // check for Mac OS X boot loader - if (!IsIn(L"System\\Library\\CoreServices", GlobalConfig.DontScanDirs)) { + if (ShouldScan(Volume, L"System\\Library\\CoreServices")) { StrCpy(FileName, MACOSX_LOADER_PATH); if (FileExists(Volume->RootDir, FileName) && !IsIn(L"boot.efi", GlobalConfig.DontScanFiles)) { AddLoaderEntry(FileName, L"Mac OS X", Volume); @@ -1088,11 +1091,11 @@ static VOID ScanEfiFiles(REFIT_VOLUME *Volume) { if (DuplicatesFallback(Volume, FileName)) ScanFallbackLoader = FALSE; } - } // if Mac directory not in GlobalConfig.DontScanDirs list + } // if should scan Mac directory // check for Microsoft boot loader/menu StrCpy(FileName, L"EFI\\Microsoft\\Boot\\Bootmgfw.efi"); - if (FileExists(Volume->RootDir, FileName) && !IsIn(L"EFI\\Microsoft\\Boot", GlobalConfig.DontScanDirs) && + if (FileExists(Volume->RootDir, FileName) && ShouldScan(Volume, L"EFI\\Microsoft\\Boot") && !IsIn(L"bootmgfw.efi", GlobalConfig.DontScanFiles)) { AddLoaderEntry(FileName, L"Microsoft EFI boot", Volume); if (DuplicatesFallback(Volume, FileName)) @@ -1119,24 +1122,18 @@ static VOID ScanEfiFiles(REFIT_VOLUME *Volume) { // Scan user-specified (or additional default) directories.... i = 0; while ((Directory = FindCommaDelimited(GlobalConfig.AlsoScan, i++)) != NULL) { - VolNum = VOL_DONTSCAN; SplitVolumeAndFilename(&Directory, &VolName); CleanUpPathNameSlashes(Directory); Length = StrLen(Directory); - if (VolName && (Length > 0) && (StrLen(VolName) > 2) && (VolName[0] == L'f') && (VolName[1] == L's') && - (VolName[2] >= L'0') && (VolName[2] <= L'9')) - VolNum = Atoi(VolName + 2); - if ((Length > 0) && ((VolName == NULL) || (StriCmp(VolName, Volume->VolName) == 0) || (Volume->VolNumber == VolNum))) - if (ScanLoaderDir(Volume, Directory, MatchPatterns)) - ScanFallbackLoader = FALSE; + if ((Length > 0) && ScanLoaderDir(Volume, Directory, MatchPatterns)) + ScanFallbackLoader = FALSE; MyFreePool(Directory); MyFreePool(VolName); } // while // If not a duplicate & if it exists & if it's not us, create an entry // for the fallback boot loader - if (ScanFallbackLoader && FileExists(Volume->RootDir, FALLBACK_FULLNAME) && - ((StriCmp(SelfDirPath, L"EFI\\BOOT") != 0) || (Volume->DeviceHandle != SelfVolume->DeviceHandle))) { + if (ScanFallbackLoader && FileExists(Volume->RootDir, FALLBACK_FULLNAME) && ShouldScan(Volume, L"EFI\\BOOT")) { AddLoaderEntry(FALLBACK_FULLNAME, L"Fallback boot loader", Volume); } } // if -- 2.39.2