From 34d525d050a59927fce87dbce5af4bd47c8fbe52 Mon Sep 17 00:00:00 2001 From: srs5694 Date: Wed, 19 Dec 2012 23:23:37 -0500 Subject: [PATCH] Misc. bug fixes & minor code improvements --- NEWS.txt | 12 +++++------ docs/refind/configfile.html | 12 +++++++---- libeg/screen.c | 1 + refind/lib.c | 33 ++++++++++++++++------------- refind/main.c | 42 ++++++++++++++++++++++--------------- 5 files changed, 59 insertions(+), 41 deletions(-) diff --git a/NEWS.txt b/NEWS.txt index 5bfd5c0..e249ef8 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,12 +1,12 @@ 0.6.1 (12/??/2012): ------------------- -- Added the filesystem's label (up to the first space, dash, or underscore, - if present) as a search base for a menu icon. For instance, if the - filesystem is called "Arch", rEFInd will try to find an icon called - os_Arch.icns; if it's called "Mac boot", rEFInd will try to use - os_Mac.icns; and if it's "suse_root", rEFInd will search for - os_suse.icns. +- Added the "words" that make up a filesystem's label (delimited by spaces, + dashes, or underscores) to the list of bases used to search for OS icons. + For instance, if the filesystem's label is "Arch", rEFInd searches for + os_Arch.icns; if it's "Fedora 17", it searches for os_Fedora.icns and + os_17.icns; and if it's "NEW_GENTOO", it searches for os_NEW.icns and + os_GENTOO.icns. - Refined hints displays to be more context-sensitive, particularly in text mode. diff --git a/docs/refind/configfile.html b/docs/refind/configfile.html index 6b6ce6c..2f33216 100644 --- a/docs/refind/configfile.html +++ b/docs/refind/configfile.html @@ -104,21 +104,25 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com

Another way to hide a boot loader is to move it into rEFInd's own directory. In order to keep rEFInd from showing up in its own menu, it ignores boot loaders in its own directory. This obviously includes the rEFInd binary file itself, but also anything else you might store there.

-

In addition to hiding boot loaders, you can adjust their icons. You can do this in any of three ways for auto-detected boot loaders:

+

In addition to hiding boot loaders, you can adjust their icons. You can do this in any of five ways for auto-detected boot loaders:

-

As a special case, rEFInd assigns icons to the Windows and OS X boot loaders based on their conventional locations, so they get suitable icons even though they don't follow these rules.

+

As a special case, rEFInd assigns icons to the Windows and OS X boot loaders based on their conventional locations, so they get suitable icons even if they don't follow these rules.

-

In addition to the main OS tag icon, you can set the badge icon for a volume by creating a file called .VolumeBadge.icns in the root directory of a partition. This icon file must include a 32x32 bitmap. If present, it replaces the disk-type icons that are overlaid on the main OS icon. If you use this feature, the badge is applied to all the boot loaders read from the disk, not just those stored in the root directory or the Apple boot loader location. You could use this feature to set a custom badge for different specific disks or to help differentiate multiple OS X installations on one computer.

+

In addition to the main OS tag icon, you can set the badge icon for a volume by creating a file called .VolumeBadge.icns in the root directory of a partition. This icon file must include a 32x32 bitmap. If present, it replaces the disk-type icons that are overlaid on the main OS icon. If you use this feature, the badge is applied to all the boot loaders read from the disk, not just those stored in the root directory or the Apple boot loader location. You could use this feature to set a custom badge for different specific disks or to help differentiate multiple OS X installations on one computer. If you don't want any badges, you can replace the three badge icons in the rEFInd icons subdirectory (vol_external.icns, vol_internal.icns, and vol_optical.icns) with a completely transparent badge. The transparent.icns file in the rEFInd icons directory may be used for this purpose.

Adjusting the Global Configuration

