]> code.delx.au - refind/commitdiff
Misc. bug fixes & minor code improvements
authorsrs5694 <srs5694@users.sourceforge.net>
Thu, 20 Dec 2012 04:23:37 +0000 (23:23 -0500)
committersrs5694 <srs5694@users.sourceforge.net>
Thu, 20 Dec 2012 04:23:37 +0000 (23:23 -0500)
NEWS.txt
docs/refind/configfile.html
libeg/screen.c
refind/lib.c
refind/main.c

index 5bfd5c07d57d45e3aca9c1e156e6203d85603241..e249ef829705fe63a0e1107d5f4ce3235c7ddcc4 100644 (file)
--- 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.
index 6b6ce6c0281d8b8ef6feb6069296d793757f173a..2f33216631b2bca04c07e41db42892f5215d1190 100644 (file)
@@ -104,21 +104,25 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
 
 <p>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.</p>
 
-<p>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:</p>
+<p>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:</p>
 
 <ul>
 
+<li>You can name an icon file after your boot loader, but with an extension of <tt>.icns</tt>. For instance, if you're using <tt class="variable">loader</tt><tt>.efi</tt>, you would name the icon file <tt class="variable">loader</tt><tt>.icns</tt>. (If you use the <tt>scan_all_linux_kernels</tt> option, you can give an icon for a Linux kernel without a <tt>.efi</tt> extension a name based on the kernel name but with a <tt>.icns</tt> extension&mdash;for instance, <tt>bzImage-3.3.2.icns</tt> will serve as the icon for the <tt>bzImage-3.3.2</tt> kernel.) These icon files should be 128x128 images in <a href="http://en.wikipedia.org/wiki/Apple_Icon_Image_format">Apple's ICNS format.</a> You can create such files easily in OS X or convert PNG files to ICNS format with <a href="http://icns.sourceforge.net/">libicns.</a></li>
+
 <li>You can place a boot loader in a directory with a name that matches one of rEFInd's standard icons, which take names of the form <tt>os_<tt class="variable">name</tt>.icns</tt>. To use this icon, you would place the boot loader in the directory called <tt class="variable">name</tt>.</li>
 
-<li>You can name an icon file after your boot loader, but with an extension of <tt>.icns</tt>. For instance, if you're using <tt class="variable">loader</tt><tt>.efi</tt>, you would name the icon file <tt class="variable">loader</tt><tt>.icns</tt>. (If you use the <tt>scan_all_linux_kernels</tt> option, you can give an icon for a Linux kernel without a <tt>.efi</tt> extension a name based on the kernel name but with a <tt>.icns</tt> extension&mdash;for instance, <tt>bzImage-3.3.2.icns</tt> will serve as the icon for the <tt>bzImage-3.3.2</tt> kernel.) These icon files should be 128x128 images in <a href="http://en.wikipedia.org/wiki/Apple_Icon_Image_format">Apple's ICNS format.</a> You can create such files easily in OS X or convert PNG files to ICNS format with <a href="http://icns.sourceforge.net/">libicns.</a></li>
+<li>You can give the filesystem from which the boot loader is loaded a name that matches the OS name component of the icon filename. For instance, if you call your boot filesystem <tt>CentOS</tt>, it matches the <tt>os_centos.icns</tt> icon. This match is performed on a word-by-word basis within the name, with "words" being delimited by spaces, dashes (<tt>-</tt>), and underscores (<tt>_</tt>). Thus, a volume called <tt>Debian-boot</tt> will match <tt>os_debian.icns</tt> or <tt>os_boot.icns</tt>.</li>
 
 <li>If you're booting OS X from its standard boot loader, or if you place a boot loader file in the root directory of a partition, you can create a file called <tt>.VolumeIcon.icns</tt> that holds an icon file. OS X uses this file for its volume icons, so rEFInd picks up these icons automatically, provided they include 128x128 bitmaps.</li>
 
+<li>Certain boot loaders have hard-coded icons associated with them. For instance, filenames beginning with <tt>vmlinuz</tt> or <tt>bzImage</tt> acquire Linux "Tux" icons and the <tt>bootmgfw.efi</tt> loader acquires a Windows icon. For the most part, these are the associations you want to overcome with the preceding rules, but sometimes renaming a boot loader to a more conventional name is the better approach.</li>
+
 </ul>
 
-<p>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.</p>
+<p>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.</p>
 
-<p>In addition to the main OS tag icon, you can set the <i>badge</i> icon for a volume by creating a file called <tt>.VolumeBadge.icns</tt> 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.</p>
+<p>In addition to the main OS tag icon, you can set the <i>badge</i> icon for a volume by creating a file called <tt>.VolumeBadge.icns</tt> 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 <tt>icons</tt> subdirectory (<tt>vol_external.icns</tt>, <tt>vol_internal.icns</tt>, and <tt>vol_optical.icns</tt>) with a completely transparent badge. The <tt>transparent.icns</tt> file in the rEFInd <tt>icons</tt> directory may be used for this purpose.</p>
 
 <h2>Adjusting the Global Configuration</h2>
 
index bac1f005d4be07f5353060f20d094e494ad41ae0..e4f585afae7ad23c30166b906b39e70244ad398b 100644 (file)
@@ -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;
index 347a176f5065b98ddfb8ae36a6061dd91967d491..958bb525712565ecb778d99379a76f09411f41f0 100644 (file)
@@ -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);
index 7a785cd423b67f7143e7d2568a50424ac3b8b7fc..22693f1732118e2968cbeb1418248e0d647c6d40 100644 (file)
 
 #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;