diff --git a/libeg/screen.c b/libeg/screen.c index bac1f00..e4f585a 100644 --- a/libeg/screen.c +++ b/libeg/screen.c @@ -217,6 +217,7 @@ UINT32 egSetTextMode(UINT32 RequestedMode) { EFI_STATUS Status; if (RequestedMode != ST->ConOut->Mode->Mode) { + SwitchToGraphics(); Status = refit_call2_wrapper(ST->ConOut->SetMode, ST->ConOut, RequestedMode); if (Status == EFI_SUCCESS) { UsedMode = RequestedMode; diff --git a/refind/lib.c b/refind/lib.c index 347a176..958bb52 100644 --- a/refind/lib.c +++ b/refind/lib.c @@ -469,7 +469,7 @@ static UINT32 IdentifyFilesystemType(IN UINT8 *Buffer, IN UINTN BufferSize) { return FoundType; } -static VOID ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT BOOLEAN *Bootable) +static VOID ScanVolumeBootcode(REFIT_VOLUME *Volume, BOOLEAN *Bootable) { EFI_STATUS Status; UINT8 Buffer[SAMPLE_SIZE]; @@ -624,7 +624,7 @@ static VOID ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT BOOLEAN *Bootabl CheckError(Status, L"while reading boot sector"); #endif } -} +} /* VOID ScanVolumeBootcode() */ // default volume badge icon based on disk kind static VOID ScanVolumeDefaultIcon(IN OUT REFIT_VOLUME *Volume) @@ -645,17 +645,18 @@ static VOID ScanVolumeDefaultIcon(IN OUT REFIT_VOLUME *Volume) // Return a string representing the input size in IEEE-1541 units. // The calling function is responsible for freeing the allocated memory. static CHAR16 *SizeInIEEEUnits(UINT64 SizeInBytes) { - float SizeInIeee; - UINTN Index = 0; + UINT64 SizeInIeee; + UINTN Index = 0, NumPrefixes; CHAR16 *Units, *Prefixes = L" KMGTPEZ"; CHAR16 *TheValue; - TheValue = AllocateZeroPool(sizeof(CHAR16) * 80); + TheValue = AllocateZeroPool(sizeof(CHAR16) * 256); if (TheValue != NULL) { - SizeInIeee = (float) SizeInBytes; - while ((SizeInIeee > 1024.0) && (Index < (StrLen(Prefixes) - 1))) { + NumPrefixes = StrLen(Prefixes); + SizeInIeee = SizeInBytes; + while ((SizeInIeee > 1024) && (Index < (NumPrefixes - 1))) { Index++; - SizeInIeee /= 1024.0; + SizeInIeee /= 1024; } // while if (Prefixes[Index] == ' ') { Units = StrDuplicate(L"-byte"); @@ -663,7 +664,7 @@ static CHAR16 *SizeInIEEEUnits(UINT64 SizeInBytes) { Units = StrDuplicate(L" iB"); Units[1] = Prefixes[Index]; } // if/else - SPrint(TheValue, 79, L"%d%s", (UINTN) SizeInIeee, Units); + SPrint(TheValue, 255, L"%ld%s", SizeInIeee, Units); } // if return TheValue; } // CHAR16 *SizeInSIUnits() @@ -726,7 +727,7 @@ static CHAR16 *GetVolumeName(IN REFIT_VOLUME *Volume) { return FoundName; } // static CHAR16 *GetVolumeName() -VOID ScanVolume(IN OUT REFIT_VOLUME *Volume) +VOID ScanVolume(REFIT_VOLUME *Volume) { EFI_STATUS Status; EFI_DEVICE_PATH *DevicePath, *NextDevicePath; @@ -915,7 +916,7 @@ static VOID ScanExtendedPartition(REFIT_VOLUME *WholeDiskVolume, MBR_PARTITION_I } } } -} +} /* VOID ScanExtendedPartition() */ VOID ScanVolumes(VOID) { @@ -1030,7 +1031,7 @@ VOID ScanVolumes(VOID) MyFreePool(SectorBuffer2); } - } + } // for } /* VOID ScanVolumes() */ static VOID UninitVolumes(VOID) @@ -1375,8 +1376,8 @@ BOOLEAN StriSubCmp(IN CHAR16 *SmallStr, IN CHAR16 *BigStr) { // Merges two strings, creating a new one and returning a pointer to it. // If AddChar != 0, the specified character is placed between the two original -// strings (unless the first string is NULL). The original input string -// *First is de-allocated and replaced by the new merged string. +// strings (unless the first string is NULL or empty). The original input +// string *First is de-allocated and replaced by the new merged string. // This is similar to StrCat, but safer and more flexible because // MergeStrings allocates memory that's the correct size for the // new merged string, so it can take a NULL *First and it cleans @@ -1392,6 +1393,10 @@ VOID MergeStrings(IN OUT CHAR16 **First, IN CHAR16 *Second, CHAR16 AddChar) { Length2 = StrLen(Second); NewString = AllocatePool(sizeof(CHAR16) * (Length1 + Length2 + 2)); if (NewString != NULL) { + if ((*First != NULL) && (StrLen(*First) == 0)) { + MyFreePool(*First); + *First = NULL; + } NewString[0] = L'\0'; if (*First != NULL) { StrCat(NewString, *First); diff --git a/refind/main.c b/refind/main.c index 7a785cd..22693f1 100644 --- a/refind/main.c +++ b/refind/main.c @@ -56,9 +56,11 @@ #ifdef __MAKEWITH_TIANO #include "../EfiLib/BdsHelper.h" +#else +#define EFI_SECURITY_VIOLATION EFIERR (26) #endif // __MAKEWITH_TIANO -// +// // variables #define MACOSX_LOADER_PATH L"System\\Library\\CoreServices\\boot.efi" @@ -66,7 +68,7 @@ #define SHELL_NAMES L"\\EFI\\tools\\shell.efi,\\EFI\\tools\\shellx64.efi,\\shellx64.efi" #define DRIVER_DIRS L"drivers,drivers_x64" #elif defined (EFI32) -#define SHELL_NAMES L"\\EFI\\tools\\shell.efi,\\EFI\\tools\shellia32.efi,\\shellia32.efi" +#define SHELL_NAMES L"\\EFI\\tools\\shell.efi,\\EFI\\tools\\shellia32.efi,\\shellia32.efi" #define DRIVER_DIRS L"drivers,drivers_ia32" #else #define SHELL_NAMES L"\\EFI\\tools\\shell.efi" @@ -125,7 +127,7 @@ static VOID AboutrEFInd(VOID) if (AboutMenu.EntryCount == 0) { AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT); - AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.6.0.2"); + AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.6.0.4"); AddMenuInfoLine(&AboutMenu, L""); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer"); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012 Roderick W. Smith"); @@ -224,7 +226,7 @@ static EFI_STATUS StartEFIImageList(IN EFI_DEVICE_PATH **DevicePaths, // ImageData, ImageSize, &ChildImageHandle); ReturnStatus = Status = refit_call6_wrapper(BS->LoadImage, FALSE, SelfImageHandle, DevicePaths[DevicePathIndex], NULL, 0, &ChildImageHandle); - if ((Status == EFI_ACCESS_DENIED) && (ShimLoaded())) { + if (((Status == EFI_ACCESS_DENIED) || (Status == EFI_SECURITY_VIOLATION)) && (ShimLoaded())) { FindVolumeAndFilename(DevicePaths[DevicePathIndex], &DeviceVolume, &loader); if (DeviceVolume != NULL) { Status = ReadFile(DeviceVolume->RootDir, loader, &File, &ImageSize); @@ -725,9 +727,9 @@ static CHAR16 * GetMainLinuxOptions(IN CHAR16 * LoaderPath, IN REFIT_VOLUME *Vol // Sets a few defaults for a loader entry -- mainly the icon, but also the OS type // code and shortcut letter. For Linux EFI stub loaders, also sets kernel options // that will (with luck) work fairly automatically. -VOID SetLoaderDefaults(LOADER_ENTRY *Entry, CHAR16 *LoaderPath, IN REFIT_VOLUME *Volume) { +VOID SetLoaderDefaults(LOADER_ENTRY *Entry, CHAR16 *LoaderPath, REFIT_VOLUME *Volume) { CHAR16 IconFileName[256]; - CHAR16 *FileName, *PathOnly, *OSIconName = NULL, *Temp; + CHAR16 *FileName, *PathOnly, *OSIconName = NULL, *Temp, *SubString; CHAR16 ShortcutLetter = 0; UINTN i, Length; @@ -735,6 +737,7 @@ VOID SetLoaderDefaults(LOADER_ENTRY *Entry, CHAR16 *LoaderPath, IN REFIT_VOLUME PathOnly = FindPath(LoaderPath); // locate a custom icon for the loader + // Anything found here takes precedence over the "hints" in the OSIconName variable StrCpy(IconFileName, LoaderPath); ReplaceEfiExtension(IconFileName, L".icns"); if (FileExists(Volume->RootDir, IconFileName)) { @@ -743,6 +746,8 @@ VOID SetLoaderDefaults(LOADER_ENTRY *Entry, CHAR16 *LoaderPath, IN REFIT_VOLUME Entry->me.Image = Volume->VolIconImage; } // icon matched to loader or volume + // Begin creating icon "hints" by using last part of directory path leading + // to the loader Temp = FindLastDirName(LoaderPath); MergeStrings(&OSIconName, Temp, L','); MyFreePool(Temp); @@ -751,18 +756,22 @@ VOID SetLoaderDefaults(LOADER_ENTRY *Entry, CHAR16 *LoaderPath, IN REFIT_VOLUME ShortcutLetter = OSIconName[0]; } - // Add the volume's label up to the first space, dash, or underscore (if present) - // as a potential base for finding an icon + // Add every "word" in the volume label, delimited by spaces, dashes (-), or + // underscores (_), to the list of hints to be used in searching for OS + // icons. if ((Volume->VolName) && (StrLen(Volume->VolName) > 0)) { - Temp = StrDuplicate(Volume->VolName); + Temp = SubString = StrDuplicate(Volume->VolName); if (Temp != NULL) { - i = 0; Length = StrLen(Temp); - do { - if ((Temp[i] == L' ') || (Temp[i] == L'_') || (Temp[i] == L'-')) + for (i = 0; i < Length; i++) { + if ((Temp[i] == L' ') || (Temp[i] == L'_') || (Temp[i] == L'-')) { Temp[i] = 0; - } while ((Temp[i] != 0) && (++i < Length)); - MergeStrings(&OSIconName, Temp, L','); + if (StrLen(SubString) > 0) + MergeStrings(&OSIconName, SubString, L','); + SubString = Temp + i + 1; + } // if + } // for + MergeStrings(&OSIconName, SubString, L','); MyFreePool(Temp); } // if } // if @@ -801,7 +810,7 @@ VOID SetLoaderDefaults(LOADER_ENTRY *Entry, CHAR16 *LoaderPath, IN REFIT_VOLUME Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_GRUB; } else if (StriCmp(FileName, L"cdboot.efi") == 0 || StriCmp(FileName, L"bootmgr.efi") == 0 || - StriCmp(FileName, L"Bootmgfw.efi") == 0) { + StriCmp(FileName, L"bootmgfw.efi") == 0) { MergeStrings(&OSIconName, L"win", L','); Entry->OSType = 'W'; ShortcutLetter = 'W'; @@ -1415,7 +1424,6 @@ static VOID ScanLegacyUEFI(IN UINTN DiskType) BDS_COMMON_OPTION *BdsOption; LIST_ENTRY TempList; BBS_BBS_DEVICE_PATH * BbsDevicePath = NULL; -// REFIT_VOLUME Volume; InitializeListHead (&TempList); ZeroMem (Buffer, sizeof (Buffer)); @@ -1941,7 +1949,7 @@ static VOID InitializeLib(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *System // EFI_STATUS EFIAPI -efi_main (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) +efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { EFI_STATUS Status; BOOLEAN MainLoopRunning = TRUE; -- 2.39.2