]> code.delx.au - refind/commitdiff
Improvements to handling of case-insensitive string comparisons, which
authorsrs5694 <srs5694@users.sourceforge.net>
Fri, 21 Aug 2015 20:27:40 +0000 (16:27 -0400)
committersrs5694 <srs5694@users.sourceforge.net>
Fri, 21 Aug 2015 20:27:40 +0000 (16:27 -0400)
affect systems with buggy EFIs. Also added /etc/lsb-release file to
files scanned for clues about a Linux distribution's identity, and
added an icon for Elementary OS.

14 files changed:
EfiLib/BdsHelper.c
EfiLib/BmLib.c
NEWS.txt
docs/refind/getting.html
docs/refind/todo.html
gptsync/gptsync.h
gptsync/os_efi.c
icons/os_elementary.png [new file with mode: 0644]
include/tiano_includes.h
refind.conf-sample
refind/config.c
refind/lib.c
refind/lib.h
refind/main.c

index b4ece24b97bee1b16232e33a4c237c896d077b0c..47ecf9ac59b028b295f285c2d504b90cdf11f6aa 100644 (file)
@@ -8,6 +8,7 @@
 #include "BdsHelper.h"
 #include "legacy.h"
 #include "../refind/screen.h"
+#include "../refind/lib.h"
 #include "../include/refit_call_wrapper.h"
 
 EFI_GUID gEfiLegacyBootProtocolGuid     = { 0xdb9a1e3d, 0x45cb, 0x4abb, { 0x85, 0x3b, 0xe5, 0x38, 0x7f, 0xdb, 0x2e, 0x2d }};
@@ -60,7 +61,7 @@ VOID UpdateBbsTable (BDS_COMMON_OPTION *Option) {
 
       // Set devices of a particular type to BootPriority of 0 or 1. 0 is the highest priority.
       if (LocalBbsTable[Idx].DeviceType == OptionBBS->DeviceType) {
-         if (StriCmp(Desc, Option->Description) == 0) {
+         if (MyStriCmp(Desc, Option->Description)) {
             // This entry exactly matches what we're looking for; make it highest priority
             LocalBbsTable[Idx].BootPriority = 0;
          } else {
index 4e7ebaaee058bc822d363bbf628450a4037dd146..99598b860d3a4288bb51ba452f717791998f38d8 100644 (file)
@@ -119,22 +119,6 @@ EfiStrDuplicate (
   return Dest;\r
 }\r
 \r
-//Compare strings case insensitive\r
-INTN\r
-EFIAPI\r
-StriCmp (\r
-               IN      CONST CHAR16              *FirstString,\r
-               IN      CONST CHAR16              *SecondString\r
-               )\r
-{\r
-       \r
-       while ((*FirstString != L'\0') && ((*FirstString & ~0x20) == (*SecondString & ~0x20))) {\r
-               FirstString++;\r
-               SecondString++;\r
-       }\r
-       return *FirstString - *SecondString;\r
-}\r
-\r
 /**\r
 \r
   Function gets the file information from an open file descriptor, and stores it\r
index a04b68b4d418550361586b3a936a69aa38427b92..e02c7db05f035e2e6e1b87c62559315819750b6f 100644 (file)
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -1,3 +1,23 @@
+0.9.1 (?/??/2015):
+------------------
+
+- Added icon for Elementary OS.
+
+- Added /etc/lsb-release to files scanned for clues about the Linux
+  distribution. This file differentiates Mint and Elementary OS from Ubuntu
+  better than does /etc/os-release, and may also help with other
+  closely-related distributions.
+
+- Improvements to handling of case-insensitive string comparisons. These
+  are buggy on some EFIs, and such bugs affect things like dont_scan_*
+  blacklists, removal of rEFInd's own directory from scanning, matching of
+  keyword names in refind.conf, and even loading of icons. I've replaced
+  many calls to problematic functions with safer calls, which should help a
+  lot. There may still be problems on some systems with some computers,
+  though; as far as I can tell, the bugs are buried deep in some EFI
+  firmware, so I can only replace some of the most direct calls to
+  potentially buggy system calls.
+
 0.9.0 (7/26/2015):
 ------------------
 
index a3bfaea8f9183877bbfaa6eef1f1a1ec27f6bbf4..dbf3f0fa64fc1983562ee53ddcf754c7b254948c 100644 (file)
@@ -17,7 +17,7 @@
 href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
 
 <p>Originally written: 3/14/2012; last Web page update:
-7/26/2015, referencing rEFInd 0.9.0</p>
+8/2/2015, referencing rEFInd 0.9.0</p>
 
 <p>This Web page is provided free of charge and with no annoying outside ads; however, I did take time to prepare it, and Web hosting does cost money. If you find this Web page useful, please consider making a small donation to help keep this site up and running. Thanks!</p>
 
index 1e25b818ed4d352216d320ec341b8193cc3cb606..dd5503687f7d6e20d18e6368a903a99596cced12 100644 (file)
@@ -334,15 +334,6 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
        BIOS-booted OS. This isn't a big priority for me personally, but I
        can see how it could be for some people.</li>
 
-    <li>I've received queries about rEFInd's ability to work with Apple's
-       whole-disk encryption scheme that's new with OS X 10.7.
-       Unfortunately, I lack the hardware to test this, but my
-       understanding is that it will work correctly <i>if</i> rEFInd is
-       installed in the ESP rather than on the Mac OS X root partition.
-       See <a
-       href="https://sourceforge.net/p/refind/discussion/general/thread/5c7d0195/">this
-       forum thread</a> for more information.</li>
-
     <li>I'd like to find a way to enable users to enter customizations for
        boot options and then save them to the <tt>refind.conf</tt> file.
        One possible way to implement this would be to have manual boot
@@ -357,6 +348,9 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
        actions would enable use of rEFInd on tablet computers that lack
        complete keyboards.</li>
 
+    <li>The ability to rotate the display for users who rotate their
+       monitors or who use tablets would be helpful.</li>
+
     <li>GRUB provides a configuration-file command called <tt>outb</tt>
        that enables manipulating hardware registers. Something similar,
        via the <tt>mm</tt> command, can be done in the EFI shell. I'd like
@@ -381,13 +375,11 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
        loader settings&mdash;say, to disable one specific boot loader or
        change its icon.</li>
 
-    <li>The ability to rotate the display for users who rotate their
-       monitors would be helpful.</li>
-
-    <li>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.</li>
+    <li>A GUI configuration tool for host OSes (Linux, OS X, Windows, etc.)
+       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.</li>
 
     </ul></li> <!-- New features -->
 
@@ -425,14 +417,6 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
        under some circumstances, such as when it makes no changes to the
        partition table. Fix this.</li>
 
-    <li>When updating a system with Secure Boot via an RPM or Debian
-       package, the RPM installation script can detect rEFInd's existing
-       shim or PreLoader program and pass options to <tt>install.sh</tt>
-       to try to copy these programs over themselves. This results in a
-       message that the copy was over the same file and an error message
-       that there were problems with the installation, although this isn't
-       really the case.</li>
-
     <li>rEFInd's support for network booting is primitive and relies on the
        external iPXE package. In my own testing, iPXE retrieves the
        BIOS-mode boot loader from some servers that offer both, which
index b9bf46e356039a362fe66fee3af4f2449cee0717..017f3dc22fcbb5defdc97bf757bbb92365dcd7f9 100644 (file)
@@ -35,7 +35,7 @@
  */
 /* Changes copyright (c) 2013 Roderick W. Smith */
 
-#define VERSION L"0.8.7"
+#define VERSION L"0.9.1"
 
 //
 // config
index fa48733e8cfb7cfac5b9d3479585ce3afe2c8f61..9559014e4a2ee9f2373172eb43fa2a9d27700f83 100644 (file)
@@ -169,13 +169,29 @@ static VOID InitializeLib(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *System
 
 #endif
 
+// Performs a case-insensitive string comparison. This function is necesary
+// because some EFIs have buggy StriCmp() functions that actually perform
+// case-sensitive comparisons.
+// Returns TRUE if strings are identical, FALSE otherwise.
+static BOOLEAN MyStriCmp(IN CHAR16 *FirstString, IN CHAR16 *SecondString) {
+    if (FirstString && SecondString) {
+        while ((*FirstString != L'\0') && ((*FirstString & ~0x20) == (*SecondString & ~0x20))) {
+                FirstString++;
+                SecondString++;
+        }
+        return (*FirstString == *SecondString);
+    } else {
+        return FALSE;
+    }
+} // BOOLEAN MyStriCmp()
+
 // Check firmware vendor; get verification to continue if it's not Apple.
 // Returns TRUE if Apple firmware or if user assents to use, FALSE otherwise.
 static BOOLEAN VerifyGoOn(VOID) {
    BOOLEAN GoOn = TRUE;
    UINTN invalid;
 
-   if (StriCmp(L"Apple", ST->FirmwareVendor) != 0) {
+   if (MyStriCmp(L"Apple", ST->FirmwareVendor)) {
       Print(L"Your firmware is made by %s.\n", ST->FirmwareVendor);
       Print(L"Ordinarily, a hybrid MBR (which this program creates) should be used ONLY on\n");
       Print(L"Apple Macs that dual-boot with Windows or some other BIOS-mode OS. Are you\n");
diff --git a/icons/os_elementary.png b/icons/os_elementary.png
new file mode 100644 (file)
index 0000000..dab53cd
Binary files /dev/null and b/icons/os_elementary.png differ
index 67851382f282a01960fde99954259a7b23330e7d..a723c9167cb4c7af9a372a991edca6977477bb68 100644 (file)
@@ -135,11 +135,6 @@ EfiStrDuplicate (
    IN CHAR16   *Src
 );
 
-INTN EFIAPI StriCmp (
-   IN      CONST CHAR16              *FirstString,
-   IN      CONST CHAR16              *SecondString
-);
-
 extern EFI_FILE_INFO * EfiLibFileInfo (IN EFI_FILE_HANDLE      FHand);
 extern EFI_FILE_SYSTEM_INFO * EfiLibFileSystemInfo (IN EFI_FILE_HANDLE   Root);
 
index f3c31a4a8c8ba5b9928862a0d85be69c706ee4d2..32ccc5947762f961e44c16ff44eec07e11792d4b 100644 (file)
@@ -336,7 +336,8 @@ timeout 20
 #  - A "+" symbol at the start of the string, which refers to the most
 #    recently booted loader.
 #  - Any substring that corresponds to a portion of the loader's title
-#    (usually the OS's name or boot loader's path).
+#    (usually the OS's name, boot loader's path, or a volume or
+#    filesystem title).
 # You may also specify multiple selectors by separating them with commas
 # and enclosing the list in quotes. (The "+" option is only meaningful in
 # this context.)
index d3b7580a28e1f812c3833aaf5718ce1731618cf4..6343f12a8547f09e5a8bf08ae8a082a247bc3ba3 100644 (file)
@@ -315,7 +315,7 @@ VOID FreeTokenLine(IN OUT CHAR16 ***TokenList, IN OUT UINTN *TokenCount)
 static VOID HandleInt(IN CHAR16 **TokenList, IN UINTN TokenCount, OUT UINTN *Value)
 {
     if (TokenCount == 2) {
-       if (StriCmp(TokenList[1], L"-1") == 0)
+       if (StrCmp(TokenList[1], L"-1") == 0)
           *Value = -1;
        else
           *Value = Atoi(TokenList[1]);
@@ -348,7 +348,7 @@ static VOID HandleStrings(IN CHAR16 **TokenList, IN UINTN TokenCount, OUT CHAR16
    UINTN i;
    BOOLEAN AddMode = FALSE;
 
-   if ((TokenCount > 2) && (StriCmp(TokenList[1], L"+") == 0)) {
+   if ((TokenCount > 2) && (StrCmp(TokenList[1], L"+") == 0)) {
       AddMode = TRUE;
    }
 
@@ -390,9 +390,9 @@ static UINTN HandleTime(IN CHAR16 *TimeString) {
 static BOOLEAN HandleBoolean(IN CHAR16 **TokenList, IN UINTN TokenCount) {
    BOOLEAN TruthValue = TRUE;
 
-   if ((TokenCount >= 2) && ((StriCmp(TokenList[1], L"0") == 0) ||
-                             (StriCmp(TokenList[1], L"false") == 0) ||
-                             (StriCmp(TokenList[1], L"off") == 0))) {
+   if ((TokenCount >= 2) && ((StrCmp(TokenList[1], L"0") == 0) ||
+                             MyStriCmp(TokenList[1], L"false") ||
+                             MyStriCmp(TokenList[1], L"off"))) {
       TruthValue = FALSE;
    } // if
 
@@ -448,7 +448,7 @@ VOID ReadConfig(CHAR16 *FileName)
     EFI_GUID        RefindGuid = REFIND_GUID_VALUE;
 
     // Set a few defaults only if we're loading the default file.
-    if (StriCmp(FileName, GlobalConfig.ConfigFilename) == 0) {
+    if (MyStriCmp(FileName, GlobalConfig.ConfigFilename)) {
        MyFreePool(GlobalConfig.AlsoScan);
        GlobalConfig.AlsoScan = StrDuplicate(ALSO_SCAN_DIRS);
        MyFreePool(GlobalConfig.DontScanDirs);
@@ -497,41 +497,41 @@ VOID ReadConfig(CHAR16 *FileName)
         if (TokenCount == 0)
             break;
 
-        if (StriCmp(TokenList[0], L"timeout") == 0) {
+        if (MyStriCmp(TokenList[0], L"timeout")) {
             HandleInt(TokenList, TokenCount, &(GlobalConfig.Timeout));
 
-        } else if (StriCmp(TokenList[0], L"hideui") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"hideui")) {
             for (i = 1; i < TokenCount; i++) {
                 FlagName = TokenList[i];
-                if (StriCmp(FlagName, L"banner") == 0) {
+                if (MyStriCmp(FlagName, L"banner")) {
                    GlobalConfig.HideUIFlags |= HIDEUI_FLAG_BANNER;
-                } else if (StriCmp(FlagName, L"label") == 0) {
+                } else if (MyStriCmp(FlagName, L"label")) {
                    GlobalConfig.HideUIFlags |= HIDEUI_FLAG_LABEL;
-                } else if (StriCmp(FlagName, L"singleuser") == 0) {
+                } else if (MyStriCmp(FlagName, L"singleuser")) {
                    GlobalConfig.HideUIFlags |= HIDEUI_FLAG_SINGLEUSER;
-                } else if (StriCmp(FlagName, L"hwtest") == 0) {
+                } else if (MyStriCmp(FlagName, L"hwtest")) {
                    GlobalConfig.HideUIFlags |= HIDEUI_FLAG_HWTEST;
-                } else if (StriCmp(FlagName, L"arrows") == 0) {
+                } else if (MyStriCmp(FlagName, L"arrows")) {
                    GlobalConfig.HideUIFlags |= HIDEUI_FLAG_ARROWS;
-                } else if (StriCmp(FlagName, L"hints") == 0) {
+                } else if (MyStriCmp(FlagName, L"hints")) {
                    GlobalConfig.HideUIFlags |= HIDEUI_FLAG_HINTS;
-                } else if (StriCmp(FlagName, L"editor") == 0) {
+                } else if (MyStriCmp(FlagName, L"editor")) {
                    GlobalConfig.HideUIFlags |= HIDEUI_FLAG_EDITOR;
-                } else if (StriCmp(FlagName, L"safemode") == 0) {
+                } else if (MyStriCmp(FlagName, L"safemode")) {
                    GlobalConfig.HideUIFlags |= HIDEUI_FLAG_SAFEMODE;
-                } else if (StriCmp(FlagName, L"badges") == 0) {
+                } else if (MyStriCmp(FlagName, L"badges")) {
                    GlobalConfig.HideUIFlags |= HIDEUI_FLAG_BADGES;
-                } else if (StriCmp(FlagName, L"all") == 0) {
+                } else if (MyStriCmp(FlagName, L"all")) {
                    GlobalConfig.HideUIFlags = HIDEUI_FLAG_ALL;
                 } else {
                     Print(L" unknown hideui flag: '%s'\n", FlagName);
                 }
             }
 
-        } else if (StriCmp(TokenList[0], L"icons_dir") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"icons_dir")) {
            HandleString(TokenList, TokenCount, &(GlobalConfig.IconsDir));
 
-        } else if (StriCmp(TokenList[0], L"scanfor") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"scanfor")) {
            for (i = 0; i < NUM_SCAN_OPTIONS; i++) {
               if (i < TokenCount)
                  GlobalConfig.ScanFor[i] = TokenList[i][0];
@@ -539,16 +539,16 @@ VOID ReadConfig(CHAR16 *FileName)
                  GlobalConfig.ScanFor[i] = ' ';
            }
 
-        } else if (StriCmp(TokenList[0], L"uefi_deep_legacy_scan") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"uefi_deep_legacy_scan")) {
            GlobalConfig.DeepLegacyScan = HandleBoolean(TokenList, TokenCount);
 
-        } else if ((StriCmp(TokenList[0], L"scan_delay") == 0) && (TokenCount == 2)) {
+        } else if (MyStriCmp(TokenList[0], L"scan_delay") && (TokenCount == 2)) {
            HandleInt(TokenList, TokenCount, &(GlobalConfig.ScanDelay));
 
-        } else if (StriCmp(TokenList[0], L"also_scan_dirs") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"also_scan_dirs")) {
             HandleStrings(TokenList, TokenCount, &(GlobalConfig.AlsoScan));
 
-        } else if ((StriCmp(TokenList[0], L"don't_scan_volumes") == 0) || (StriCmp(TokenList[0], L"dont_scan_volumes") == 0)) {
+        } else if (MyStriCmp(TokenList[0], L"don't_scan_volumes") || MyStriCmp(TokenList[0], L"dont_scan_volumes")) {
            // Note: Don't use HandleStrings() because it modifies slashes, which might be present in volume name
            MyFreePool(GlobalConfig.DontScanVolumes);
            GlobalConfig.DontScanVolumes = NULL;
@@ -556,141 +556,140 @@ VOID ReadConfig(CHAR16 *FileName)
               MergeStrings(&GlobalConfig.DontScanVolumes, TokenList[i], L',');
            }
 
-        } else if ((StriCmp(TokenList[0], L"don't_scan_dirs") == 0) || (StriCmp(TokenList[0], L"dont_scan_dirs") == 0)) {
+        } else if (MyStriCmp(TokenList[0], L"don't_scan_dirs") || MyStriCmp(TokenList[0], L"dont_scan_dirs")) {
             HandleStrings(TokenList, TokenCount, &(GlobalConfig.DontScanDirs));
 
-        } else if ((StriCmp(TokenList[0], L"don't_scan_files") == 0) || (StriCmp(TokenList[0], L"dont_scan_files") == 0)) {
+        } else if (MyStriCmp(TokenList[0], L"don't_scan_files") || MyStriCmp(TokenList[0], L"dont_scan_files")) {
            HandleStrings(TokenList, TokenCount, &(GlobalConfig.DontScanFiles));
 
-        } else if (StriCmp(TokenList[0], L"windows_recovery_files") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"windows_recovery_files")) {
            HandleStrings(TokenList, TokenCount, &(GlobalConfig.WindowsRecoveryFiles));
 
-        } else if (StriCmp(TokenList[0], L"scan_driver_dirs") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"scan_driver_dirs")) {
             HandleStrings(TokenList, TokenCount, &(GlobalConfig.DriverDirs));
 
-        } else if (StriCmp(TokenList[0], L"showtools") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"showtools")) {
             SetMem(GlobalConfig.ShowTools, NUM_TOOLS * sizeof(UINTN), 0);
             for (i = 1; (i < TokenCount) && (i < NUM_TOOLS); i++) {
                 FlagName = TokenList[i];
-                if (StriCmp(FlagName, L"shell") == 0) {
+                if (MyStriCmp(FlagName, L"shell")) {
                     GlobalConfig.ShowTools[i - 1] = TAG_SHELL;
-                } else if (StriCmp(FlagName, L"gptsync") == 0) {
+                } else if (MyStriCmp(FlagName, L"gptsync")) {
                     GlobalConfig.ShowTools[i - 1] = TAG_GPTSYNC;
-                } else if (StriCmp(FlagName, L"gdisk") == 0) {
+                } else if (MyStriCmp(FlagName, L"gdisk")) {
                    GlobalConfig.ShowTools[i - 1] = TAG_GDISK;
-                } else if (StriCmp(FlagName, L"about") == 0) {
+                } else if (MyStriCmp(FlagName, L"about")) {
                    GlobalConfig.ShowTools[i - 1] = TAG_ABOUT;
-                } else if (StriCmp(FlagName, L"exit") == 0) {
+                } else if (MyStriCmp(FlagName, L"exit")) {
                    GlobalConfig.ShowTools[i - 1] = TAG_EXIT;
-                } else if (StriCmp(FlagName, L"reboot") == 0) {
+                } else if (MyStriCmp(FlagName, L"reboot")) {
                    GlobalConfig.ShowTools[i - 1] = TAG_REBOOT;
-                } else if (StriCmp(FlagName, L"shutdown") == 0) {
+                } else if (MyStriCmp(FlagName, L"shutdown")) {
                    GlobalConfig.ShowTools[i - 1] = TAG_SHUTDOWN;
-                } else if (StriCmp(FlagName, L"apple_recovery") == 0) {
+                } else if (MyStriCmp(FlagName, L"apple_recovery")) {
                    GlobalConfig.ShowTools[i - 1] = TAG_APPLE_RECOVERY;
-                } else if (StriCmp(FlagName, L"windows_recovery") == 0) {
+                } else if (MyStriCmp(FlagName, L"windows_recovery")) {
                    GlobalConfig.ShowTools[i - 1] = TAG_WINDOWS_RECOVERY;
-                } else if (StriCmp(FlagName, L"mok_tool") == 0) {
+                } else if (MyStriCmp(FlagName, L"mok_tool")) {
                    GlobalConfig.ShowTools[i - 1] = TAG_MOK_TOOL;
-                } else if (StriCmp(FlagName, L"firmware") == 0) {
+                } else if (MyStriCmp(FlagName, L"firmware")) {
                    GlobalConfig.ShowTools[i - 1] = TAG_FIRMWARE;
-                } else if ((StriCmp(FlagName, L"memtest86") == 0) || (StriCmp(FlagName, L"memtest") == 0)) {
+                } else if (MyStriCmp(FlagName, L"memtest86") || MyStriCmp(FlagName, L"memtest")) {
                    GlobalConfig.ShowTools[i - 1] = TAG_MEMTEST;
-                } else if (StriCmp(FlagName, L"netboot") == 0) {
+                } else if (MyStriCmp(FlagName, L"netboot")) {
                    GlobalConfig.ShowTools[i - 1] = TAG_NETBOOT;
                 } else {
                    Print(L" unknown showtools flag: '%s'\n", FlagName);
                 }
             } // showtools options
 
-        } else if (StriCmp(TokenList[0], L"banner") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"banner")) {
            HandleString(TokenList, TokenCount, &(GlobalConfig.BannerFileName));
 
-        } else if ((StriCmp(TokenList[0], L"banner_scale") == 0) && (TokenCount == 2)) {
-           if (StriCmp(TokenList[1], L"noscale") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"banner_scale") && (TokenCount == 2)) {
+           if (MyStriCmp(TokenList[1], L"noscale")) {
               GlobalConfig.BannerScale = BANNER_NOSCALE;
-           } else if ((StriCmp(TokenList[1], L"fillscreen") == 0) || (StriCmp(TokenList[1], L"fullscreen") == 0)) {
+           } else if (MyStriCmp(TokenList[1], L"fillscreen") || MyStriCmp(TokenList[1], L"fullscreen")) {
               GlobalConfig.BannerScale = BANNER_FILLSCREEN;
            } else {
               Print(L" unknown banner_type flag: '%s'\n", TokenList[1]);
            } // if/else
 
-        } else if ((StriCmp(TokenList[0], L"small_icon_size") == 0) && (TokenCount == 2)) {
+        } else if (MyStriCmp(TokenList[0], L"small_icon_size") && (TokenCount == 2)) {
            HandleInt(TokenList, TokenCount, &i);
            if (i >= 32)
               GlobalConfig.IconSizes[ICON_SIZE_SMALL] = i;
 
-        } else if ((StriCmp(TokenList[0], L"big_icon_size") == 0) && (TokenCount == 2)) {
+        } else if (MyStriCmp(TokenList[0], L"big_icon_size") && (TokenCount == 2)) {
            HandleInt(TokenList, TokenCount, &i);
            if (i >= 32) {
               GlobalConfig.IconSizes[ICON_SIZE_BIG] = i;
               GlobalConfig.IconSizes[ICON_SIZE_BADGE] = i / 4;
            }
 
-        } else if (StriCmp(TokenList[0], L"selection_small") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"selection_small")) {
            HandleString(TokenList, TokenCount, &(GlobalConfig.SelectionSmallFileName));
 
-        } else if (StriCmp(TokenList[0], L"selection_big") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"selection_big")) {
            HandleString(TokenList, TokenCount, &(GlobalConfig.SelectionBigFileName));
 
-        } else if (StriCmp(TokenList[0], L"default_selection") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"default_selection")) {
            if (TokenCount == 4) {
               SetDefaultByTime(TokenList, &(GlobalConfig.DefaultSelection));
            } else {
               HandleString(TokenList, TokenCount, &(GlobalConfig.DefaultSelection));
            }
 
-        } else if (StriCmp(TokenList[0], L"textonly") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"textonly")) {
            GlobalConfig.TextOnly = HandleBoolean(TokenList, TokenCount);
 
-        } else if (StriCmp(TokenList[0], L"textmode") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"textmode")) {
            HandleInt(TokenList, TokenCount, &(GlobalConfig.RequestedTextMode));
 
-        } else if ((StriCmp(TokenList[0], L"resolution") == 0) && ((TokenCount == 2) || (TokenCount == 3))) {
+        } else if (MyStriCmp(TokenList[0], L"resolution") && ((TokenCount == 2) || (TokenCount == 3))) {
            GlobalConfig.RequestedScreenWidth = Atoi(TokenList[1]);
            if (TokenCount == 3)
               GlobalConfig.RequestedScreenHeight = Atoi(TokenList[2]);
            else
               GlobalConfig.RequestedScreenHeight = 0;
 
-        } else if (StriCmp(TokenList[0], L"screensaver") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"screensaver")) {
            HandleInt(TokenList, TokenCount, &(GlobalConfig.ScreensaverTime));
 
-        } else if (StriCmp(TokenList[0], L"use_graphics_for") == 0) {
-           if ((TokenCount == 2) || ((TokenCount > 2) && (StriCmp(TokenList[1], L"+") != 0)))
+        } else if (MyStriCmp(TokenList[0], L"use_graphics_for")) {
+           if ((TokenCount == 2) || ((TokenCount > 2) && (!MyStriCmp(TokenList[1], L"+"))))
               GlobalConfig.GraphicsFor = 0;
            for (i = 1; i < TokenCount; i++) {
-              if (StriCmp(TokenList[i], L"osx") == 0) {
+              if (MyStriCmp(TokenList[i], L"osx")) {
                  GlobalConfig.GraphicsFor |= GRAPHICS_FOR_OSX;
-              } else if (StriCmp(TokenList[i], L"linux") == 0) {
+              } else if (MyStriCmp(TokenList[i], L"linux")) {
                  GlobalConfig.GraphicsFor |= GRAPHICS_FOR_LINUX;
-              } else if (StriCmp(TokenList[i], L"elilo") == 0) {
+              } else if (MyStriCmp(TokenList[i], L"elilo")) {
                  GlobalConfig.GraphicsFor |= GRAPHICS_FOR_ELILO;
-              } else if (StriCmp(TokenList[i], L"grub") == 0) {
+              } else if (MyStriCmp(TokenList[i], L"grub")) {
                  GlobalConfig.GraphicsFor |= GRAPHICS_FOR_GRUB;
-              } else if (StriCmp(TokenList[i], L"windows") == 0) {
+              } else if (MyStriCmp(TokenList[i], L"windows")) {
                  GlobalConfig.GraphicsFor |= GRAPHICS_FOR_WINDOWS;
               }
            } // for (graphics_on tokens)
 
-        } else if ((StriCmp(TokenList[0], L"font") == 0) && (TokenCount == 2)) {
+        } else if (MyStriCmp(TokenList[0], L"font") && (TokenCount == 2)) {
            egLoadFont(TokenList[1]);
 
-        } else if (StriCmp(TokenList[0], L"scan_all_linux_kernels") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"scan_all_linux_kernels")) {
            GlobalConfig.ScanAllLinux = HandleBoolean(TokenList, TokenCount);
 
-        } else if (StriCmp(TokenList[0], L"fold_linux_kernels") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"fold_linux_kernels")) {
             GlobalConfig.FoldLinuxKernels = HandleBoolean(TokenList, TokenCount);
 
-        } else if (StriCmp(TokenList[0], L"max_tags") == 0) {
+        } else if (MyStriCmp(TokenList[0], L"max_tags")) {
            HandleInt(TokenList, TokenCount, &(GlobalConfig.MaxTags));
 
-       } else if (StriCmp(TokenList[0], L"enable_and_lock_vmx") == 0) {
+       } else if (MyStriCmp(TokenList[0], L"enable_and_lock_vmx")) {
           GlobalConfig.EnableAndLockVMX = HandleBoolean(TokenList, TokenCount);
 
-        } else if ((StriCmp(TokenList[0], L"include") == 0) && (TokenCount == 2) &&
-                   (StriCmp(FileName, GlobalConfig.ConfigFilename) == 0)) {
-           if (StriCmp(TokenList[1], FileName) != 0) {
+        } else if (MyStriCmp(TokenList[0], L"include") && (TokenCount == 2) && MyStriCmp(FileName, GlobalConfig.ConfigFilename)) {
+           if (!MyStriCmp(TokenList[1], FileName)) {
               ReadConfig(TokenList[1]);
            }
 
@@ -736,8 +735,7 @@ static BOOLEAN FindVolume(REFIT_VOLUME **Volume, CHAR16 *Identifier) {
             CountedVolumes++;
          } // if
       } else { // User specified a volume by label or GUID
-         if ((StriCmp(Identifier, Volumes[i]->VolName) == 0) ||
-             (StriCmp(Identifier, Volumes[i]->PartName) == 0)) {
+         if (MyStriCmp(Identifier, Volumes[i]->VolName) || MyStriCmp(Identifier, Volumes[i]->PartName)) {
             *Volume = Volumes[i];
             Found = TRUE;
          } // if
@@ -768,14 +766,14 @@ static VOID AddSubmenu(LOADER_ENTRY *Entry, REFIT_FILE *File, REFIT_VOLUME *Volu
       return;
    SubEntry->me.Title        = StrDuplicate(Title);
 
-   while (((TokenCount = ReadTokenLine(File, &TokenList)) > 0) && (StriCmp(TokenList[0], L"}") != 0)) {
+   while (((TokenCount = ReadTokenLine(File, &TokenList)) > 0) && (StrCmp(TokenList[0], L"}") != 0)) {
 
-      if ((StriCmp(TokenList[0], L"loader") == 0) && (TokenCount > 1)) { // set the boot loader filename
+      if (MyStriCmp(TokenList[0], L"loader") && (TokenCount > 1)) { // set the boot loader filename
          MyFreePool(SubEntry->LoaderPath);
          SubEntry->LoaderPath = StrDuplicate(TokenList[1]);
          SubEntry->DevicePath = FileDevicePath(Volume->DeviceHandle, SubEntry->LoaderPath);
 
-      } else if ((StriCmp(TokenList[0], L"volume") == 0) && (TokenCount > 1)) {
+      } else if (MyStriCmp(TokenList[0], L"volume") && (TokenCount > 1)) {
          if (FindVolume(&Volume, TokenList[1])) {
             if ((Volume != NULL) && (Volume->IsReadable) && (Volume->RootDir)) {
                MyFreePool(SubEntry->me.Title);
@@ -786,27 +784,27 @@ static VOID AddSubmenu(LOADER_ENTRY *Entry, REFIT_FILE *File, REFIT_VOLUME *Volu
             } // if volume is readable
          } // if match found
 
-      } else if (StriCmp(TokenList[0], L"initrd") == 0) {
+      } else if (MyStriCmp(TokenList[0], L"initrd")) {
          MyFreePool(SubEntry->InitrdPath);
          SubEntry->InitrdPath = NULL;
          if (TokenCount > 1) {
             SubEntry->InitrdPath = StrDuplicate(TokenList[1]);
          }
 
-      } else if (StriCmp(TokenList[0], L"options") == 0) {
+      } else if (MyStriCmp(TokenList[0], L"options")) {
          MyFreePool(SubEntry->LoadOptions);
          SubEntry->LoadOptions = NULL;
          if (TokenCount > 1) {
             SubEntry->LoadOptions = StrDuplicate(TokenList[1]);
          } // if/else
 
-      } else if ((StriCmp(TokenList[0], L"add_options") == 0) && (TokenCount > 1)) {
+      } else if (MyStriCmp(TokenList[0], L"add_options") && (TokenCount > 1)) {
          MergeStrings(&SubEntry->LoadOptions, TokenList[1], L' ');
 
-      } else if ((StriCmp(TokenList[0], L"graphics") == 0) && (TokenCount > 1)) {
-         SubEntry->UseGraphicsMode = (StriCmp(TokenList[1], L"on") == 0);
+      } else if (MyStriCmp(TokenList[0], L"graphics") && (TokenCount > 1)) {
+         SubEntry->UseGraphicsMode = MyStriCmp(TokenList[1], L"on");
 
-      } else if (StriCmp(TokenList[0], L"disabled") == 0) {
+      } else if (MyStriCmp(TokenList[0], L"disabled")) {
          SubEntry->Enabled = FALSE;
       } // ief/elseif
 
@@ -849,8 +847,8 @@ static LOADER_ENTRY * AddStanzaEntries(REFIT_FILE *File, REFIT_VOLUME *Volume, C
 
    // Parse the config file to add options for a single stanza, terminating when the token
    // is "}" or when the end of file is reached.
-   while (((TokenCount = ReadTokenLine(File, &TokenList)) > 0) && (StriCmp(TokenList[0], L"}") != 0)) {
-      if ((StriCmp(TokenList[0], L"loader") == 0) && (TokenCount > 1)) { // set the boot loader filename
+   while (((TokenCount = ReadTokenLine(File, &TokenList)) > 0) && (StrCmp(TokenList[0], L"}") != 0)) {
+      if (MyStriCmp(TokenList[0], L"loader") && (TokenCount > 1)) { // set the boot loader filename
          Entry->LoaderPath = StrDuplicate(TokenList[1]);
          Entry->DevicePath = FileDevicePath(CurrentVolume->DeviceHandle, Entry->LoaderPath);
          SetLoaderDefaults(Entry, TokenList[1], CurrentVolume);
@@ -858,7 +856,7 @@ static LOADER_ENTRY * AddStanzaEntries(REFIT_FILE *File, REFIT_VOLUME *Volume, C
          Entry->LoadOptions = NULL; // Discard default options, if any
          DefaultsSet = TRUE;
 
-      } else if ((StriCmp(TokenList[0], L"volume") == 0) && (TokenCount > 1)) {
+      } else if (MyStriCmp(TokenList[0], L"volume") && (TokenCount > 1)) {
          if (FindVolume(&CurrentVolume, TokenList[1])) {
             if ((CurrentVolume != NULL) && (CurrentVolume->IsReadable) && (CurrentVolume->RootDir)) {
                MyFreePool(Entry->me.Title);
@@ -869,33 +867,33 @@ static LOADER_ENTRY * AddStanzaEntries(REFIT_FILE *File, REFIT_VOLUME *Volume, C
             } // if volume is readable
          } // if match found
 
-      } else if ((StriCmp(TokenList[0], L"icon") == 0) && (TokenCount > 1)) {
+      } else if (MyStriCmp(TokenList[0], L"icon") && (TokenCount > 1)) {
          MyFreePool(Entry->me.Image);
          Entry->me.Image = egLoadIcon(CurrentVolume->RootDir, TokenList[1], GlobalConfig.IconSizes[ICON_SIZE_BIG]);
          if (Entry->me.Image == NULL) {
             Entry->me.Image = DummyImage(GlobalConfig.IconSizes[ICON_SIZE_BIG]);
          }
 
-      } else if ((StriCmp(TokenList[0], L"initrd") == 0) && (TokenCount > 1)) {
+      } else if (MyStriCmp(TokenList[0], L"initrd") && (TokenCount > 1)) {
          MyFreePool(Entry->InitrdPath);
          Entry->InitrdPath = StrDuplicate(TokenList[1]);
 
-      } else if ((StriCmp(TokenList[0], L"options") == 0) && (TokenCount > 1)) {
+      } else if (MyStriCmp(TokenList[0], L"options") && (TokenCount > 1)) {
          MyFreePool(Entry->LoadOptions);
          Entry->LoadOptions = StrDuplicate(TokenList[1]);
 
-      } else if ((StriCmp(TokenList[0], L"ostype") == 0) && (TokenCount > 1)) {
+      } else if (MyStriCmp(TokenList[0], L"ostype") && (TokenCount > 1)) {
          if (TokenCount > 1) {
             Entry->OSType = TokenList[1][0];
          }
 
-      } else if ((StriCmp(TokenList[0], L"graphics") == 0) && (TokenCount > 1)) {
-         Entry->UseGraphicsMode = (StriCmp(TokenList[1], L"on") == 0);
+      } else if (MyStriCmp(TokenList[0], L"graphics") && (TokenCount > 1)) {
+         Entry->UseGraphicsMode = MyStriCmp(TokenList[1], L"on");
 
-      } else if (StriCmp(TokenList[0], L"disabled") == 0) {
+      } else if (MyStriCmp(TokenList[0], L"disabled")) {
          Entry->Enabled = FALSE;
 
-      } else if ((StriCmp(TokenList[0], L"submenuentry") == 0) && (TokenCount > 1)) {
+      } else if (MyStriCmp(TokenList[0], L"submenuentry") && (TokenCount > 1)) {
          AddSubmenu(Entry, File, CurrentVolume, TokenList[1]);
          AddedSubmenu = TRUE;
 
@@ -939,7 +937,7 @@ VOID ScanUserConfigured(CHAR16 *FileName)
       Volume = SelfVolume;
 
       while ((TokenCount = ReadTokenLine(&File, &TokenList)) > 0) {
-         if ((StriCmp(TokenList[0], L"menuentry") == 0) && (TokenCount > 1)) {
+         if (MyStriCmp(TokenList[0], L"menuentry") && (TokenCount > 1)) {
             Title = StrDuplicate(TokenList[1]);
             Entry = AddStanzaEntries(&File, Volume, TokenList[1]);
             if (Entry->Enabled) {
@@ -951,9 +949,9 @@ VOID ScanUserConfigured(CHAR16 *FileName)
             } // if/else
             MyFreePool(Title);
 
-         } else if ((StriCmp(TokenList[0], L"include") == 0) && (TokenCount == 2) &&
-                    (StriCmp(FileName, GlobalConfig.ConfigFilename) == 0)) {
-            if (StriCmp(TokenList[1], FileName) != 0) {
+         } else if (MyStriCmp(TokenList[0], L"include") && (TokenCount == 2) &&
+                    MyStriCmp(FileName, GlobalConfig.ConfigFilename)) {
+            if (!MyStriCmp(TokenList[1], FileName)) {
                ScanUserConfigured(TokenList[1]);
             }
 
@@ -989,9 +987,9 @@ static REFIT_FILE * GenerateOptionsFromEtcFstab(REFIT_VOLUME *Volume) {
          while ((TokenCount = ReadTokenLine(Fstab, &TokenList)) > 0) {
             if (TokenCount > 2) {
                Root[0] = '\0';
-               if (StriCmp(TokenList[1], L"\\") == 0) {
+               if (StrCmp(TokenList[1], L"\\") == 0) {
                   SPrint(Root, 99, L"%s", TokenList[0]);
-               } else if (StriCmp(TokenList[2], L"\\") == 0) {
+               } else if (StrCmp(TokenList[2], L"\\") == 0) {
                   SPrint(Root, 99, L"%s=%s", TokenList[0], TokenList[1]);
                } // if/elseif/elseif
                if (Root[0] != L'\0') {
index 416a1f1adf272723efd708e668498ed25aa5f904..92abfd04cc46f9e2f84e458696d1e5a875ac52b4 100644 (file)
@@ -866,8 +866,6 @@ static VOID SetPartGuidAndName(REFIT_VOLUME *Volume, EFI_DEVICE_PATH_PROTOCOL *D
              CopyMem(&(Volume->PartTypeGuid), PartInfo->type_guid, sizeof(EFI_GUID));
              if (GuidsAreEqual (&(Volume->PartTypeGuid), &gFreedesktopRootGuid)) {
                 GlobalConfig.DiscoveredRoot = Volume;
-                Print(L"Found match!\n");
-                PauseForKey();
              } // if (GUIDs match)
          } // if (PartInfo exists)
       } // if (GPT disk)
@@ -1424,14 +1422,6 @@ MetaiMatch (IN CHAR16 *String, IN CHAR16 *Pattern)
    return FALSE; // Shouldn't happen
 }
 
-static VOID StrLwr (IN OUT CHAR16 *Str) {
-   if (!mUnicodeCollation) {
-      InitializeUnicodeCollationProtocol();
-   }
-   if (mUnicodeCollation)
-      mUnicodeCollation->StrLwr (mUnicodeCollation, Str);
-}
-
 #endif
 
 BOOLEAN DirIterNext(IN OUT REFIT_DIR_ITER *DirIter, IN UINTN FilterMode, IN CHAR16 *FilePattern OPTIONAL,
@@ -1517,8 +1507,7 @@ CHAR16 * StripEfiExtension(CHAR16 *FileName) {
 
    if ((FileName != NULL) && ((Copy = StrDuplicate(FileName)) != NULL)) {
       Length = StrLen(Copy);
-      // Note: Do StriCmp() twice to work around Gigabyte Hybrid EFI case-sensitivity bug....
-      if ((Length >= 4) && ((StriCmp(&Copy[Length - 4], L".efi") == 0) || (StriCmp(&Copy[Length - 4], L".EFI") == 0))) {
+      if ((Length >= 4) && MyStriCmp(&Copy[Length - 4], L".efi")) {
          Copy[Length - 4] = 0;
       } // if
    } // if
@@ -1544,31 +1533,50 @@ INTN FindMem(IN VOID *Buffer, IN UINTN BufferLength, IN VOID *SearchString, IN U
     return -1;
 }
 
-// Performs a case-insensitive search of BigStr for SmallStr.
-// Returns TRUE if found, FALSE if not.
 BOOLEAN StriSubCmp(IN CHAR16 *SmallStr, IN CHAR16 *BigStr) {
-   CHAR16 *SmallCopy, *BigCopy;
-   BOOLEAN Found = FALSE;
-   UINTN StartPoint = 0, NumCompares = 0, SmallLen = 0;
-
-   if ((SmallStr != NULL) && (BigStr != NULL) && (StrLen(BigStr) >= StrLen(SmallStr))) {
-      SmallCopy = StrDuplicate(SmallStr);
-      BigCopy = StrDuplicate(BigStr);
-      StrLwr(SmallCopy);
-      StrLwr(BigCopy);
-      SmallLen = StrLen(SmallCopy);
-      NumCompares = StrLen(BigCopy) - SmallLen + 1;
-      while ((!Found) && (StartPoint < NumCompares)) {
-         Found = (StrnCmp(SmallCopy, &BigCopy[StartPoint++], SmallLen) == 0);
-      } // while
-      MyFreePool(SmallCopy);
-      MyFreePool(BigCopy);
-   } // if
+    BOOLEAN Found = 0, Terminate = 0;
+    UINTN BigIndex = 0, SmallIndex = 0, BigStart = 0;
 
-   return (Found);
+    if (SmallStr && BigStr) {
+        while (!Terminate) {
+            if (BigStr[BigIndex] == '\0') {
+                Terminate = 1;
+            }
+            if (SmallStr[SmallIndex] == '\0') {
+                Found = 1;
+                Terminate = 1;
+            }
+            if ((SmallStr[SmallIndex] & ~0x20) == (BigStr[BigIndex] & ~0x20)) {
+                SmallIndex++;
+                BigIndex++;
+            } else {
+                SmallIndex = 0;
+                BigStart++;
+                BigIndex = BigStart;
+            }
+        } // while
+    } // if
+    return Found;
 } // BOOLEAN StriSubCmp()
 
+// Performs a case-insensitive string comparison. This function is necesary
+// because some EFIs have buggy StriCmp() functions that actually perform
+// case-sensitive comparisons.
+// Returns TRUE if strings are identical, FALSE otherwise.
+BOOLEAN MyStriCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString) {
+    if (FirstString && SecondString) {
+        while ((*FirstString != L'\0') && ((*FirstString & ~0x20) == (*SecondString & ~0x20))) {
+                FirstString++;
+                SecondString++;
+        }
+        return (*FirstString == *SecondString);
+    } else {
+        return FALSE;
+    }
+} // BOOLEAN MyStriCmp()
+
 // Convert input string to all-lowercase.
+// DO NOT USE the standard StrLwr() function, since it's broken on some EFIs!
 VOID ToLower(CHAR16 * MyString) {
     UINTN i = 0;
 
@@ -1600,7 +1608,7 @@ 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)) {
+      if ((*First != NULL) && (Length1 == 0)) {
          MyFreePool(*First);
          *First = NULL;
       }
@@ -1619,7 +1627,35 @@ VOID MergeStrings(IN OUT CHAR16 **First, IN CHAR16 *Second, CHAR16 AddChar) {
    } else {
       Print(L"Error! Unable to allocate memory in MergeStrings()!\n");
    } // if/else
-} // static CHAR16* MergeStrings()
+} // VOID MergeStrings()
+
+// Similar to MergeStrings, but breaks the input string into word chunks and
+// merges each word separately. Words are defined as string fragments separated
+// by ' ', '_', or '-'.
+VOID MergeWords(CHAR16 **MergeTo, CHAR16 *SourceString, CHAR16 AddChar) {
+    CHAR16 *Temp, *Word, *p;
+    BOOLEAN LineFinished = FALSE;
+
+    if (SourceString) {
+        Temp = Word = p = StrDuplicate(SourceString);
+        if (Temp) {
+            while (!LineFinished) {
+                if ((*p == L' ') || (*p == L'_') || (*p == L'-') || (*p == L'\0')) {
+                    if (*p == L'\0')
+                        LineFinished = TRUE;
+                    *p = L'\0';
+                    if (*Word != L'\0')
+                        MergeStrings(MergeTo, Word, AddChar);
+                    Word = p + 1;
+                } // if
+                p++;
+            } // while
+            MyFreePool(Temp);
+        } else {
+            Print(L"Error! Unable to allocate memory in MergeWords()!\n");
+        } // if/else
+    } // if
+} // VOID MergeWords()
 
 // Takes an input pathname (*Path) and returns the part of the filename from
 // the final dot onwards, converted to lowercase. If the filename includes
@@ -1644,7 +1680,7 @@ CHAR16 *FindExtension(IN CHAR16 *Path) {
       } // while
       if (Found) {
          MergeStrings(&Extension, &Path[i], 0);
-         StrLwr(Extension);
+         ToLower(Extension);
       } // if (Found)
    } // if
    return (Extension);
@@ -1804,7 +1840,7 @@ VOID FindVolumeAndFilename(IN EFI_DEVICE_PATH *loadpath, OUT REFIT_VOLUME **Devi
    while ((i < VolumesCount) && (!Found)) {
       VolumeDeviceString = DevicePathToStr(Volumes[i]->DevicePath);
       Temp = SplitDeviceString(VolumeDeviceString);
-      if (StriCmp(DeviceString, VolumeDeviceString) == 0) {
+      if (MyStriCmp(DeviceString, VolumeDeviceString)) {
          Found = TRUE;
          *DeviceVolume = Volumes[i];
       }
@@ -1972,8 +2008,7 @@ VOID SplitPathName(CHAR16 *InPath, CHAR16 **VolName, CHAR16 **Path, CHAR16 **Fil
 } // VOID SplitPathName
 
 // 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).
+// FALSE otherwise. Performs comparison case-insensitively.
 BOOLEAN IsIn(IN CHAR16 *SmallString, IN CHAR16 *List) {
    UINTN     i = 0;
    BOOLEAN   Found = FALSE;
@@ -1981,7 +2016,7 @@ BOOLEAN IsIn(IN CHAR16 *SmallString, IN CHAR16 *List) {
 
    if (SmallString && List) {
       while (!Found && (OneElement = FindCommaDelimited(List, i++))) {
-         if (StriCmp(OneElement, SmallString) == 0)
+         if (MyStriCmp(OneElement, SmallString))
             Found = TRUE;
       } // while
    } // if
@@ -2009,8 +2044,7 @@ BOOLEAN IsInSubstring(IN CHAR16 *BigString, IN CHAR16 *List) {
 // element in the comma-delimited List, FALSE otherwise. Note that Directory and
 // Filename must *NOT* include a volume or path specification (that's part of
 // the Volume variable), but the List elements may. Performs comparison
-// case-insensitively (except on buggy EFIs with case-sensitive StriCmp()
-// functions).
+// case-insensitively.
 BOOLEAN FilenameIn(REFIT_VOLUME *Volume, CHAR16 *Directory, CHAR16 *Filename, CHAR16 *List) {
    UINTN     i = 0;
    BOOLEAN   Found = FALSE;
@@ -2022,9 +2056,9 @@ BOOLEAN FilenameIn(REFIT_VOLUME *Volume, CHAR16 *Directory, CHAR16 *Filename, CH
          Found = TRUE;
          SplitPathName(OneElement, &TargetVolName, &TargetPath, &TargetFilename);
          VolumeNumberToName(Volume, &TargetVolName);
-         if (((TargetVolName != NULL) && ((Volume == NULL) || (StriCmp(TargetVolName, Volume->VolName) != 0))) ||
-             ((TargetPath != NULL) && (StriCmp(TargetPath, Directory) != 0)) ||
-             ((TargetFilename != NULL) && (StriCmp(TargetFilename, Filename) != 0))) {
+         if (((TargetVolName != NULL) && ((Volume == NULL) || (!MyStriCmp(TargetVolName, Volume->VolName)))) ||
+             ((TargetPath != NULL) && (!MyStriCmp(TargetPath, Directory))) ||
+             ((TargetFilename != NULL) && (!MyStriCmp(TargetFilename, Filename)))) {
             Found = FALSE;
          } // if
          MyFreePool(OneElement);
index 93a2ea4daefe80f4ac46367f9183ef893e155605..552b11f9d0ba5d78eb340eddd67d4678aea41d1a 100644 (file)
@@ -116,8 +116,10 @@ INTN FindMem(IN VOID *Buffer, IN UINTN BufferLength, IN VOID *SearchString, IN U
 VOID ReinitVolumes(VOID);
 
 BOOLEAN StriSubCmp(IN CHAR16 *TargetStr, IN CHAR16 *BigStr);
+BOOLEAN MyStriCmp(IN CONST CHAR16 *String1, IN CONST CHAR16 *String2);
 VOID ToLower(CHAR16 * MyString);
 VOID MergeStrings(IN OUT CHAR16 **First, IN CHAR16 *Second, CHAR16 AddChar);
+VOID MergeWords(CHAR16 **MergeTo, CHAR16 *InString, CHAR16 AddChar);
 CHAR16 *FindExtension(IN CHAR16 *Path);
 CHAR16 *FindLastDirName(IN CHAR16 *Path);
 CHAR16 *FindPath(IN CHAR16* FullPath);
index 8228a686264e0b38ed19dd4a11ada0e46517f057..6112b243a71ab1518aca96efd483d3057db0c030 100644 (file)
@@ -158,9 +158,9 @@ 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 {
-   CHAR16              *FileName;
-   EFI_TIME            TimeStamp;
-   struct LOADER_LIST  *NextEntry;
+    CHAR16              *FileName;
+    EFI_TIME            TimeStamp;
+    struct LOADER_LIST  *NextEntry;
 };
 
 //
@@ -173,7 +173,7 @@ static VOID AboutrEFInd(VOID)
 
     if (AboutMenu.EntryCount == 0) {
         AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
-        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.9.0");
+        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.9.0.3");
         AddMenuInfoLine(&AboutMenu, L"");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012-2015 Roderick W. Smith");
@@ -212,24 +212,24 @@ static VOID AboutrEFInd(VOID)
 } /* VOID AboutrEFInd() */
 
 static VOID WarnSecureBootError(CHAR16 *Name, BOOLEAN Verbose) {
-   if (Name == NULL)
-      Name = L"the loader";
-
-   refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_ERROR);
-   Print(L"Secure Boot validation failure loading %s!\n", Name);
-   refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_BASIC);
-   if (Verbose && secure_mode()) {
-      Print(L"\nThis computer is configured with Secure Boot active, but\n%s has failed validation.\n", Name);
-      Print(L"\nYou can:\n * Launch another boot loader\n");
-      Print(L" * Disable Secure Boot in your firmware\n");
-      Print(L" * Sign %s with a machine owner key (MOK)\n", Name);
-      Print(L" * Use a MOK utility (often present on the second row) to add a MOK with which\n");
-      Print(L"   %s has already been signed.\n", Name);
-      Print(L" * Use a MOK utility to register %s (\"enroll its hash\") without\n", Name);
-      Print(L"   signing it.\n");
-      Print(L"\nSee http://www.rodsbooks.com/refind/secureboot.html for more information\n");
-      PauseForKey();
-   } // if
+    if (Name == NULL)
+        Name = L"the loader";
+
+    refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_ERROR);
+    Print(L"Secure Boot validation failure loading %s!\n", Name);
+    refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_BASIC);
+    if (Verbose && secure_mode()) {
+        Print(L"\nThis computer is configured with Secure Boot active, but\n%s has failed validation.\n", Name);
+        Print(L"\nYou can:\n * Launch another boot loader\n");
+        Print(L" * Disable Secure Boot in your firmware\n");
+        Print(L" * Sign %s with a machine owner key (MOK)\n", Name);
+        Print(L" * Use a MOK utility (often present on the second row) to add a MOK with which\n");
+        Print(L"   %s has already been signed.\n", Name);
+        Print(L" * Use a MOK utility to register %s (\"enroll its hash\") without\n", Name);
+        Print(L"   signing it.\n");
+        Print(L"\nSee http://www.rodsbooks.com/refind/secureboot.html for more information\n");
+        PauseForKey();
+    } // if
 } // VOID WarnSecureBootError()
 
 // Returns TRUE if this file is a valid EFI loader file, and is proper ARCH
@@ -242,15 +242,15 @@ static BOOLEAN IsValidLoader(EFI_FILE *RootDir, CHAR16 *FileName) {
     UINTN           Size = sizeof(Header);
 
     if ((RootDir == NULL) || (FileName == NULL)) {
-       // Assume valid here, because Macs produce NULL RootDir (& maybe FileName)
-       // when launching from a Firewire drive. This should be handled better, but
-       // fix would have to be in StartEFIImageList() and/or in FindVolumeAndFilename().
-       return TRUE;
+        // Assume valid here, because Macs produce NULL RootDir (& maybe FileName)
+        // when launching from a Firewire drive. This should be handled better, but
+        // fix would have to be in StartEFIImageList() and/or in FindVolumeAndFilename().
+        return TRUE;
     } // if
 
     Status = refit_call5_wrapper(RootDir->Open, RootDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0);
     if (EFI_ERROR(Status))
-       return FALSE;
+        return FALSE;
 
     Status = refit_call3_wrapper(FileHandle->Read, FileHandle, &Size, Header);
     refit_call1_wrapper(FileHandle->Close, FileHandle);
@@ -290,52 +290,52 @@ EFI_STATUS StartEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
 
     // set load options
     if (LoadOptions != NULL) {
-       FullLoadOptions = StrDuplicate(LoadOptions);
-       if ((LoaderType == TYPE_EFI) && (OSType == 'M')) {
-           MergeStrings(&FullLoadOptions, L" ", 0);
-           // NOTE: That last space is also added by the EFI shell and seems to be significant
-           // when passing options to Apple's boot.efi...
+        FullLoadOptions = StrDuplicate(LoadOptions);
+        if ((LoaderType == TYPE_EFI) && (OSType == 'M')) {
+            MergeStrings(&FullLoadOptions, L" ", 0);
+            // NOTE: That last space is also added by the EFI shell and seems to be significant
+            // when passing options to Apple's boot.efi...
         } // if
     } // if (LoadOptions != NULL)
     if (Verbose)
-       Print(L"Starting %s\nUsing load options '%s'\n", ImageTitle, FullLoadOptions ? FullLoadOptions : L"");
+    Print(L"Starting %s\nUsing load options '%s'\n", ImageTitle, FullLoadOptions ? FullLoadOptions : L"");
 
     // load the image into memory (and execute it, in the case of a shim/MOK image).
     ReturnStatus = Status = EFI_NOT_FOUND;  // in case the list is empty
     for (DevicePathIndex = 0; DevicePaths[DevicePathIndex] != NULL; DevicePathIndex++) {
-       FindVolumeAndFilename(DevicePaths[DevicePathIndex], &Volume, &Filename);
-       // Some EFIs crash if attempting to load driver for invalid architecture, so
-       // protect for this condition; but sometimes Volume comes back NULL, so provide
-       // an exception. (TODO: Handle this special condition better.)
-       if ((LoaderType == TYPE_LEGACY) || (Volume == NULL) || IsValidLoader(Volume->RootDir, Filename)) {
-          if (Filename && (LoaderType != TYPE_LEGACY)) {
-             Temp = PoolPrint(L"\\%s %s", Filename, FullLoadOptions ? FullLoadOptions : L"");
-             if (Temp != NULL) {
-                MyFreePool(FullLoadOptions);
-                FullLoadOptions = Temp;
-             }
-          } // if (Filename)
-
-          // NOTE: Below commented-out line could be more efficient if file were read ahead of
-          // time and passed as a pre-loaded image to LoadImage(), but it doesn't work on my
-          // 32-bit Mac Mini or my 64-bit Intel box when launching a Linux kernel; the
-          // kernel returns a "Failed to handle fs_proto" error message.
-          // TODO: Track down the cause of this error and fix it, if possible.
-          // ReturnStatus = Status = refit_call6_wrapper(BS->LoadImage, FALSE, SelfImageHandle, DevicePaths[DevicePathIndex],
-          //                                            ImageData, ImageSize, &ChildImageHandle);
-          ReturnStatus = Status = refit_call6_wrapper(BS->LoadImage, FALSE, SelfImageHandle, DevicePaths[DevicePathIndex],
-                                                      NULL, 0, &ChildImageHandle);
-       } else {
-          Print(L"Invalid loader file!\n");
-          ReturnStatus = EFI_LOAD_ERROR;
-       }
-       if (ReturnStatus != EFI_NOT_FOUND) {
-          break;
-       }
-    }
+        FindVolumeAndFilename(DevicePaths[DevicePathIndex], &Volume, &Filename);
+        // Some EFIs crash if attempting to load driver for invalid architecture, so
+        // protect for this condition; but sometimes Volume comes back NULL, so provide
+        // an exception. (TODO: Handle this special condition better.)
+        if ((LoaderType == TYPE_LEGACY) || (Volume == NULL) || IsValidLoader(Volume->RootDir, Filename)) {
+            if (Filename && (LoaderType != TYPE_LEGACY)) {
+                Temp = PoolPrint(L"\\%s %s", Filename, FullLoadOptions ? FullLoadOptions : L"");
+                if (Temp != NULL) {
+                    MyFreePool(FullLoadOptions);
+                    FullLoadOptions = Temp;
+                }
+            } // if (Filename)
+
+            // NOTE: Below commented-out line could be more efficient if file were read ahead of
+            // time and passed as a pre-loaded image to LoadImage(), but it doesn't work on my
+            // 32-bit Mac Mini or my 64-bit Intel box when launching a Linux kernel; the
+            // kernel returns a "Failed to handle fs_proto" error message.
+            // TODO: Track down the cause of this error and fix it, if possible.
+            // ReturnStatus = Status = refit_call6_wrapper(BS->LoadImage, FALSE, SelfImageHandle, DevicePaths[DevicePathIndex],
+            //                                            ImageData, ImageSize, &ChildImageHandle);
+            ReturnStatus = Status = refit_call6_wrapper(BS->LoadImage, FALSE, SelfImageHandle, DevicePaths[DevicePathIndex],
+                                                        NULL, 0, &ChildImageHandle);
+        } else {
+            Print(L"Invalid loader file!\n");
+            ReturnStatus = EFI_LOAD_ERROR;
+        }
+        if (ReturnStatus != EFI_NOT_FOUND) {
+            break;
+        }
+    } // for
     if ((Status == EFI_ACCESS_DENIED) || (Status == EFI_SECURITY_VIOLATION)) {
-       WarnSecureBootError(ImageTitle, Verbose);
-       goto bailout;
+        WarnSecureBootError(ImageTitle, Verbose);
+        goto bailout;
     }
     SPrint(ErrorInfo, 255, L"while loading %s", ImageTitle);
     if (CheckError(Status, ErrorInfo)) {
@@ -347,9 +347,9 @@ EFI_STATUS StartEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
     ReturnStatus = Status = refit_call3_wrapper(BS->HandleProtocol, ChildImageHandle, &LoadedImageProtocol,
                                                 (VOID **) &ChildLoadedImage);
     if (CheckError(Status, L"while getting a LoadedImageProtocol handle")) {
-       if (ErrorInStep != NULL)
-          *ErrorInStep = 2;
-       goto bailout_unload;
+        if (ErrorInStep != NULL)
+            *ErrorInStep = 2;
+        goto bailout_unload;
     }
     ChildLoadedImage->LoadOptions = (VOID *)FullLoadOptions;
     ChildLoadedImage->LoadOptionsSize = FullLoadOptions ? ((UINT32)StrLen(FullLoadOptions) + 1) * sizeof(CHAR16) : 0;
@@ -373,7 +373,7 @@ EFI_STATUS StartEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
 bailout_unload:
     // unload the image, we don't care if it works or not...
     if (!IsDriver)
-       Status = refit_call1_wrapper(BS->UnloadImage, ChildImageHandle);
+        Status = refit_call1_wrapper(BS->UnloadImage, ChildImageHandle);
 
 bailout:
     MyFreePool(FullLoadOptions);
@@ -397,42 +397,42 @@ static EFI_STATUS StartEFIImage(IN EFI_DEVICE_PATH *DevicePath,
 
 // From gummiboot: Reboot the computer into its built-in user interface
 static EFI_STATUS RebootIntoFirmware(VOID) {
-   CHAR8 *b;
-   UINTN size;
-   UINT64 osind;
-   EFI_STATUS err;
-
-   osind = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
-
-   err = EfivarGetRaw(&GlobalGuid, L"OsIndications", &b, &size);
-   if (err == EFI_SUCCESS)
-      osind |= (UINT64)*b;
-   MyFreePool(b);
-
-   err = EfivarSetRaw(&GlobalGuid, L"OsIndications", (CHAR8 *)&osind, sizeof(UINT64), TRUE);
-   if (err != EFI_SUCCESS)
-      return err;
-
-   refit_call4_wrapper(RT->ResetSystem, EfiResetCold, EFI_SUCCESS, 0, NULL);
-   Print(L"Error calling ResetSystem: %r", err);
-   PauseForKey();
-   return err;
+    CHAR8 *b;
+    UINTN size;
+    UINT64 osind;
+    EFI_STATUS err;
+
+    osind = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
+
+    err = EfivarGetRaw(&GlobalGuid, L"OsIndications", &b, &size);
+    if (err == EFI_SUCCESS)
+        osind |= (UINT64)*b;
+    MyFreePool(b);
+
+    err = EfivarSetRaw(&GlobalGuid, L"OsIndications", (CHAR8 *)&osind, sizeof(UINT64), TRUE);
+    if (err != EFI_SUCCESS)
+        return err;
+
+    refit_call4_wrapper(RT->ResetSystem, EfiResetCold, EFI_SUCCESS, 0, NULL);
+    Print(L"Error calling ResetSystem: %r", err);
+    PauseForKey();
+    return err;
 }
 
 // Record the value of the loader's name/description in rEFInd's "PreviousBoot" EFI variable,
 // if it's different from what's already stored there.
 VOID StoreLoaderName(IN CHAR16 *Name) {
-   EFI_STATUS   Status;
-   CHAR16       *OldName = NULL;
-   UINTN        Length;
-
-   if (Name) {
-      Status = EfivarGetRaw(&RefindGuid, L"PreviousBoot", (CHAR8**) &OldName, &Length);
-      if ((Status != EFI_SUCCESS) || (StrCmp(OldName, Name) != 0)) {
-         EfivarSetRaw(&RefindGuid, L"PreviousBoot", (CHAR8*) Name, StrLen(Name) * 2 + 2, TRUE);
-      } // if
-      MyFreePool(OldName);
-   } // if
+    EFI_STATUS   Status;
+    CHAR16       *OldName = NULL;
+    UINTN        Length;
+
+    if (Name) {
+        Status = EfivarGetRaw(&RefindGuid, L"PreviousBoot", (CHAR8**) &OldName, &Length);
+        if ((Status != EFI_SUCCESS) || (StrCmp(OldName, Name) != 0)) {
+            EfivarSetRaw(&RefindGuid, L"PreviousBoot", (CHAR8*) Name, StrLen(Name) * 2 + 2, TRUE);
+        } // if
+        MyFreePool(OldName);
+    } // if
 } // VOID StoreLoaderName()
 
 //
@@ -485,80 +485,80 @@ static VOID StartLoader(LOADER_ENTRY *Entry, CHAR16 *SelectionName)
 // the kernel's directory.
 // If no matching init file can be found, returns NULL.
 static CHAR16 * FindInitrd(IN CHAR16 *LoaderPath, IN REFIT_VOLUME *Volume) {
-   CHAR16              *InitrdName = NULL, *FileName, *KernelVersion, *InitrdVersion, *Path;
-   REFIT_DIR_ITER      DirIter;
-   EFI_FILE_INFO       *DirEntry;
-
-   FileName = Basename(LoaderPath);
-   KernelVersion = FindNumbers(FileName);
-   Path = FindPath(LoaderPath);
-
-   // Add trailing backslash for root directory; necessary on some systems, but must
-   // NOT be added to all directories, since on other systems, a trailing backslash on
-   // anything but the root directory causes them to flake out!
-   if (StrLen(Path) == 0) {
-      MergeStrings(&Path, L"\\", 0);
-   } // if
-   DirIterOpen(Volume->RootDir, Path, &DirIter);
-   // Now add a trailing backslash if it was NOT added earlier, for consistency in
-   // building the InitrdName later....
-   if ((StrLen(Path) > 0) && (Path[StrLen(Path) - 1] != L'\\'))
-      MergeStrings(&Path, L"\\", 0);
-   while ((DirIterNext(&DirIter, 2, L"init*", &DirEntry)) && (InitrdName == NULL)) {
-      InitrdVersion = FindNumbers(DirEntry->FileName);
-      if (KernelVersion != NULL) {
-         if (StriCmp(InitrdVersion, KernelVersion) == 0) {
-            InitrdName = PoolPrint(L"%s%s", Path, DirEntry->FileName);
-         } // if
-      } else {
-         if (InitrdVersion == NULL) {
-            InitrdName = PoolPrint(L"%s%s", Path, DirEntry->FileName);
-         } // if
-      } // if/else
-      MyFreePool(InitrdVersion);
-   } // while
-   DirIterClose(&DirIter);
-
-   // Note: Don't FreePool(FileName), since Basename returns a pointer WITHIN the string it's passed.
-   MyFreePool(KernelVersion);
-   MyFreePool(Path);
-   return (InitrdName);
+    CHAR16              *InitrdName = NULL, *FileName, *KernelVersion, *InitrdVersion, *Path;
+    REFIT_DIR_ITER      DirIter;
+    EFI_FILE_INFO       *DirEntry;
+
+    FileName = Basename(LoaderPath);
+    KernelVersion = FindNumbers(FileName);
+    Path = FindPath(LoaderPath);
+
+    // Add trailing backslash for root directory; necessary on some systems, but must
+    // NOT be added to all directories, since on other systems, a trailing backslash on
+    // anything but the root directory causes them to flake out!
+    if (StrLen(Path) == 0) {
+        MergeStrings(&Path, L"\\", 0);
+    } // if
+    DirIterOpen(Volume->RootDir, Path, &DirIter);
+    // Now add a trailing backslash if it was NOT added earlier, for consistency in
+    // building the InitrdName later....
+    if ((StrLen(Path) > 0) && (Path[StrLen(Path) - 1] != L'\\'))
+        MergeStrings(&Path, L"\\", 0);
+    while ((DirIterNext(&DirIter, 2, L"init*", &DirEntry)) && (InitrdName == NULL)) {
+        InitrdVersion = FindNumbers(DirEntry->FileName);
+        if (KernelVersion != NULL) {
+            if (MyStriCmp(InitrdVersion, KernelVersion)) {
+                InitrdName = PoolPrint(L"%s%s", Path, DirEntry->FileName);
+            } // if
+        } else {
+            if (InitrdVersion == NULL) {
+                InitrdName = PoolPrint(L"%s%s", Path, DirEntry->FileName);
+            } // if
+        } // if/else
+        MyFreePool(InitrdVersion);
+    } // while
+    DirIterClose(&DirIter);
+
+    // Note: Don't FreePool(FileName), since Basename returns a pointer WITHIN the string it's passed.
+    MyFreePool(KernelVersion);
+    MyFreePool(Path);
+    return (InitrdName);
 } // static CHAR16 * FindInitrd()
 
 LOADER_ENTRY * AddPreparedLoaderEntry(LOADER_ENTRY *Entry) {
-   AddMenuEntry(&MainMenu, (REFIT_MENU_ENTRY *)Entry);
+    AddMenuEntry(&MainMenu, (REFIT_MENU_ENTRY *)Entry);
 
-   return(Entry);
+    return(Entry);
 } // LOADER_ENTRY * AddPreparedLoaderEntry()
 
 // Creates a copy of a menu screen.
 // Returns a pointer to the copy of the menu screen.
 static REFIT_MENU_SCREEN* CopyMenuScreen(REFIT_MENU_SCREEN *Entry) {
-   REFIT_MENU_SCREEN *NewEntry;
-   UINTN i;
-
-   NewEntry = AllocateZeroPool(sizeof(REFIT_MENU_SCREEN));
-   if ((Entry != NULL) && (NewEntry != NULL)) {
-      CopyMem(NewEntry, Entry, sizeof(REFIT_MENU_SCREEN));
-      NewEntry->Title = (Entry->Title) ? StrDuplicate(Entry->Title) : NULL;
-      NewEntry->TimeoutText = (Entry->TimeoutText) ? StrDuplicate(Entry->TimeoutText) : NULL;
-      if (Entry->TitleImage != NULL) {
-         NewEntry->TitleImage = AllocatePool(sizeof(EG_IMAGE));
-         if (NewEntry->TitleImage != NULL)
-            CopyMem(NewEntry->TitleImage, Entry->TitleImage, sizeof(EG_IMAGE));
-      } // if
-      NewEntry->InfoLines = (CHAR16**) AllocateZeroPool(Entry->InfoLineCount * (sizeof(CHAR16*)));
-      for (i = 0; i < Entry->InfoLineCount && NewEntry->InfoLines; i++) {
-         NewEntry->InfoLines[i] = (Entry->InfoLines[i]) ? StrDuplicate(Entry->InfoLines[i]) : NULL;
-      } // for
-      NewEntry->Entries = (REFIT_MENU_ENTRY**) AllocateZeroPool(Entry->EntryCount * (sizeof (REFIT_MENU_ENTRY*)));
-      for (i = 0; i < Entry->EntryCount && NewEntry->Entries; i++) {
-         AddMenuEntry(NewEntry, Entry->Entries[i]);
-      } // for
-      NewEntry->Hint1 = (Entry->Hint1) ? StrDuplicate(Entry->Hint1) : NULL;
-      NewEntry->Hint2 = (Entry->Hint2) ? StrDuplicate(Entry->Hint2) : NULL;
-   } // if
-   return (NewEntry);
+    REFIT_MENU_SCREEN *NewEntry;
+    UINTN i;
+
+    NewEntry = AllocateZeroPool(sizeof(REFIT_MENU_SCREEN));
+    if ((Entry != NULL) && (NewEntry != NULL)) {
+        CopyMem(NewEntry, Entry, sizeof(REFIT_MENU_SCREEN));
+        NewEntry->Title = (Entry->Title) ? StrDuplicate(Entry->Title) : NULL;
+        NewEntry->TimeoutText = (Entry->TimeoutText) ? StrDuplicate(Entry->TimeoutText) : NULL;
+        if (Entry->TitleImage != NULL) {
+            NewEntry->TitleImage = AllocatePool(sizeof(EG_IMAGE));
+            if (NewEntry->TitleImage != NULL)
+                CopyMem(NewEntry->TitleImage, Entry->TitleImage, sizeof(EG_IMAGE));
+        } // if
+        NewEntry->InfoLines = (CHAR16**) AllocateZeroPool(Entry->InfoLineCount * (sizeof(CHAR16*)));
+        for (i = 0; i < Entry->InfoLineCount && NewEntry->InfoLines; i++) {
+            NewEntry->InfoLines[i] = (Entry->InfoLines[i]) ? StrDuplicate(Entry->InfoLines[i]) : NULL;
+        } // for
+        NewEntry->Entries = (REFIT_MENU_ENTRY**) AllocateZeroPool(Entry->EntryCount * (sizeof (REFIT_MENU_ENTRY*)));
+        for (i = 0; i < Entry->EntryCount && NewEntry->Entries; i++) {
+            AddMenuEntry(NewEntry, Entry->Entries[i]);
+        } // for
+        NewEntry->Hint1 = (Entry->Hint1) ? StrDuplicate(Entry->Hint1) : NULL;
+        NewEntry->Hint2 = (Entry->Hint2) ? StrDuplicate(Entry->Hint2) : NULL;
+    } // if
+    return (NewEntry);
 } // static REFIT_MENU_SCREEN* CopyMenuScreen()
 
 // Creates a copy of a menu entry. Intended to enable moving a stack-based
@@ -567,27 +567,27 @@ static REFIT_MENU_SCREEN* CopyMenuScreen(REFIT_MENU_SCREEN *Entry) {
 // entries when re-scanning.
 // Returns a pointer to the copy of the menu entry.
 static REFIT_MENU_ENTRY* CopyMenuEntry(REFIT_MENU_ENTRY *Entry) {
-   REFIT_MENU_ENTRY *NewEntry;
-
-   NewEntry = AllocateZeroPool(sizeof(REFIT_MENU_ENTRY));
-   if ((Entry != NULL) && (NewEntry != NULL)) {
-      CopyMem(NewEntry, Entry, sizeof(REFIT_MENU_ENTRY));
-      NewEntry->Title = (Entry->Title) ? StrDuplicate(Entry->Title) : NULL;
-      if (Entry->BadgeImage != NULL) {
-         NewEntry->BadgeImage = AllocatePool(sizeof(EG_IMAGE));
-         if (NewEntry->BadgeImage != NULL)
-            CopyMem(NewEntry->BadgeImage, Entry->BadgeImage, sizeof(EG_IMAGE));
-      }
-      if (Entry->Image != NULL) {
-         NewEntry->Image = AllocatePool(sizeof(EG_IMAGE));
-         if (NewEntry->Image != NULL)
-            CopyMem(NewEntry->Image, Entry->Image, sizeof(EG_IMAGE));
-      }
-      if (Entry->SubScreen != NULL) {
-         NewEntry->SubScreen = CopyMenuScreen(Entry->SubScreen);
-      }
-   } // if
-   return (NewEntry);
+    REFIT_MENU_ENTRY *NewEntry;
+
+    NewEntry = AllocateZeroPool(sizeof(REFIT_MENU_ENTRY));
+    if ((Entry != NULL) && (NewEntry != NULL)) {
+        CopyMem(NewEntry, Entry, sizeof(REFIT_MENU_ENTRY));
+        NewEntry->Title = (Entry->Title) ? StrDuplicate(Entry->Title) : NULL;
+        if (Entry->BadgeImage != NULL) {
+            NewEntry->BadgeImage = AllocatePool(sizeof(EG_IMAGE));
+            if (NewEntry->BadgeImage != NULL)
+                CopyMem(NewEntry->BadgeImage, Entry->BadgeImage, sizeof(EG_IMAGE));
+        }
+        if (Entry->Image != NULL) {
+            NewEntry->Image = AllocatePool(sizeof(EG_IMAGE));
+            if (NewEntry->Image != NULL)
+                CopyMem(NewEntry->Image, Entry->Image, sizeof(EG_IMAGE));
+        }
+        if (Entry->SubScreen != NULL) {
+            NewEntry->SubScreen = CopyMenuScreen(Entry->SubScreen);
+        }
+    } // if
+    return (NewEntry);
 } // REFIT_MENU_ENTRY* CopyMenuEntry()
 
 // Creates a new LOADER_ENTRY data structure and populates it with
@@ -596,25 +596,25 @@ static REFIT_MENU_ENTRY* CopyMenuEntry(REFIT_MENU_ENTRY *Entry) {
 // Returns a pointer to the new data structure, or NULL if it
 // couldn't be allocated
 LOADER_ENTRY *InitializeLoaderEntry(IN LOADER_ENTRY *Entry) {
-   LOADER_ENTRY *NewEntry = NULL;
-
-   NewEntry = AllocateZeroPool(sizeof(LOADER_ENTRY));
-   if (NewEntry != NULL) {
-      NewEntry->me.Title        = NULL;
-      NewEntry->me.Tag          = TAG_LOADER;
-      NewEntry->Enabled         = TRUE;
-      NewEntry->UseGraphicsMode = FALSE;
-      NewEntry->OSType          = 0;
-      if (Entry != NULL) {
-         NewEntry->LoaderPath      = (Entry->LoaderPath) ? StrDuplicate(Entry->LoaderPath) : NULL;
-         NewEntry->VolName         = (Entry->VolName) ? StrDuplicate(Entry->VolName) : NULL;
-         NewEntry->DevicePath      = Entry->DevicePath;
-         NewEntry->UseGraphicsMode = Entry->UseGraphicsMode;
-         NewEntry->LoadOptions     = (Entry->LoadOptions) ? StrDuplicate(Entry->LoadOptions) : NULL;
-         NewEntry->InitrdPath      = (Entry->InitrdPath) ? StrDuplicate(Entry->InitrdPath) : NULL;
-      }
-   } // if
-   return (NewEntry);
+    LOADER_ENTRY *NewEntry = NULL;
+
+    NewEntry = AllocateZeroPool(sizeof(LOADER_ENTRY));
+    if (NewEntry != NULL) {
+        NewEntry->me.Title        = NULL;
+        NewEntry->me.Tag          = TAG_LOADER;
+        NewEntry->Enabled         = TRUE;
+        NewEntry->UseGraphicsMode = FALSE;
+        NewEntry->OSType          = 0;
+        if (Entry != NULL) {
+            NewEntry->LoaderPath      = (Entry->LoaderPath) ? StrDuplicate(Entry->LoaderPath) : NULL;
+            NewEntry->VolName         = (Entry->VolName) ? StrDuplicate(Entry->VolName) : NULL;
+            NewEntry->DevicePath      = Entry->DevicePath;
+            NewEntry->UseGraphicsMode = Entry->UseGraphicsMode;
+            NewEntry->LoadOptions     = (Entry->LoadOptions) ? StrDuplicate(Entry->LoadOptions) : NULL;
+            NewEntry->InitrdPath      = (Entry->InitrdPath) ? StrDuplicate(Entry->InitrdPath) : NULL;
+        }
+    } // if
+    return (NewEntry);
 } // LOADER_ENTRY *InitializeLoaderEntry()
 
 // Adds InitrdPath to Options, but only if Options doesn't already include an
@@ -623,15 +623,15 @@ LOADER_ENTRY *InitializeLoaderEntry(IN LOADER_ENTRY *Entry) {
 // Returns a pointer to a new string. The calling function is responsible for
 // freeing its memory.
 static CHAR16 *AddInitrdToOptions(CHAR16 *Options, CHAR16 *InitrdPath) {
-   CHAR16 *NewOptions = NULL;
-
-   if (Options != NULL)
-      NewOptions = StrDuplicate(Options);
-   if ((InitrdPath != NULL) && !StriSubCmp(L"initrd=", Options)) {
-      MergeStrings(&NewOptions, L"initrd=", L' ');
-      MergeStrings(&NewOptions, InitrdPath, 0);
-   }
-   return NewOptions;
+    CHAR16 *NewOptions = NULL;
+
+    if (Options != NULL)
+        NewOptions = StrDuplicate(Options);
+    if ((InitrdPath != NULL) && !StriSubCmp(L"initrd=", Options)) {
+        MergeStrings(&NewOptions, L"initrd=", L' ');
+        MergeStrings(&NewOptions, InitrdPath, 0);
+    }
+    return NewOptions;
 } // CHAR16 *AddInitrdToOptions()
 
 // Prepare a REFIT_MENU_SCREEN data structure for a subscreen entry. This sets up
@@ -642,427 +642,424 @@ static CHAR16 *AddInitrdToOptions(CHAR16 *Options, CHAR16 *InitrdPath) {
 // Returns a pointer to the new subscreen data structure, or NULL if there
 // were problems allocating memory.
 REFIT_MENU_SCREEN *InitializeSubScreen(IN LOADER_ENTRY *Entry) {
-   CHAR16              *FileName, *MainOptions = NULL;
-   REFIT_MENU_SCREEN   *SubScreen = NULL;
-   LOADER_ENTRY        *SubEntry;
-
-   FileName = Basename(Entry->LoaderPath);
-   if (Entry->me.SubScreen == NULL) { // No subscreen yet; initialize default entry....
-      SubScreen = AllocateZeroPool(sizeof(REFIT_MENU_SCREEN));
-      if (SubScreen != NULL) {
-         SubScreen->Title = AllocateZeroPool(sizeof(CHAR16) * 256);
-         SPrint(SubScreen->Title, 255, L"Boot Options for %s on %s",
-                (Entry->Title != NULL) ? Entry->Title : FileName, Entry->VolName);
-         SubScreen->TitleImage = Entry->me.Image;
-         // default entry
-         SubEntry = InitializeLoaderEntry(Entry);
-         if (SubEntry != NULL) {
-            SubEntry->me.Title = StrDuplicate(L"Boot using default options");
-            MainOptions = SubEntry->LoadOptions;
-            SubEntry->LoadOptions = AddInitrdToOptions(MainOptions, SubEntry->InitrdPath);
-            MyFreePool(MainOptions);
-            AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-         } // if (SubEntry != NULL)
-         SubScreen->Hint1 = StrDuplicate(SUBSCREEN_HINT1);
-         if (GlobalConfig.HideUIFlags & HIDEUI_FLAG_EDITOR) {
-            SubScreen->Hint2 = StrDuplicate(SUBSCREEN_HINT2_NO_EDITOR);
-         } else {
-            SubScreen->Hint2 = StrDuplicate(SUBSCREEN_HINT2);
-         } // if/else
-      } // if (SubScreen != NULL)
-   } else { // existing subscreen; less initialization, and just add new entry later....
-      SubScreen = Entry->me.SubScreen;
-   } // if/else
-   return SubScreen;
+    CHAR16              *FileName, *MainOptions = NULL;
+    REFIT_MENU_SCREEN   *SubScreen = NULL;
+    LOADER_ENTRY        *SubEntry;
+
+    FileName = Basename(Entry->LoaderPath);
+    if (Entry->me.SubScreen == NULL) { // No subscreen yet; initialize default entry....
+        SubScreen = AllocateZeroPool(sizeof(REFIT_MENU_SCREEN));
+        if (SubScreen != NULL) {
+            SubScreen->Title = AllocateZeroPool(sizeof(CHAR16) * 256);
+            SPrint(SubScreen->Title, 255, L"Boot Options for %s on %s",
+                   (Entry->Title != NULL) ? Entry->Title : FileName, Entry->VolName);
+            SubScreen->TitleImage = Entry->me.Image;
+            // default entry
+            SubEntry = InitializeLoaderEntry(Entry);
+            if (SubEntry != NULL) {
+                SubEntry->me.Title = StrDuplicate(L"Boot using default options");
+                MainOptions = SubEntry->LoadOptions;
+                SubEntry->LoadOptions = AddInitrdToOptions(MainOptions, SubEntry->InitrdPath);
+                MyFreePool(MainOptions);
+                AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
+            } // if (SubEntry != NULL)
+            SubScreen->Hint1 = StrDuplicate(SUBSCREEN_HINT1);
+            if (GlobalConfig.HideUIFlags & HIDEUI_FLAG_EDITOR) {
+                SubScreen->Hint2 = StrDuplicate(SUBSCREEN_HINT2_NO_EDITOR);
+            } else {
+                SubScreen->Hint2 = StrDuplicate(SUBSCREEN_HINT2);
+            } // if/else
+        } // if (SubScreen != NULL)
+    } else { // existing subscreen; less initialization, and just add new entry later....
+        SubScreen = Entry->me.SubScreen;
+    } // if/else
+    return SubScreen;
 } // REFIT_MENU_SCREEN *InitializeSubScreen()
 
 VOID GenerateSubScreen(LOADER_ENTRY *Entry, IN REFIT_VOLUME *Volume, IN BOOLEAN GenerateReturn) {
-   REFIT_MENU_SCREEN  *SubScreen;
-   LOADER_ENTRY       *SubEntry;
-   CHAR16             *InitrdName;
-   CHAR16             DiagsFileName[256];
-   REFIT_FILE         *File;
-   UINTN              TokenCount;
-   CHAR16             **TokenList;
-
-   // create the submenu
-   if (StrLen(Entry->Title) == 0) {
-      MyFreePool(Entry->Title);
-      Entry->Title = NULL;
-   }
-   SubScreen = InitializeSubScreen(Entry);
-
-   // loader-specific submenu entries
-   if (Entry->OSType == 'M') {          // entries for Mac OS X
+    REFIT_MENU_SCREEN  *SubScreen;
+    LOADER_ENTRY       *SubEntry;
+    CHAR16             *InitrdName;
+    CHAR16             DiagsFileName[256];
+    REFIT_FILE         *File;
+    UINTN              TokenCount;
+    CHAR16             **TokenList;
+
+    // create the submenu
+    if (StrLen(Entry->Title) == 0) {
+        MyFreePool(Entry->Title);
+        Entry->Title = NULL;
+    }
+    SubScreen = InitializeSubScreen(Entry);
+
+    // loader-specific submenu entries
+    if (Entry->OSType == 'M') {          // entries for Mac OS X
 #if defined(EFIX64)
-      SubEntry = InitializeLoaderEntry(Entry);
-      if (SubEntry != NULL) {
-         SubEntry->me.Title        = L"Boot Mac OS X with a 64-bit kernel";
-         SubEntry->LoadOptions     = L"arch=x86_64";
-         SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_OSX;
-         AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-      } // if
-
-      SubEntry = InitializeLoaderEntry(Entry);
-      if (SubEntry != NULL) {
-         SubEntry->me.Title        = L"Boot Mac OS X with a 32-bit kernel";
-         SubEntry->LoadOptions     = L"arch=i386";
-         SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_OSX;
-         AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-      } // if
-#endif
+        SubEntry = InitializeLoaderEntry(Entry);
+        if (SubEntry != NULL) {
+            SubEntry->me.Title        = L"Boot Mac OS X with a 64-bit kernel";
+            SubEntry->LoadOptions     = L"arch=x86_64";
+            SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_OSX;
+            AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
+        } // if
 
-      if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_SINGLEUSER)) {
-         SubEntry = InitializeLoaderEntry(Entry);
-         if (SubEntry != NULL) {
-            SubEntry->me.Title        = L"Boot Mac OS X in verbose mode";
-            SubEntry->UseGraphicsMode = FALSE;
-            SubEntry->LoadOptions     = L"-v";
+        SubEntry = InitializeLoaderEntry(Entry);
+        if (SubEntry != NULL) {
+            SubEntry->me.Title        = L"Boot Mac OS X with a 32-bit kernel";
+            SubEntry->LoadOptions     = L"arch=i386";
+            SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_OSX;
             AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-         } // if
+        } // if
+#endif
+
+        if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_SINGLEUSER)) {
+            SubEntry = InitializeLoaderEntry(Entry);
+            if (SubEntry != NULL) {
+                SubEntry->me.Title        = L"Boot Mac OS X in verbose mode";
+                SubEntry->UseGraphicsMode = FALSE;
+                SubEntry->LoadOptions     = L"-v";
+                AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
+            } // if
 
 #if defined(EFIX64)
-         SubEntry = InitializeLoaderEntry(Entry);
-         if (SubEntry != NULL) {
-            SubEntry->me.Title        = L"Boot Mac OS X in verbose mode (64-bit)";
-            SubEntry->UseGraphicsMode = FALSE;
-            SubEntry->LoadOptions     = L"-v arch=x86_64";
-            AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-         }
+            SubEntry = InitializeLoaderEntry(Entry);
+            if (SubEntry != NULL) {
+                SubEntry->me.Title        = L"Boot Mac OS X in verbose mode (64-bit)";
+                SubEntry->UseGraphicsMode = FALSE;
+                SubEntry->LoadOptions     = L"-v arch=x86_64";
+                AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
+            }
 
-         SubEntry = InitializeLoaderEntry(Entry);
-         if (SubEntry != NULL) {
-            SubEntry->me.Title        = L"Boot Mac OS X in verbose mode (32-bit)";
-            SubEntry->UseGraphicsMode = FALSE;
-            SubEntry->LoadOptions     = L"-v arch=i386";
-            AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-         }
+            SubEntry = InitializeLoaderEntry(Entry);
+            if (SubEntry != NULL) {
+                SubEntry->me.Title        = L"Boot Mac OS X in verbose mode (32-bit)";
+                SubEntry->UseGraphicsMode = FALSE;
+                SubEntry->LoadOptions     = L"-v arch=i386";
+                AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
+            }
 #endif
 
-         SubEntry = InitializeLoaderEntry(Entry);
-         if (SubEntry != NULL) {
-            SubEntry->me.Title        = L"Boot Mac OS X in single user mode";
-            SubEntry->UseGraphicsMode = FALSE;
-            SubEntry->LoadOptions     = L"-v -s";
+            SubEntry = InitializeLoaderEntry(Entry);
+            if (SubEntry != NULL) {
+                SubEntry->me.Title        = L"Boot Mac OS X in single user mode";
+                SubEntry->UseGraphicsMode = FALSE;
+                SubEntry->LoadOptions     = L"-v -s";
+                AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
+            } // if
+        } // single-user mode allowed
+
+        if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_SAFEMODE)) {
+            SubEntry = InitializeLoaderEntry(Entry);
+            if (SubEntry != NULL) {
+                SubEntry->me.Title        = L"Boot Mac OS X in safe mode";
+                SubEntry->UseGraphicsMode = FALSE;
+                SubEntry->LoadOptions     = L"-v -x";
+                AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
+            } // if
+        } // safe mode allowed
+
+        // check for Apple hardware diagnostics
+        StrCpy(DiagsFileName, L"System\\Library\\CoreServices\\.diagnostics\\diags.efi");
+        if (FileExists(Volume->RootDir, DiagsFileName) && !(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HWTEST)) {
+            SubEntry = InitializeLoaderEntry(Entry);
+            if (SubEntry != NULL) {
+                SubEntry->me.Title        = L"Run Apple Hardware Test";
+                MyFreePool(SubEntry->LoaderPath);
+                SubEntry->LoaderPath      = StrDuplicate(DiagsFileName);
+                SubEntry->DevicePath      = FileDevicePath(Volume->DeviceHandle, SubEntry->LoaderPath);
+                SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_OSX;
+                AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
+            } // if
+        } // if diagnostics entry found
+
+    } else if (Entry->OSType == 'L') {   // entries for Linux kernels with EFI stub loaders
+        File = ReadLinuxOptionsFile(Entry->LoaderPath, Volume);
+        if (File != NULL) {
+            InitrdName =  FindInitrd(Entry->LoaderPath, Volume);
+            TokenCount = ReadTokenLine(File, &TokenList);
+            // first entry requires special processing, since it was initially set
+            // up with a default title but correct options by InitializeSubScreen(),
+            // earlier....
+            if ((TokenCount > 1) && (SubScreen->Entries != NULL) && (SubScreen->Entries[0] != NULL)) {
+                MyFreePool(SubScreen->Entries[0]->Title);
+                SubScreen->Entries[0]->Title = TokenList[0] ? StrDuplicate(TokenList[0]) : StrDuplicate(L"Boot Linux");
+            } // if
+            FreeTokenLine(&TokenList, &TokenCount);
+            while ((TokenCount = ReadTokenLine(File, &TokenList)) > 1) {
+                SubEntry = InitializeLoaderEntry(Entry);
+                SubEntry->me.Title = TokenList[0] ? StrDuplicate(TokenList[0]) : StrDuplicate(L"Boot Linux");
+                MyFreePool(SubEntry->LoadOptions);
+                SubEntry->LoadOptions = AddInitrdToOptions(TokenList[1], InitrdName);
+                FreeTokenLine(&TokenList, &TokenCount);
+                SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_LINUX;
+                AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
+            } // while
+            MyFreePool(InitrdName);
+            MyFreePool(File);
+        } // if
+
+    } else if (Entry->OSType == 'E') {   // entries for ELILO
+        SubEntry = InitializeLoaderEntry(Entry);
+        if (SubEntry != NULL) {
+            SubEntry->me.Title        = L"Run ELILO in interactive mode";
+            SubEntry->LoadOptions     = L"-p";
+            SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO;
             AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-         } // if
-      } // single-user mode allowed
-
-      if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_SAFEMODE)) {
-         SubEntry = InitializeLoaderEntry(Entry);
-         if (SubEntry != NULL) {
-            SubEntry->me.Title        = L"Boot Mac OS X in safe mode";
-            SubEntry->UseGraphicsMode = FALSE;
-            SubEntry->LoadOptions     = L"-v -x";
+        }
+
+        SubEntry = InitializeLoaderEntry(Entry);
+        if (SubEntry != NULL) {
+            SubEntry->me.Title        = L"Boot Linux for a 17\" iMac or a 15\" MacBook Pro (*)";
+            SubEntry->LoadOptions     = L"-d 0 i17";
+            SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO;
             AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-         } // if
-      } // safe mode allowed
-
-      // check for Apple hardware diagnostics
-      StrCpy(DiagsFileName, L"System\\Library\\CoreServices\\.diagnostics\\diags.efi");
-      if (FileExists(Volume->RootDir, DiagsFileName) && !(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HWTEST)) {
-         SubEntry = InitializeLoaderEntry(Entry);
-         if (SubEntry != NULL) {
-            SubEntry->me.Title        = L"Run Apple Hardware Test";
-            MyFreePool(SubEntry->LoaderPath);
-            SubEntry->LoaderPath      = StrDuplicate(DiagsFileName);
-            SubEntry->DevicePath      = FileDevicePath(Volume->DeviceHandle, SubEntry->LoaderPath);
-            SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_OSX;
+        }
+
+        SubEntry = InitializeLoaderEntry(Entry);
+        if (SubEntry != NULL) {
+            SubEntry->me.Title        = L"Boot Linux for a 20\" iMac (*)";
+            SubEntry->LoadOptions     = L"-d 0 i20";
+            SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO;
             AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-         } // if
-      } // if diagnostics entry found
-
-   } else if (Entry->OSType == 'L') {   // entries for Linux kernels with EFI stub loaders
-      File = ReadLinuxOptionsFile(Entry->LoaderPath, Volume);
-      if (File != NULL) {
-         InitrdName =  FindInitrd(Entry->LoaderPath, Volume);
-         TokenCount = ReadTokenLine(File, &TokenList);
-         // first entry requires special processing, since it was initially set
-         // up with a default title but correct options by InitializeSubScreen(),
-         // earlier....
-         if ((TokenCount > 1) && (SubScreen->Entries != NULL) && (SubScreen->Entries[0] != NULL)) {
-            MyFreePool(SubScreen->Entries[0]->Title);
-            SubScreen->Entries[0]->Title = TokenList[0] ? StrDuplicate(TokenList[0]) : StrDuplicate(L"Boot Linux");
-         } // if
-         FreeTokenLine(&TokenList, &TokenCount);
-         while ((TokenCount = ReadTokenLine(File, &TokenList)) > 1) {
-            SubEntry = InitializeLoaderEntry(Entry);
-            SubEntry->me.Title = TokenList[0] ? StrDuplicate(TokenList[0]) : StrDuplicate(L"Boot Linux");
-            MyFreePool(SubEntry->LoadOptions);
-            SubEntry->LoadOptions = AddInitrdToOptions(TokenList[1], InitrdName);
-            FreeTokenLine(&TokenList, &TokenCount);
-            SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_LINUX;
+        }
+
+        SubEntry = InitializeLoaderEntry(Entry);
+        if (SubEntry != NULL) {
+            SubEntry->me.Title        = L"Boot Linux for a Mac Mini (*)";
+            SubEntry->LoadOptions     = L"-d 0 mini";
+            SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO;
             AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-         } // while
-         MyFreePool(InitrdName);
-         MyFreePool(File);
-      } // if
-
-   } else if (Entry->OSType == 'E') {   // entries for ELILO
-      SubEntry = InitializeLoaderEntry(Entry);
-      if (SubEntry != NULL) {
-         SubEntry->me.Title        = L"Run ELILO in interactive mode";
-         SubEntry->LoadOptions     = L"-p";
-         SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO;
-         AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-      }
-
-      SubEntry = InitializeLoaderEntry(Entry);
-      if (SubEntry != NULL) {
-         SubEntry->me.Title        = L"Boot Linux for a 17\" iMac or a 15\" MacBook Pro (*)";
-         SubEntry->LoadOptions     = L"-d 0 i17";
-         SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO;
-         AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-      }
-
-      SubEntry = InitializeLoaderEntry(Entry);
-      if (SubEntry != NULL) {
-         SubEntry->me.Title        = L"Boot Linux for a 20\" iMac (*)";
-         SubEntry->LoadOptions     = L"-d 0 i20";
-         SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO;
-         AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-      }
-
-      SubEntry = InitializeLoaderEntry(Entry);
-      if (SubEntry != NULL) {
-         SubEntry->me.Title        = L"Boot Linux for a Mac Mini (*)";
-         SubEntry->LoadOptions     = L"-d 0 mini";
-         SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO;
-         AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
-      }
-
-      AddMenuInfoLine(SubScreen, L"NOTE: This is an example. Entries");
-      AddMenuInfoLine(SubScreen, L"marked with (*) may not work.");
-
-   } else if (Entry->OSType == 'X') {   // entries for xom.efi
+        }
+
+        AddMenuInfoLine(SubScreen, L"NOTE: This is an example. Entries");
+        AddMenuInfoLine(SubScreen, L"marked with (*) may not work.");
+
+    } else if (Entry->OSType == 'X') {   // entries for xom.efi
         // by default, skip the built-in selection and boot from hard disk only
         Entry->LoadOptions = L"-s -h";
 
         SubEntry = InitializeLoaderEntry(Entry);
         if (SubEntry != NULL) {
-           SubEntry->me.Title        = L"Boot Windows from Hard Disk";
-           SubEntry->LoadOptions     = L"-s -h";
-           SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_WINDOWS;
-           AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
+            SubEntry->me.Title        = L"Boot Windows from Hard Disk";
+            SubEntry->LoadOptions     = L"-s -h";
+            SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_WINDOWS;
+            AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
         }
 
         SubEntry = InitializeLoaderEntry(Entry);
         if (SubEntry != NULL) {
-           SubEntry->me.Title        = L"Boot Windows from CD-ROM";
-           SubEntry->LoadOptions     = L"-s -c";
-           SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_WINDOWS;
-           AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
+            SubEntry->me.Title        = L"Boot Windows from CD-ROM";
+            SubEntry->LoadOptions     = L"-s -c";
+            SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_WINDOWS;
+            AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
         }
 
         SubEntry = InitializeLoaderEntry(Entry);
         if (SubEntry != NULL) {
-           SubEntry->me.Title        = L"Run XOM in text mode";
-           SubEntry->LoadOptions     = L"-v";
-           SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_WINDOWS;
-           AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
+            SubEntry->me.Title        = L"Run XOM in text mode";
+            SubEntry->LoadOptions     = L"-v";
+            SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_WINDOWS;
+            AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
         }
-   } // entries for xom.efi
-   if (GenerateReturn)
-       AddMenuEntry(SubScreen, &MenuEntryReturn);
-   Entry->me.SubScreen = SubScreen;
+    } // entries for xom.efi
+    if (GenerateReturn)
+        AddMenuEntry(SubScreen, &MenuEntryReturn);
+    Entry->me.SubScreen = SubScreen;
 } // VOID GenerateSubScreen()
 
 // Returns options for a Linux kernel. Reads them from an options file in the
 // kernel's directory; and if present, adds an initrd= option for an initial
 // RAM disk file with the same version number as the kernel file.
 static CHAR16 * GetMainLinuxOptions(IN CHAR16 * LoaderPath, IN REFIT_VOLUME *Volume) {
-   CHAR16 *Options = NULL, *InitrdName, *FullOptions = NULL;
+    CHAR16 *Options = NULL, *InitrdName, *FullOptions = NULL;
 
-   Options = GetFirstOptionsFromFile(LoaderPath, Volume);
-   InitrdName = FindInitrd(LoaderPath, Volume);
-   FullOptions = AddInitrdToOptions(Options, InitrdName);
+    Options = GetFirstOptionsFromFile(LoaderPath, Volume);
+    InitrdName = FindInitrd(LoaderPath, Volume);
+    FullOptions = AddInitrdToOptions(Options, InitrdName);
 
-   MyFreePool(Options);
-   MyFreePool(InitrdName);
-   return (FullOptions);
+    MyFreePool(Options);
+    MyFreePool(InitrdName);
+    return (FullOptions);
 } // static CHAR16 * GetMainLinuxOptions()
 
+// Read the specified file and add values of "ID", "NAME", or "DISTRIB_ID" tokens to
+// OSIconName list. Intended for adding Linux distribution clues gleaned from
+// /etc/lsb-release and /etc/os-release files.
+static VOID ParseReleaseFile(CHAR16 **OSIconName, REFIT_VOLUME *Volume, CHAR16 *FileName) {
+    UINTN       FileSize = 0;
+    REFIT_FILE  File;
+    CHAR16      **TokenList;
+    UINTN       TokenCount = 0;
+
+    if ((Volume == NULL) || (FileName == NULL) || (OSIconName == NULL) || (*OSIconName == NULL))
+        return;
+
+    if (FileExists(Volume->RootDir, FileName) &&
+        (ReadFile(Volume->RootDir, FileName, &File, &FileSize) == EFI_SUCCESS)) {
+        do {
+            TokenCount = ReadTokenLine(&File, &TokenList);
+            if ((TokenCount > 1) && (MyStriCmp(TokenList[0], L"ID") ||
+                                     MyStriCmp(TokenList[0], L"NAME") ||
+                                     MyStriCmp(TokenList[0], L"DISTRIB_ID"))) {
+                MergeWords(OSIconName, TokenList[1], L',');
+            } // if
+            FreeTokenLine(&TokenList, &TokenCount);
+        } while (TokenCount > 0);
+        MyFreePool(File.Buffer);
+    } // if
+} // VOID ParseReleaseFile()
+
 // Try to guess the name of the Linux distribution & add that name to
 // OSIconName list.
 static VOID GuessLinuxDistribution(CHAR16 **OSIconName, REFIT_VOLUME *Volume, CHAR16 *LoaderPath) {
-   UINTN       FileSize = 0;
-   REFIT_FILE  File;
-   CHAR16**    TokenList;
-   UINTN       TokenCount = 0;
-
-   // If on Linux root fs, /etc/os-release file probably has clues....
-   if (FileExists(Volume->RootDir, L"etc\\os-release") &&
-       (ReadFile(Volume->RootDir, L"etc\\os-release", &File, &FileSize) == EFI_SUCCESS)) {
-      do {
-         TokenCount = ReadTokenLine(&File, &TokenList);
-         if ((TokenCount > 1) && ((StriCmp(TokenList[0], L"ID") == 0) || (StriCmp(TokenList[0], L"NAME") == 0))) {
-            MergeStrings(OSIconName, TokenList[1], L',');
-         } // if
-         FreeTokenLine(&TokenList, &TokenCount);
-      } while (TokenCount > 0);
-      MyFreePool(File.Buffer);
-   } // if
-
-   // Search for clues in the kernel's filename....
-   if (StriSubCmp(L".fc", LoaderPath))
-      MergeStrings(OSIconName, L"fedora", L',');
-   if (StriSubCmp(L".el", LoaderPath))
-      MergeStrings(OSIconName, L"redhat", L',');
+    // If on Linux root fs, /etc/os-release or /etc/lsb-release file probably has clues....
+    ParseReleaseFile(OSIconName, Volume, L"etc\\lsb-release");
+    ParseReleaseFile(OSIconName, Volume, L"etc\\os-release");
+
+    // Search for clues in the kernel's filename....
+    if (StriSubCmp(L".fc", LoaderPath))
+        MergeStrings(OSIconName, L"fedora", L',');
+    if (StriSubCmp(L".el", LoaderPath))
+        MergeStrings(OSIconName, L"redhat", L',');
 } // VOID GuessLinuxDistribution()
 
 // 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, REFIT_VOLUME *Volume) {
-   CHAR16      *NameClues, *PathOnly, *NoExtension, *OSIconName = NULL, *Temp, *SubString;
-   CHAR16      ShortcutLetter = 0;
-   UINTN       i = 0, Length;
-
-   NameClues = Basename(LoaderPath);
-   PathOnly = FindPath(LoaderPath);
-   NoExtension = StripEfiExtension(NameClues);
-
-   if (Volume->DiskKind == DISK_KIND_NET) {
-      MergeStrings(&NameClues, Entry->me.Title, L' ');
-   } else {
-      // locate a custom icon for the loader
-      // Anything found here takes precedence over the "hints" in the OSIconName variable
-      if (!Entry->me.Image) {
-         Entry->me.Image = egLoadIconAnyType(Volume->RootDir, PathOnly, NoExtension, GlobalConfig.IconSizes[ICON_SIZE_BIG]);
-      }
-      if (!Entry->me.Image) {
-         Entry->me.Image = egCopyImage(Volume->VolIconImage);
-      }
-
-      // Begin creating icon "hints" by using last part of directory path leading
-      // to the loader
-      Temp = FindLastDirName(LoaderPath);
-      MergeStrings(&OSIconName, Temp, L',');
-      MyFreePool(Temp);
-      Temp = NULL;
-      if (OSIconName != NULL) {
-         ShortcutLetter = OSIconName[0];
-      }
-
-      // 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 = SubString = StrDuplicate(Volume->VolName);
-         if (Temp != NULL) {
-            Length = StrLen(Temp);
-            for (i = 0; i < Length; i++) {
-               if ((Temp[i] == L' ') || (Temp[i] == L'_') || (Temp[i] == L'-')) {
-                  Temp[i] = 0;
-                  if (StrLen(SubString) > 0)
-                     MergeStrings(&OSIconName, SubString, L',');
-                  SubString = Temp + i + 1;
-               } // if
-            } // for
-            MergeStrings(&OSIconName, SubString, L',');
-            MyFreePool(Temp);
-         } // if
-      } // if
-   } // if/else network boot
-
-   // detect specific loaders
-   if (StriSubCmp(L"bzImage", NameClues) || StriSubCmp(L"vmlinuz", NameClues)) {
-      if (Volume->DiskKind != DISK_KIND_NET) {
-         GuessLinuxDistribution(&OSIconName, Volume, LoaderPath);
-         Entry->LoadOptions = GetMainLinuxOptions(LoaderPath, Volume);
-      }
-      MergeStrings(&OSIconName, L"linux", L',');
-      Entry->OSType = 'L';
-      if (ShortcutLetter == 0)
-         ShortcutLetter = 'L';
-      Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_LINUX;
-   } else if (StriSubCmp(L"refit", LoaderPath)) {
-      MergeStrings(&OSIconName, L"refit", L',');
-      Entry->OSType = 'R';
-      ShortcutLetter = 'R';
-   } else if (StriSubCmp(L"refind", LoaderPath)) {
-      MergeStrings(&OSIconName, L"refind", L',');
-      Entry->OSType = 'R';
-      ShortcutLetter = 'R';
-   } else if (StriCmp(LoaderPath, MACOSX_LOADER_PATH) == 0) {
-      MergeStrings(&OSIconName, L"mac", L',');
-      Entry->OSType = 'M';
-      ShortcutLetter = 'M';
-      Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_OSX;
-   } else if (StriCmp(NameClues, L"diags.efi") == 0) {
-      MergeStrings(&OSIconName, L"hwtest", L',');
-   } else if (StriCmp(NameClues, L"e.efi") == 0 || StriCmp(NameClues, L"elilo.efi") == 0 || StriSubCmp(L"elilo", NameClues)) {
-      MergeStrings(&OSIconName, L"elilo,linux", L',');
-      Entry->OSType = 'E';
-      if (ShortcutLetter == 0)
-         ShortcutLetter = 'L';
-      Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO;
-   } else if (StriSubCmp(L"grub", NameClues)) {
-      MergeStrings(&OSIconName, L"grub,linux", L',');
-      Entry->OSType = 'G';
-      ShortcutLetter = 'G';
-      Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_GRUB;
-   } else if (StriCmp(NameClues, L"cdboot.efi") == 0 ||
-              StriCmp(NameClues, L"bootmgr.efi") == 0 ||
-              StriCmp(NameClues, L"bootmgfw.efi") == 0 ||
-              StriCmp(NameClues, L"bkpbootmgfw.efi") == 0) {
-      MergeStrings(&OSIconName, L"win8", L',');
-      Entry->OSType = 'W';
-      ShortcutLetter = 'W';
-      Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_WINDOWS;
-   } else if (StriCmp(NameClues, L"xom.efi") == 0) {
-      MergeStrings(&OSIconName, L"xom,win,win8", L',');
-      Entry->OSType = 'X';
-      ShortcutLetter = 'W';
-      Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_WINDOWS;
-   }
-   else if (StriSubCmp(L"ipxe", NameClues)) {
-      Entry->OSType = 'N';
-      ShortcutLetter = 'N';
-      MergeStrings(&OSIconName, L"network", L',');
-   } 
-
-   if ((ShortcutLetter >= 'a') && (ShortcutLetter <= 'z'))
-      ShortcutLetter = ShortcutLetter - 'a' + 'A'; // convert lowercase to uppercase
-   Entry->me.ShortcutLetter = ShortcutLetter;
-   if (Entry->me.Image == NULL)
-      Entry->me.Image = LoadOSIcon(OSIconName, L"unknown", FALSE);
-   MyFreePool(PathOnly);
+    CHAR16      *NameClues, *PathOnly, *NoExtension, *OSIconName = NULL, *Temp;
+    CHAR16      ShortcutLetter = 0;
+
+    NameClues = Basename(LoaderPath);
+    PathOnly = FindPath(LoaderPath);
+    NoExtension = StripEfiExtension(NameClues);
+
+    if (Volume->DiskKind == DISK_KIND_NET) {
+        MergeStrings(&NameClues, Entry->me.Title, L' ');
+    } else {
+        // locate a custom icon for the loader
+        // Anything found here takes precedence over the "hints" in the OSIconName variable
+        if (!Entry->me.Image) {
+            Entry->me.Image = egLoadIconAnyType(Volume->RootDir, PathOnly, NoExtension, GlobalConfig.IconSizes[ICON_SIZE_BIG]);
+        }
+        if (!Entry->me.Image) {
+            Entry->me.Image = egCopyImage(Volume->VolIconImage);
+        }
+
+        // Begin creating icon "hints" by using last part of directory path leading
+        // to the loader
+        Temp = FindLastDirName(LoaderPath);
+        MergeStrings(&OSIconName, Temp, L',');
+        MyFreePool(Temp);
+        Temp = NULL;
+        if (OSIconName != NULL) {
+            ShortcutLetter = OSIconName[0];
+        }
+
+        // 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.
+        MergeWords(&OSIconName, Volume->VolName, L',');
+    } // if/else network boot
+
+    // detect specific loaders
+    if (StriSubCmp(L"bzImage", NameClues) || StriSubCmp(L"vmlinuz", NameClues)) {
+        if (Volume->DiskKind != DISK_KIND_NET) {
+            GuessLinuxDistribution(&OSIconName, Volume, LoaderPath);
+            Entry->LoadOptions = GetMainLinuxOptions(LoaderPath, Volume);
+        }
+        MergeStrings(&OSIconName, L"linux", L',');
+        Entry->OSType = 'L';
+        if (ShortcutLetter == 0)
+            ShortcutLetter = 'L';
+        Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_LINUX;
+    } else if (StriSubCmp(L"refit", LoaderPath)) {
+        MergeStrings(&OSIconName, L"refit", L',');
+        Entry->OSType = 'R';
+        ShortcutLetter = 'R';
+    } else if (StriSubCmp(L"refind", LoaderPath)) {
+        MergeStrings(&OSIconName, L"refind", L',');
+        Entry->OSType = 'R';
+        ShortcutLetter = 'R';
+    } else if (MyStriCmp(LoaderPath, MACOSX_LOADER_PATH)) {
+        MergeStrings(&OSIconName, L"mac", L',');
+        Entry->OSType = 'M';
+        ShortcutLetter = 'M';
+        Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_OSX;
+    } else if (MyStriCmp(NameClues, L"diags.efi")) {
+        MergeStrings(&OSIconName, L"hwtest", L',');
+    } else if (MyStriCmp(NameClues, L"e.efi") || MyStriCmp(NameClues, L"elilo.efi") || StriSubCmp(L"elilo", NameClues)) {
+        MergeStrings(&OSIconName, L"elilo,linux", L',');
+        Entry->OSType = 'E';
+        if (ShortcutLetter == 0)
+            ShortcutLetter = 'L';
+        Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO;
+    } else if (StriSubCmp(L"grub", NameClues)) {
+        MergeStrings(&OSIconName, L"grub,linux", L',');
+        Entry->OSType = 'G';
+        ShortcutLetter = 'G';
+        Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_GRUB;
+    } else if (MyStriCmp(NameClues, L"cdboot.efi") ||
+               MyStriCmp(NameClues, L"bootmgr.efi") ||
+               MyStriCmp(NameClues, L"bootmgfw.efi") ||
+               MyStriCmp(NameClues, L"bkpbootmgfw.efi")) {
+        MergeStrings(&OSIconName, L"win8", L',');
+        Entry->OSType = 'W';
+        ShortcutLetter = 'W';
+        Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_WINDOWS;
+    } else if (MyStriCmp(NameClues, L"xom.efi")) {
+        MergeStrings(&OSIconName, L"xom,win,win8", L',');
+        Entry->OSType = 'X';
+        ShortcutLetter = 'W';
+        Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_WINDOWS;
+    }
+    else if (StriSubCmp(L"ipxe", NameClues)) {
+        Entry->OSType = 'N';
+        ShortcutLetter = 'N';
+        MergeStrings(&OSIconName, L"network", L',');
+    } 
+
+    if ((ShortcutLetter >= 'a') && (ShortcutLetter <= 'z'))
+        ShortcutLetter = ShortcutLetter - 'a' + 'A'; // convert lowercase to uppercase
+    Entry->me.ShortcutLetter = ShortcutLetter;
+    if (Entry->me.Image == NULL)
+        Entry->me.Image = LoadOSIcon(OSIconName, L"unknown", FALSE);
+    MyFreePool(PathOnly);
 } // VOID SetLoaderDefaults()
 
 // Add a specified EFI boot loader to the list, using automatic settings
 // for icons, options, etc.
 static LOADER_ENTRY * AddLoaderEntry(IN CHAR16 *LoaderPath, IN CHAR16 *LoaderTitle, IN REFIT_VOLUME *Volume, IN BOOLEAN SubScreenReturn) {
-   LOADER_ENTRY  *Entry;
-
-   CleanUpPathNameSlashes(LoaderPath);
-   Entry = InitializeLoaderEntry(NULL);
-   if (Entry != NULL) {
-      Entry->Title = StrDuplicate((LoaderTitle != NULL) ? LoaderTitle : LoaderPath);
-      Entry->me.Title = AllocateZeroPool(sizeof(CHAR16) * 256);
-      // Extra space at end of Entry->me.Title enables searching on Volume->VolName even if another volume
-      // name is identical except for something added to the end (e.g., VolB1 vs. VolB12).
-      // Note: Volume->VolName will be NULL for network boot programs.
-      if (Volume->VolName)
-         SPrint(Entry->me.Title, 255, L"Boot %s from %s ", (LoaderTitle != NULL) ? LoaderTitle : LoaderPath, Volume->VolName);
-      else
-         SPrint(Entry->me.Title, 255, L"Boot %s ", (LoaderTitle != NULL) ? LoaderTitle : LoaderPath);
-      Entry->me.Row = 0;
-      Entry->me.BadgeImage = Volume->VolBadgeImage;
-      if ((LoaderPath != NULL) && (LoaderPath[0] != L'\\')) {
-         Entry->LoaderPath = StrDuplicate(L"\\");
-      } else {
-         Entry->LoaderPath = NULL;
-      }
-      MergeStrings(&(Entry->LoaderPath), LoaderPath, 0);
-      Entry->VolName = Volume->VolName;
-      Entry->DevicePath = FileDevicePath(Volume->DeviceHandle, Entry->LoaderPath);
-      SetLoaderDefaults(Entry, LoaderPath, Volume);
-      GenerateSubScreen(Entry, Volume, SubScreenReturn);
-      AddMenuEntry(&MainMenu, (REFIT_MENU_ENTRY *)Entry);
-   }
-
-   return(Entry);
+    LOADER_ENTRY  *Entry;
+
+    CleanUpPathNameSlashes(LoaderPath);
+    Entry = InitializeLoaderEntry(NULL);
+    if (Entry != NULL) {
+        Entry->Title = StrDuplicate((LoaderTitle != NULL) ? LoaderTitle : LoaderPath);
+        Entry->me.Title = AllocateZeroPool(sizeof(CHAR16) * 256);
+        // Extra space at end of Entry->me.Title enables searching on Volume->VolName even if another volume
+        // name is identical except for something added to the end (e.g., VolB1 vs. VolB12).
+        // Note: Volume->VolName will be NULL for network boot programs.
+        if (Volume->VolName)
+            SPrint(Entry->me.Title, 255, L"Boot %s from %s ", (LoaderTitle != NULL) ? LoaderTitle : LoaderPath, Volume->VolName);
+        else
+            SPrint(Entry->me.Title, 255, L"Boot %s ", (LoaderTitle != NULL) ? LoaderTitle : LoaderPath);
+        Entry->me.Row = 0;
+        Entry->me.BadgeImage = Volume->VolBadgeImage;
+        if ((LoaderPath != NULL) && (LoaderPath[0] != L'\\')) {
+            Entry->LoaderPath = StrDuplicate(L"\\");
+        } else {
+            Entry->LoaderPath = NULL;
+        }
+        MergeStrings(&(Entry->LoaderPath), LoaderPath, 0);
+        Entry->VolName = Volume->VolName;
+        Entry->DevicePath = FileDevicePath(Volume->DeviceHandle, Entry->LoaderPath);
+        SetLoaderDefaults(Entry, LoaderPath, Volume);
+        GenerateSubScreen(Entry, Volume, SubScreenReturn);
+        AddMenuEntry(&MainMenu, (REFIT_MENU_ENTRY *)Entry);
+    }
+
+    return(Entry);
 } // LOADER_ENTRY * AddLoaderEntry()
 
 // Add a Linux kernel as a submenu entry for another (pre-existing) Linux kernel entry.
@@ -1108,55 +1105,55 @@ static VOID AddKernelToSubmenu(LOADER_ENTRY * TargetLoader, CHAR16 *FileName, RE
 // this is used for sorting boot loader entries, differences smaller
 // than this are likely to be meaningless (and unlikely!).
 INTN TimeComp(IN EFI_TIME *Time1, IN EFI_TIME *Time2) {
-   INT64 Time1InSeconds, Time2InSeconds;
-
-   // Following values are overestimates; I'm assuming 31 days in every month.
-   // This is fine for the purpose of this function, which is limited
-   Time1InSeconds = Time1->Second + (Time1->Minute * 60) + (Time1->Hour * 3600) + (Time1->Day * 86400) +
-                    (Time1->Month * 2678400) + ((Time1->Year - 1998) * 32140800);
-   Time2InSeconds = Time2->Second + (Time2->Minute * 60) + (Time2->Hour * 3600) + (Time2->Day * 86400) +
-                    (Time2->Month * 2678400) + ((Time2->Year - 1998) * 32140800);
-   if (Time1InSeconds < Time2InSeconds)
-      return (-1);
-   else if (Time1InSeconds > Time2InSeconds)
-      return (1);
-
-   return 0;
+    INT64 Time1InSeconds, Time2InSeconds;
+
+    // Following values are overestimates; I'm assuming 31 days in every month.
+    // This is fine for the purpose of this function, which is limited
+    Time1InSeconds = Time1->Second + (Time1->Minute * 60) + (Time1->Hour * 3600) + (Time1->Day * 86400) +
+                        (Time1->Month * 2678400) + ((Time1->Year - 1998) * 32140800);
+    Time2InSeconds = Time2->Second + (Time2->Minute * 60) + (Time2->Hour * 3600) + (Time2->Day * 86400) +
+                        (Time2->Month * 2678400) + ((Time2->Year - 1998) * 32140800);
+    if (Time1InSeconds < Time2InSeconds)
+        return (-1);
+    else if (Time1InSeconds > Time2InSeconds)
+        return (1);
+
+    return 0;
 } // INTN TimeComp()
 
 // Adds a loader list element, keeping it sorted by date. Returns the new
 // first element (the one with the most recent date).
 static struct LOADER_LIST * AddLoaderListEntry(struct LOADER_LIST *LoaderList, struct LOADER_LIST *NewEntry) {
-   struct LOADER_LIST *LatestEntry, *CurrentEntry, *PrevEntry = NULL;
-
-   LatestEntry = CurrentEntry = LoaderList;
-   if (LoaderList == NULL) {
-      LatestEntry = NewEntry;
-   } else {
-      while ((CurrentEntry != NULL) && (TimeComp(&(NewEntry->TimeStamp), &(CurrentEntry->TimeStamp)) < 0)) {
-         PrevEntry = CurrentEntry;
-         CurrentEntry = CurrentEntry->NextEntry;
-      } // while
-      NewEntry->NextEntry = CurrentEntry;
-      if (PrevEntry == NULL) {
-         LatestEntry = NewEntry;
-      } else {
-         PrevEntry->NextEntry = NewEntry;
-      } // if/else
-   } // if/else
-   return (LatestEntry);
+    struct LOADER_LIST *LatestEntry, *CurrentEntry, *PrevEntry = NULL;
+
+    LatestEntry = CurrentEntry = LoaderList;
+    if (LoaderList == NULL) {
+        LatestEntry = NewEntry;
+    } else {
+        while ((CurrentEntry != NULL) && (TimeComp(&(NewEntry->TimeStamp), &(CurrentEntry->TimeStamp)) < 0)) {
+            PrevEntry = CurrentEntry;
+            CurrentEntry = CurrentEntry->NextEntry;
+        } // while
+        NewEntry->NextEntry = CurrentEntry;
+        if (PrevEntry == NULL) {
+            LatestEntry = NewEntry;
+        } else {
+            PrevEntry->NextEntry = NewEntry;
+        } // if/else
+    } // if/else
+    return (LatestEntry);
 } // static VOID AddLoaderListEntry()
 
 // Delete the LOADER_LIST linked list
 static VOID CleanUpLoaderList(struct LOADER_LIST *LoaderList) {
-   struct LOADER_LIST *Temp;
-
-   while (LoaderList != NULL) {
-      Temp = LoaderList;
-      LoaderList = LoaderList->NextEntry;
-      MyFreePool(Temp->FileName);
-      MyFreePool(Temp);
-   } // while
+    struct LOADER_LIST *Temp;
+
+    while (LoaderList != NULL) {
+        Temp = LoaderList;
+        LoaderList = LoaderList->NextEntry;
+        MyFreePool(Temp->FileName);
+        MyFreePool(Temp);
+    } // while
 } // static VOID CleanUpLoaderList()
 
 // Returns FALSE if the specified file/volume matches the GlobalConfig.DontScanDirs
@@ -1165,47 +1162,47 @@ static VOID CleanUpLoaderList(struct LOADER_LIST *LoaderList) {
 // 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, *PathCopy = NULL;
-   UINTN    i = 0;
-   BOOLEAN  ScanIt = TRUE;
-
-   if ((IsIn(Volume->VolName, GlobalConfig.DontScanVolumes)) || (IsIn(Volume->PartName, GlobalConfig.DontScanVolumes)))
-      return FALSE;
-
-   if ((StriCmp(Path, SelfDirPath) == 0) && (Volume->DeviceHandle == SelfVolume->DeviceHandle))
-      return FALSE;
-
-   // See if Path includes an explicit volume declaration that's NOT Volume....
-   PathCopy = StrDuplicate(Path);
-   if (SplitVolumeAndFilename(&PathCopy, &VolName)) {
-      VolumeNumberToName(Volume, &VolName);
-      if (VolName && StriCmp(VolName, Volume->VolName) != 0) {
-         ScanIt = FALSE;
-      } // if
-   } // if Path includes volume specification
-   MyFreePool(PathCopy);
-   MyFreePool(VolName);
-   VolName = NULL;
-
-   // See if Volume is in GlobalConfig.DontScanDirs....
-   while (ScanIt && (DontScanDir = FindCommaDelimited(GlobalConfig.DontScanDirs, i++))) {
-      SplitVolumeAndFilename(&DontScanDir, &VolName);
-      CleanUpPathNameSlashes(DontScanDir);
-      VolumeNumberToName(Volume, &VolName);
-      if (VolName != NULL) {
-         if ((StriCmp(VolName, Volume->VolName) == 0) && (StriCmp(DontScanDir, Path) == 0))
-            ScanIt = FALSE;
-      } else {
-         if (StriCmp(DontScanDir, Path) == 0)
+    CHAR16   *VolName = NULL, *DontScanDir, *PathCopy = NULL;
+    UINTN    i = 0;
+    BOOLEAN  ScanIt = TRUE;
+
+    if ((IsIn(Volume->VolName, GlobalConfig.DontScanVolumes)) || (IsIn(Volume->PartName, GlobalConfig.DontScanVolumes)))
+        return FALSE;
+
+    if (MyStriCmp(Path, SelfDirPath) && (Volume->DeviceHandle == SelfVolume->DeviceHandle))
+        return FALSE;
+
+    // See if Path includes an explicit volume declaration that's NOT Volume....
+    PathCopy = StrDuplicate(Path);
+    if (SplitVolumeAndFilename(&PathCopy, &VolName)) {
+        VolumeNumberToName(Volume, &VolName);
+        if (VolName && !MyStriCmp(VolName, Volume->VolName)) {
             ScanIt = FALSE;
-      }
-      MyFreePool(DontScanDir);
-      MyFreePool(VolName);
-      DontScanDir = NULL;
-      VolName = NULL;
-   } // while()
-
-   return ScanIt;
+        } // if
+    } // if Path includes volume specification
+    MyFreePool(PathCopy);
+    MyFreePool(VolName);
+    VolName = NULL;
+
+    // See if Volume is in GlobalConfig.DontScanDirs....
+    while (ScanIt && (DontScanDir = FindCommaDelimited(GlobalConfig.DontScanDirs, i++))) {
+        SplitVolumeAndFilename(&DontScanDir, &VolName);
+        CleanUpPathNameSlashes(DontScanDir);
+        VolumeNumberToName(Volume, &VolName);
+        if (VolName != NULL) {
+            if (MyStriCmp(VolName, Volume->VolName) && MyStriCmp(DontScanDir, Path))
+                ScanIt = FALSE;
+        } else {
+            if (MyStriCmp(DontScanDir, Path))
+                ScanIt = FALSE;
+        }
+        MyFreePool(DontScanDir);
+        MyFreePool(VolName);
+        DontScanDir = NULL;
+        VolName = NULL;
+    } // while()
+
+    return ScanIt;
 } // BOOLEAN ShouldScan()
 
 // Returns TRUE if the file is byte-for-byte identical with the fallback file
@@ -1214,61 +1211,61 @@ static BOOLEAN ShouldScan(REFIT_VOLUME *Volume, CHAR16 *Path) {
 // IS the fallback file. Intended for use in excluding the fallback boot
 // loader when it's a duplicate of another boot loader.
 static BOOLEAN DuplicatesFallback(IN REFIT_VOLUME *Volume, IN CHAR16 *FileName) {
-   CHAR8           *FileContents, *FallbackContents;
-   EFI_FILE_HANDLE FileHandle, FallbackHandle;
-   EFI_FILE_INFO   *FileInfo, *FallbackInfo;
-   UINTN           FileSize = 0, FallbackSize = 0;
-   EFI_STATUS      Status;
-   BOOLEAN         AreIdentical = FALSE;
-
-   if (!FileExists(Volume->RootDir, FileName) || !FileExists(Volume->RootDir, FALLBACK_FULLNAME))
-      return FALSE;
-
-   CleanUpPathNameSlashes(FileName);
-
-   if (StriCmp(FileName, FALLBACK_FULLNAME) == 0)
-      return FALSE; // identical filenames, so not a duplicate....
-
-   Status = refit_call5_wrapper(Volume->RootDir->Open, Volume->RootDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0);
-   if (Status == EFI_SUCCESS) {
-      FileInfo = LibFileInfo(FileHandle);
-      FileSize = FileInfo->FileSize;
-   } else {
-      return FALSE;
-   }
-
-   Status = refit_call5_wrapper(Volume->RootDir->Open, Volume->RootDir, &FallbackHandle, FALLBACK_FULLNAME, EFI_FILE_MODE_READ, 0);
-   if (Status == EFI_SUCCESS) {
-      FallbackInfo = LibFileInfo(FallbackHandle);
-      FallbackSize = FallbackInfo->FileSize;
-   } else {
-      refit_call1_wrapper(FileHandle->Close, FileHandle);
-      return FALSE;
-   }
-
-   if (FallbackSize != FileSize) { // not same size, so can't be identical
-      AreIdentical = FALSE;
-   } else { // could be identical; do full check....
-      FileContents = AllocatePool(FileSize);
-      FallbackContents = AllocatePool(FallbackSize);
-      if (FileContents && FallbackContents) {
-         Status = refit_call3_wrapper(FileHandle->Read, FileHandle, &FileSize, FileContents);
-         if (Status == EFI_SUCCESS) {
-            Status = refit_call3_wrapper(FallbackHandle->Read, FallbackHandle, &FallbackSize, FallbackContents);
-         }
-         if (Status == EFI_SUCCESS) {
-            AreIdentical = (CompareMem(FileContents, FallbackContents, FileSize) == 0);
-         } // if
-      } // if
-      MyFreePool(FileContents);
-      MyFreePool(FallbackContents);
-   } // if/else
-
-   // BUG ALERT: Some systems (e.g., DUET, some Macs with large displays) crash if the
-   // following two calls are reversed. Go figure....
-   refit_call1_wrapper(FileHandle->Close, FallbackHandle);
-   refit_call1_wrapper(FileHandle->Close, FileHandle);
-   return AreIdentical;
+    CHAR8           *FileContents, *FallbackContents;
+    EFI_FILE_HANDLE FileHandle, FallbackHandle;
+    EFI_FILE_INFO   *FileInfo, *FallbackInfo;
+    UINTN           FileSize = 0, FallbackSize = 0;
+    EFI_STATUS      Status;
+    BOOLEAN         AreIdentical = FALSE;
+
+    if (!FileExists(Volume->RootDir, FileName) || !FileExists(Volume->RootDir, FALLBACK_FULLNAME))
+        return FALSE;
+
+    CleanUpPathNameSlashes(FileName);
+
+    if (MyStriCmp(FileName, FALLBACK_FULLNAME))
+        return FALSE; // identical filenames, so not a duplicate....
+
+    Status = refit_call5_wrapper(Volume->RootDir->Open, Volume->RootDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0);
+    if (Status == EFI_SUCCESS) {
+        FileInfo = LibFileInfo(FileHandle);
+        FileSize = FileInfo->FileSize;
+    } else {
+        return FALSE;
+    }
+
+    Status = refit_call5_wrapper(Volume->RootDir->Open, Volume->RootDir, &FallbackHandle, FALLBACK_FULLNAME, EFI_FILE_MODE_READ, 0);
+    if (Status == EFI_SUCCESS) {
+        FallbackInfo = LibFileInfo(FallbackHandle);
+        FallbackSize = FallbackInfo->FileSize;
+    } else {
+        refit_call1_wrapper(FileHandle->Close, FileHandle);
+        return FALSE;
+    }
+
+    if (FallbackSize != FileSize) { // not same size, so can't be identical
+        AreIdentical = FALSE;
+    } else { // could be identical; do full check....
+        FileContents = AllocatePool(FileSize);
+        FallbackContents = AllocatePool(FallbackSize);
+        if (FileContents && FallbackContents) {
+            Status = refit_call3_wrapper(FileHandle->Read, FileHandle, &FileSize, FileContents);
+            if (Status == EFI_SUCCESS) {
+                Status = refit_call3_wrapper(FallbackHandle->Read, FallbackHandle, &FallbackSize, FallbackContents);
+            }
+            if (Status == EFI_SUCCESS) {
+                AreIdentical = (CompareMem(FileContents, FallbackContents, FileSize) == 0);
+            } // if
+        } // if
+        MyFreePool(FileContents);
+        MyFreePool(FallbackContents);
+    } // if/else
+
+    // BUG ALERT: Some systems (e.g., DUET, some Macs with large displays) crash if the
+    // following two calls are reversed. Go figure....
+    refit_call1_wrapper(FileHandle->Close, FallbackHandle);
+    refit_call1_wrapper(FileHandle->Close, FileHandle);
+    return AreIdentical;
 } // BOOLEAN DuplicatesFallback()
 
 // Returns FALSE if two measures of file size are identical for a single file,
@@ -1280,27 +1277,27 @@ static BOOLEAN DuplicatesFallback(IN REFIT_VOLUME *Volume, IN CHAR16 *FileName)
 // this function to exclude symbolic links from the list of boot loaders,
 // that would be fine, since such boot loaders wouldn't work.)
 static BOOLEAN IsSymbolicLink(REFIT_VOLUME *Volume, CHAR16 *Path, EFI_FILE_INFO *DirEntry) {
-   EFI_FILE_HANDLE FileHandle;
-   EFI_FILE_INFO   *FileInfo = NULL;
-   EFI_STATUS      Status;
-   UINTN           FileSize2 = 0;
-   CHAR16          *FileName;
-
-   FileName = StrDuplicate(Path);
-   MergeStrings(&FileName, DirEntry->FileName, L'\\');
-   CleanUpPathNameSlashes(FileName);
-
-   Status = refit_call5_wrapper(Volume->RootDir->Open, Volume->RootDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0);
-   if (Status == EFI_SUCCESS) {
-      FileInfo = LibFileInfo(FileHandle);
-      if (FileInfo != NULL)
-         FileSize2 = FileInfo->FileSize;
-   }
-
-   MyFreePool(FileName);
-   MyFreePool(FileInfo);
-
-   return (DirEntry->FileSize != FileSize2);
+    EFI_FILE_HANDLE FileHandle;
+    EFI_FILE_INFO   *FileInfo = NULL;
+    EFI_STATUS      Status;
+    UINTN           FileSize2 = 0;
+    CHAR16          *FileName;
+
+    FileName = StrDuplicate(Path);
+    MergeStrings(&FileName, DirEntry->FileName, L'\\');
+    CleanUpPathNameSlashes(FileName);
+
+    Status = refit_call5_wrapper(Volume->RootDir->Open, Volume->RootDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0);
+    if (Status == EFI_SUCCESS) {
+        FileInfo = LibFileInfo(FileHandle);
+        if (FileInfo != NULL)
+            FileSize2 = FileInfo->FileSize;
+    }
+
+    MyFreePool(FileName);
+    MyFreePool(FileInfo);
+
+    return (DirEntry->FileSize != FileSize2);
 } // BOOLEAN IsSymbolicLink()
 
 // Returns TRUE if a file with the same name as the original but with
@@ -1310,20 +1307,20 @@ static BOOLEAN IsSymbolicLink(REFIT_VOLUME *Volume, CHAR16 *Path, EFI_FILE_INFO
 // 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 (NewFile != NULL) {
-      CleanUpPathNameSlashes(NewFile);
-      if (FileExists(Volume->RootDir, NewFile))
-         retval = TRUE;
-      MyFreePool(NewFile);
-   } // if
-
-   return retval;
+    CHAR16 *NewFile = NULL;
+    BOOLEAN retval = FALSE;
+
+    MergeStrings(&NewFile, Path, 0);
+    MergeStrings(&NewFile, Filename, L'\\');
+    MergeStrings(&NewFile, L".efi.signed", 0);
+    if (NewFile != NULL) {
+        CleanUpPathNameSlashes(NewFile);
+        if (FileExists(Volume->RootDir, NewFile))
+            retval = TRUE;
+        MyFreePool(NewFile);
+    } // if
+
+    return retval;
 } // BOOLEAN HasSignedCounterpart()
 
 // Scan an individual directory for EFI boot loader files and, if found,
@@ -1339,18 +1336,19 @@ static BOOLEAN ScanLoaderDir(IN REFIT_VOLUME *Volume, IN CHAR16 *Path, IN CHAR16
     CHAR16                  FileName[256], *Extension;
     struct LOADER_LIST      *LoaderList = NULL, *NewLoader;
     LOADER_ENTRY            *FirstKernel = NULL, *LatestEntry = NULL;
-    BOOLEAN                 FoundFallbackDuplicate = FALSE, IsLinux = FALSE;
+    BOOLEAN                 FoundFallbackDuplicate = FALSE, IsLinux = FALSE, InSelfPath;
 
-    if ((!SelfDirPath || !Path || ((StriCmp(Path, SelfDirPath) == 0) && (Volume->DeviceHandle != SelfVolume->DeviceHandle)) ||
-           (StriCmp(Path, SelfDirPath) != 0)) && (ShouldScan(Volume, Path))) {
+    InSelfPath = MyStriCmp(Path, SelfDirPath);
+    if ((!SelfDirPath || !Path || (InSelfPath && (Volume->DeviceHandle != SelfVolume->DeviceHandle)) ||
+           (!InSelfPath)) && (ShouldScan(Volume, Path))) {
        // look through contents of the directory
        DirIterOpen(Volume->RootDir, Path, &DirIter);
        while (DirIterNext(&DirIter, 2, Pattern, &DirEntry)) {
           Extension = FindExtension(DirEntry->FileName);
           if (DirEntry->FileName[0] == '.' ||
-              StriCmp(Extension, L".icns") == 0 ||
-              StriCmp(Extension, L".png") == 0 ||
-              (StriCmp(DirEntry->FileName, FALLBACK_BASENAME) == 0 && (StriCmp(Path, L"EFI\\BOOT") == 0)) ||
+              MyStriCmp(Extension, L".icns") ||
+              MyStriCmp(Extension, L".png") ||
+              (MyStriCmp(DirEntry->FileName, FALLBACK_BASENAME) && (MyStriCmp(Path, L"EFI\\BOOT"))) ||
               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 */
@@ -1414,21 +1412,20 @@ static BOOLEAN ScanLoaderDir(IN REFIT_VOLUME *Volume, IN CHAR16 *Path, IN CHAR16
 // server and the name of the boot file it delivers.
 CHAR16* RuniPXEDiscover(EFI_HANDLE Volume)
 {
-   EFI_STATUS       Status;
-   EFI_DEVICE_PATH  *FilePath;
-   EFI_HANDLE       iPXEHandle;
-   CHAR16           *boot_info = NULL;
-   UINTN            boot_info_size = 0;
+    EFI_STATUS       Status;
+    EFI_DEVICE_PATH  *FilePath;
+    EFI_HANDLE       iPXEHandle;
+    CHAR16           *boot_info = NULL;
+    UINTN            boot_info_size = 0;
 
-   FilePath = FileDevicePath (Volume, IPXE_DISCOVER_NAME);
-   Status = refit_call6_wrapper(BS->LoadImage, FALSE, SelfImageHandle, FilePath,
-                                NULL, 0, &iPXEHandle);
-   if (Status != 0)
-      return NULL;
+    FilePath = FileDevicePath (Volume, IPXE_DISCOVER_NAME);
+    Status = refit_call6_wrapper(BS->LoadImage, FALSE, SelfImageHandle, FilePath, NULL, 0, &iPXEHandle);
+    if (Status != 0)
+        return NULL;
 
-   Status = refit_call3_wrapper(BS->StartImage, iPXEHandle, &boot_info_size, &boot_info);
+    Status = refit_call3_wrapper(BS->StartImage, iPXEHandle, &boot_info_size, &boot_info);
 
-   return boot_info;
+    return boot_info;
 } // RuniPXEDiscover()
 
 // Scan for network (PXE) boot servers. This function relies on the presence
@@ -1436,175 +1433,175 @@ CHAR16* RuniPXEDiscover(EFI_HANDLE Volume)
 // which rEFInd launched. As of December 6, 2014, these tools aren't entirely
 // reliable. See BUILDING.txt for information on building them.
 static VOID ScanNetboot() {
-   CHAR16        *iPXEFileName = IPXE_NAME;
-   CHAR16        *Location;
-   REFIT_VOLUME  *NetVolume;
-
-   if (FileExists(SelfVolume->RootDir, IPXE_DISCOVER_NAME) &&
-       FileExists(SelfVolume->RootDir, IPXE_NAME) &&
-       IsValidLoader(SelfVolume->RootDir, IPXE_DISCOVER_NAME) &&
-       IsValidLoader(SelfVolume->RootDir, IPXE_NAME)) {
-      Location = RuniPXEDiscover(SelfVolume->DeviceHandle);
-      if (Location != NULL && FileExists(SelfVolume->RootDir, iPXEFileName)) {
-         NetVolume = AllocatePool(sizeof(REFIT_VOLUME));
-         CopyMem(NetVolume, SelfVolume, sizeof(REFIT_VOLUME));
-         NetVolume->DiskKind = DISK_KIND_NET;
-         NetVolume->VolBadgeImage = BuiltinIcon(BUILTIN_ICON_VOL_NET);
-         NetVolume->PartName = NetVolume->VolName = NULL;
-         AddLoaderEntry(iPXEFileName, Location, NetVolume, TRUE);
-         MyFreePool(NetVolume);
-      } // if support files exist and are valid
-   } 
+    CHAR16        *iPXEFileName = IPXE_NAME;
+    CHAR16        *Location;
+    REFIT_VOLUME  *NetVolume;
+
+    if (FileExists(SelfVolume->RootDir, IPXE_DISCOVER_NAME) &&
+        FileExists(SelfVolume->RootDir, IPXE_NAME) &&
+        IsValidLoader(SelfVolume->RootDir, IPXE_DISCOVER_NAME) &&
+        IsValidLoader(SelfVolume->RootDir, IPXE_NAME)) {
+            Location = RuniPXEDiscover(SelfVolume->DeviceHandle);
+            if (Location != NULL && FileExists(SelfVolume->RootDir, iPXEFileName)) {
+                NetVolume = AllocatePool(sizeof(REFIT_VOLUME));
+                CopyMem(NetVolume, SelfVolume, sizeof(REFIT_VOLUME));
+                NetVolume->DiskKind = DISK_KIND_NET;
+                NetVolume->VolBadgeImage = BuiltinIcon(BUILTIN_ICON_VOL_NET);
+                NetVolume->PartName = NetVolume->VolName = NULL;
+                AddLoaderEntry(iPXEFileName, Location, NetVolume, TRUE);
+                MyFreePool(NetVolume);
+            } // if support files exist and are valid
+    
 } // VOID ScanNetBoot()
 
 static VOID ScanEfiFiles(REFIT_VOLUME *Volume) {
-   EFI_STATUS              Status;
-   REFIT_DIR_ITER          EfiDirIter;
-   EFI_FILE_INFO           *EfiDirEntry;
-   CHAR16                  FileName[256], *Directory = NULL, *MatchPatterns, *VolName = NULL, *SelfPath;
-   UINTN                   i, Length;
-   BOOLEAN                 ScanFallbackLoader = TRUE;
-   BOOLEAN                 FoundBRBackup = FALSE;
-
-   if (Volume && (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, MACOSX_LOADER_DIR)) {
-         StrCpy(FileName, MACOSX_LOADER_PATH);
-         if (FileExists(Volume->RootDir, FileName) && !FilenameIn(Volume, MACOSX_LOADER_DIR, L"boot.efi", GlobalConfig.DontScanFiles)) {
-            AddLoaderEntry(FileName, L"Mac OS X", Volume, TRUE);
-            if (DuplicatesFallback(Volume, FileName))
-               ScanFallbackLoader = FALSE;
-         }
-
-         // check for XOM
-         StrCpy(FileName, L"System\\Library\\CoreServices\\xom.efi");
-         if (FileExists(Volume->RootDir, FileName) && !FilenameIn(Volume, MACOSX_LOADER_DIR, L"xom.efi", GlobalConfig.DontScanFiles)) {
-            AddLoaderEntry(FileName, L"Windows XP (XoM)", Volume, TRUE);
-            if (DuplicatesFallback(Volume, FileName))
-               ScanFallbackLoader = FALSE;
-         }
-      } // if should scan Mac directory
-
-      // 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, L"EFI\\Microsoft\\Boot", L"bkpbootmgfw.efi",
-             GlobalConfig.DontScanFiles)) {
-            AddLoaderEntry(FileName, L"Microsoft EFI boot (Boot Repair backup)", Volume, TRUE);
-            FoundBRBackup = TRUE;
-            if (DuplicatesFallback(Volume, FileName))
-               ScanFallbackLoader = FALSE;
-         }
-         StrCpy(FileName, L"EFI\\Microsoft\\Boot\\bootmgfw.efi");
-         if (FileExists(Volume->RootDir, FileName) &&
-             !FilenameIn(Volume, L"EFI\\Microsoft\\Boot", L"bootmgfw.efi", GlobalConfig.DontScanFiles)) {
-            if (FoundBRBackup)
-               AddLoaderEntry(FileName, L"Supposed Microsoft EFI boot (probably GRUB)", Volume, TRUE);
-            else
-               AddLoaderEntry(FileName, L"Microsoft EFI boot", Volume, TRUE);
-            if (DuplicatesFallback(Volume, FileName))
-               ScanFallbackLoader = FALSE;
-         }
-      } // if
-
-      // scan the root directory for EFI executables
-      if (ScanLoaderDir(Volume, L"\\", MatchPatterns))
-         ScanFallbackLoader = FALSE;
-
-      // scan subdirectories of the EFI directory (as per the standard)
-      DirIterOpen(Volume->RootDir, L"EFI", &EfiDirIter);
-      while (DirIterNext(&EfiDirIter, 1, NULL, &EfiDirEntry)) {
-         if (StriCmp(EfiDirEntry->FileName, L"tools") == 0 || EfiDirEntry->FileName[0] == '.')
-            continue;   // skip this, doesn't contain boot loaders or is scanned later
-         SPrint(FileName, 255, L"EFI\\%s", EfiDirEntry->FileName);
-         if (ScanLoaderDir(Volume, FileName, MatchPatterns))
+    EFI_STATUS              Status;
+    REFIT_DIR_ITER          EfiDirIter;
+    EFI_FILE_INFO           *EfiDirEntry;
+    CHAR16                  FileName[256], *Directory = NULL, *MatchPatterns, *VolName = NULL, *SelfPath;
+    UINTN                   i, Length;
+    BOOLEAN                 ScanFallbackLoader = TRUE;
+    BOOLEAN                 FoundBRBackup = FALSE;
+
+    if (Volume && (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, MACOSX_LOADER_DIR)) {
+            StrCpy(FileName, MACOSX_LOADER_PATH);
+            if (FileExists(Volume->RootDir, FileName) && !FilenameIn(Volume, MACOSX_LOADER_DIR, L"boot.efi", GlobalConfig.DontScanFiles)) {
+                AddLoaderEntry(FileName, L"Mac OS X", Volume, TRUE);
+                if (DuplicatesFallback(Volume, FileName))
+                    ScanFallbackLoader = FALSE;
+            }
+
+            // check for XOM
+            StrCpy(FileName, L"System\\Library\\CoreServices\\xom.efi");
+            if (FileExists(Volume->RootDir, FileName) && !FilenameIn(Volume, MACOSX_LOADER_DIR, L"xom.efi", GlobalConfig.DontScanFiles)) {
+                AddLoaderEntry(FileName, L"Windows XP (XoM)", Volume, TRUE);
+                if (DuplicatesFallback(Volume, FileName))
+                    ScanFallbackLoader = FALSE;
+            }
+        } // if should scan Mac directory
+
+        // 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, L"EFI\\Microsoft\\Boot", L"bkpbootmgfw.efi",
+                GlobalConfig.DontScanFiles)) {
+                    AddLoaderEntry(FileName, L"Microsoft EFI boot (Boot Repair backup)", Volume, TRUE);
+                    FoundBRBackup = TRUE;
+                    if (DuplicatesFallback(Volume, FileName))
+                        ScanFallbackLoader = FALSE;
+            }
+            StrCpy(FileName, L"EFI\\Microsoft\\Boot\\bootmgfw.efi");
+            if (FileExists(Volume->RootDir, FileName) &&
+                !FilenameIn(Volume, L"EFI\\Microsoft\\Boot", L"bootmgfw.efi", GlobalConfig.DontScanFiles)) {
+                    if (FoundBRBackup)
+                        AddLoaderEntry(FileName, L"Supposed Microsoft EFI boot (probably GRUB)", Volume, TRUE);
+                    else
+                        AddLoaderEntry(FileName, L"Microsoft EFI boot", Volume, TRUE);
+                    if (DuplicatesFallback(Volume, FileName))
+                        ScanFallbackLoader = FALSE;
+            }
+        } // if
+
+        // scan the root directory for EFI executables
+        if (ScanLoaderDir(Volume, L"\\", MatchPatterns))
+            ScanFallbackLoader = FALSE;
+
+        // scan subdirectories of the EFI directory (as per the standard)
+        DirIterOpen(Volume->RootDir, L"EFI", &EfiDirIter);
+        while (DirIterNext(&EfiDirIter, 1, NULL, &EfiDirEntry)) {
+            if (MyStriCmp(EfiDirEntry->FileName, L"tools") || EfiDirEntry->FileName[0] == '.')
+                continue;   // skip this, doesn't contain boot loaders or is scanned later
+            SPrint(FileName, 255, L"EFI\\%s", EfiDirEntry->FileName);
+            if (ScanLoaderDir(Volume, FileName, MatchPatterns))
+                ScanFallbackLoader = FALSE;
+        } // while()
+        Status = DirIterClose(&EfiDirIter);
+        if ((Status != EFI_NOT_FOUND) && (Status != EFI_INVALID_PARAMETER))
+            CheckError(Status, L"while scanning the EFI directory");
+
+        // Scan user-specified (or additional default) directories....
+        i = 0;
+        while ((Directory = FindCommaDelimited(GlobalConfig.AlsoScan, i++)) != NULL) {
+            if (ShouldScan(Volume, Directory)) {
+                SplitVolumeAndFilename(&Directory, &VolName);
+                CleanUpPathNameSlashes(Directory);
+                Length = StrLen(Directory);
+                if ((Length > 0) && ScanLoaderDir(Volume, Directory, MatchPatterns))
+                    ScanFallbackLoader = FALSE;
+                MyFreePool(VolName);
+            } // if should scan dir
+            MyFreePool(Directory);
+        } // while
+
+        // Don't scan the fallback loader if it's on the same volume and a duplicate of rEFInd itself....
+        SelfPath = DevicePathToStr(SelfLoadedImage->FilePath);
+        CleanUpPathNameSlashes(SelfPath);
+        if ((Volume->DeviceHandle == SelfLoadedImage->DeviceHandle) && DuplicatesFallback(Volume, SelfPath))
             ScanFallbackLoader = FALSE;
-      } // while()
-      Status = DirIterClose(&EfiDirIter);
-      if ((Status != EFI_NOT_FOUND) && (Status != EFI_INVALID_PARAMETER))
-         CheckError(Status, L"while scanning the EFI directory");
-
-      // Scan user-specified (or additional default) directories....
-      i = 0;
-      while ((Directory = FindCommaDelimited(GlobalConfig.AlsoScan, i++)) != NULL) {
-         if (ShouldScan(Volume, Directory)) {
-            SplitVolumeAndFilename(&Directory, &VolName);
-            CleanUpPathNameSlashes(Directory);
-            Length = StrLen(Directory);
-            if ((Length > 0) && ScanLoaderDir(Volume, Directory, MatchPatterns))
-               ScanFallbackLoader = FALSE;
-            MyFreePool(VolName);
-         } // if should scan dir
-         MyFreePool(Directory);
-      } // while
-
-      // Don't scan the fallback loader if it's on the same volume and a duplicate of rEFInd itself....
-      SelfPath = DevicePathToStr(SelfLoadedImage->FilePath);
-      CleanUpPathNameSlashes(SelfPath);
-      if ((Volume->DeviceHandle == SelfLoadedImage->DeviceHandle) && DuplicatesFallback(Volume, SelfPath))
-         ScanFallbackLoader = FALSE;
-
-      // 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) && ShouldScan(Volume, L"EFI\\BOOT")) {
-         AddLoaderEntry(FALLBACK_FULLNAME, L"Fallback boot loader", Volume, TRUE);
-      }
-   } // if
+
+        // 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) && ShouldScan(Volume, L"EFI\\BOOT")) {
+            AddLoaderEntry(FALLBACK_FULLNAME, L"Fallback boot loader", Volume, TRUE);
+        }
+    } // if
 } // static VOID ScanEfiFiles()
 
 // Scan internal disks for valid EFI boot loaders....
 static VOID ScanInternal(VOID) {
-   UINTN                   VolumeIndex;
+    UINTN                   VolumeIndex;
 
-   for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
-      if (Volumes[VolumeIndex]->DiskKind == DISK_KIND_INTERNAL) {
-         ScanEfiFiles(Volumes[VolumeIndex]);
-      }
-   } // for
+    for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
+        if (Volumes[VolumeIndex]->DiskKind == DISK_KIND_INTERNAL) {
+            ScanEfiFiles(Volumes[VolumeIndex]);
+        }
+    } // for
 } // static VOID ScanInternal()
 
 // Scan external disks for valid EFI boot loaders....
 static VOID ScanExternal(VOID) {
-   UINTN                   VolumeIndex;
+    UINTN                   VolumeIndex;
 
-   for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
-      if (Volumes[VolumeIndex]->DiskKind == DISK_KIND_EXTERNAL) {
-         ScanEfiFiles(Volumes[VolumeIndex]);
-      }
-   } // for
+    for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
+        if (Volumes[VolumeIndex]->DiskKind == DISK_KIND_EXTERNAL) {
+            ScanEfiFiles(Volumes[VolumeIndex]);
+        }
+    } // for
 } // static VOID ScanExternal()
 
 // Scan internal disks for valid EFI boot loaders....
 static VOID ScanOptical(VOID) {
-   UINTN                   VolumeIndex;
+    UINTN                   VolumeIndex;
 
-   for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
-      if (Volumes[VolumeIndex]->DiskKind == DISK_KIND_OPTICAL) {
-         ScanEfiFiles(Volumes[VolumeIndex]);
-      }
-   } // for
+    for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
+        if (Volumes[VolumeIndex]->DiskKind == DISK_KIND_OPTICAL) {
+            ScanEfiFiles(Volumes[VolumeIndex]);
+        }
+    } // for
 } // static VOID ScanOptical()
 
 // default volume badge icon based on disk kind
 EG_IMAGE * GetDiskBadge(IN UINTN DiskType) {
-   EG_IMAGE * Badge = NULL;
-
-   switch (DiskType) {
-      case BBS_HARDDISK:
-         Badge = BuiltinIcon(BUILTIN_ICON_VOL_INTERNAL);
-         break;
-      case BBS_USB:
-         Badge = BuiltinIcon(BUILTIN_ICON_VOL_EXTERNAL);
-         break;
-      case BBS_CDROM:
-         Badge = BuiltinIcon(BUILTIN_ICON_VOL_OPTICAL);
-         break;
-   } // switch()
-   return Badge;
+    EG_IMAGE * Badge = NULL;
+
+    switch (DiskType) {
+        case BBS_HARDDISK:
+            Badge = BuiltinIcon(BUILTIN_ICON_VOL_INTERNAL);
+            break;
+        case BBS_USB:
+            Badge = BuiltinIcon(BUILTIN_ICON_VOL_EXTERNAL);
+            break;
+        case BBS_CDROM:
+            Badge = BuiltinIcon(BUILTIN_ICON_VOL_OPTICAL);
+            break;
+    } // switch()
+    return Badge;
 } // EG_IMAGE * GetDiskBadge()
 
 //
@@ -1613,11 +1610,11 @@ EG_IMAGE * GetDiskBadge(IN UINTN DiskType) {
 
 static VOID StartTool(IN LOADER_ENTRY *Entry)
 {
-   BeginExternalScreen(Entry->UseGraphicsMode, Entry->me.Title + 6);  // assumes "Start <title>" as assigned below
-   StoreLoaderName(Entry->me.Title);
-   StartEFIImage(Entry->DevicePath, Entry->LoadOptions, TYPE_EFI,
-                 Basename(Entry->LoaderPath), Entry->OSType, NULL, TRUE, FALSE);
-   FinishExternalScreen();
+    BeginExternalScreen(Entry->UseGraphicsMode, Entry->me.Title + 6);  // assumes "Start <title>" as assigned below
+    StoreLoaderName(Entry->me.Title);
+    StartEFIImage(Entry->DevicePath, Entry->LoadOptions, TYPE_EFI,
+                  Basename(Entry->LoaderPath), Entry->OSType, NULL, TRUE, FALSE);
+    FinishExternalScreen();
 } /* static VOID StartTool() */
 
 static LOADER_ENTRY * AddToolEntry(EFI_HANDLE DeviceHandle, IN CHAR16 *LoaderPath, IN CHAR16 *LoaderTitle, IN EG_IMAGE *Image,
@@ -1744,8 +1741,8 @@ Done:
 } /* EFI_STATUS ConnectAllDriversToAllControllers() */
 #else
 static EFI_STATUS ConnectAllDriversToAllControllers(VOID) {
-   BdsLibConnectAllDriversToAllControllers();
-   return 0;
+    BdsLibConnectAllDriversToAllControllers();
+    return 0;
 }
 #endif
 
@@ -1787,263 +1784,264 @@ static VOID LoadDrivers(VOID)
 
 // Locates boot loaders. NOTE: This assumes that GlobalConfig.LegacyType is set correctly.
 static VOID ScanForBootloaders(VOID) {
-   UINTN    i;
-   CHAR8    s;
-   BOOLEAN  ScanForLegacy = FALSE;
-
-   // Determine up-front if we'll be scanning for legacy loaders....
-   for (i = 0; i < NUM_SCAN_OPTIONS; i++) {
-      s = GlobalConfig.ScanFor[i];
-      if ((s == 'c') || (s == 'C') || (s == 'h') || (s == 'H') || (s == 'b') || (s == 'B'))
-         ScanForLegacy = TRUE;
-   } // for
-
-   // If UEFI & scanning for legacy loaders & deep legacy scan, update NVRAM boot manager list
-   if ((GlobalConfig.LegacyType == LEGACY_TYPE_UEFI) && ScanForLegacy && GlobalConfig.DeepLegacyScan) {
-      BdsDeleteAllInvalidLegacyBootOptions();
-      BdsAddNonExistingLegacyBootOptions();
-   } // if
-
-   // scan for loaders and tools, add them to the menu
-   for (i = 0; i < NUM_SCAN_OPTIONS; i++) {
-      switch(GlobalConfig.ScanFor[i]) {
-         case 'c': case 'C':
-            ScanLegacyDisc();
-            break;
-         case 'h': case 'H':
-            ScanLegacyInternal();
-            break;
-         case 'b': case 'B':
-            ScanLegacyExternal();
-            break;
-         case 'm': case 'M':
-            ScanUserConfigured(GlobalConfig.ConfigFilename);
-            break;
-         case 'e': case 'E':
-            ScanExternal();
-            break;
-         case 'i': case 'I':
-            ScanInternal();
-            break;
-         case 'o': case 'O':
-            ScanOptical();
-            break;
-         case 'n': case 'N':
-            ScanNetboot();
-            break;
-      } // switch()
-   } // for
+    UINTN    i;
+    CHAR8    s;
+    BOOLEAN  ScanForLegacy = FALSE;
+
+    // Determine up-front if we'll be scanning for legacy loaders....
+    for (i = 0; i < NUM_SCAN_OPTIONS; i++) {
+        s = GlobalConfig.ScanFor[i];
+        if ((s == 'c') || (s == 'C') || (s == 'h') || (s == 'H') || (s == 'b') || (s == 'B'))
+            ScanForLegacy = TRUE;
+    } // for
+
+    // If UEFI & scanning for legacy loaders & deep legacy scan, update NVRAM boot manager list
+    if ((GlobalConfig.LegacyType == LEGACY_TYPE_UEFI) && ScanForLegacy && GlobalConfig.DeepLegacyScan) {
+        BdsDeleteAllInvalidLegacyBootOptions();
+        BdsAddNonExistingLegacyBootOptions();
+    } // if
+
+    // scan for loaders and tools, add them to the menu
+    for (i = 0; i < NUM_SCAN_OPTIONS; i++) {
+        switch(GlobalConfig.ScanFor[i]) {
+            case 'c': case 'C':
+                ScanLegacyDisc();
+                break;
+            case 'h': case 'H':
+                ScanLegacyInternal();
+                break;
+            case 'b': case 'B':
+                ScanLegacyExternal();
+                break;
+            case 'm': case 'M':
+                ScanUserConfigured(GlobalConfig.ConfigFilename);
+                break;
+            case 'e': case 'E':
+                ScanExternal();
+                break;
+            case 'i': case 'I':
+                ScanInternal();
+                break;
+            case 'o': case 'O':
+                ScanOptical();
+                break;
+            case 'n': case 'N':
+                ScanNetboot();
+                break;
+        } // switch()
+    } // for
 
-   // assign shortcut keys
-   for (i = 0; i < MainMenu.EntryCount && MainMenu.Entries[i]->Row == 0 && i < 9; i++)
-      MainMenu.Entries[i]->ShortcutDigit = (CHAR16)('1' + i);
+    // assign shortcut keys
+    for (i = 0; i < MainMenu.EntryCount && MainMenu.Entries[i]->Row == 0 && i < 9; i++)
+        MainMenu.Entries[i]->ShortcutDigit = (CHAR16)('1' + i);
 
-   // wait for user ACK when there were errors
-   FinishTextScreen(FALSE);
+    // wait for user ACK when there were errors
+    FinishTextScreen(FALSE);
 } // static VOID ScanForBootloaders()
 
 // Locate a single tool from the specified Locations using one of the
 // specified Names and add it to the menu.
 static VOID FindTool(CHAR16 *Locations, CHAR16 *Names, CHAR16 *Description, UINTN Icon) {
-   UINTN j = 0, k, VolumeIndex;
-   CHAR16 *DirName, *FileName, *PathName, FullDescription[256];
-
-   while ((DirName = FindCommaDelimited(Locations, j++)) != NULL) {
-      k = 0;
-      while ((FileName = FindCommaDelimited(Names, k++)) != NULL) {
-         PathName = StrDuplicate(DirName);
-         MergeStrings(&PathName, FileName, (StriCmp(PathName, L"\\") == 0) ? 0 : L'\\');
-         for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
-            if ((Volumes[VolumeIndex]->RootDir != NULL) && (FileExists(Volumes[VolumeIndex]->RootDir, PathName)) &&
-                IsValidLoader(Volumes[VolumeIndex]->RootDir, PathName)) {
-               SPrint(FullDescription, 255, L"%s at %s on %s", Description, PathName, Volumes[VolumeIndex]->VolName);
-               AddToolEntry(Volumes[VolumeIndex]->DeviceHandle, PathName, FullDescription, BuiltinIcon(Icon), 'S', FALSE);
-            } // if
-         } // for
-         MyFreePool(PathName);
-         MyFreePool(FileName);
-      } // while Names
-      MyFreePool(DirName);
-   } // while Locations
+    UINTN j = 0, k, VolumeIndex;
+    CHAR16 *DirName, *FileName, *PathName, FullDescription[256];
+
+    while ((DirName = FindCommaDelimited(Locations, j++)) != NULL) {
+        k = 0;
+        while ((FileName = FindCommaDelimited(Names, k++)) != NULL) {
+            PathName = StrDuplicate(DirName);
+            MergeStrings(&PathName, FileName, MyStriCmp(PathName, L"\\") ? 0 : L'\\');
+            for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
+                if ((Volumes[VolumeIndex]->RootDir != NULL) &&
+                    (FileExists(Volumes[VolumeIndex]->RootDir, PathName)) &&
+                    IsValidLoader(Volumes[VolumeIndex]->RootDir, PathName)) {
+                        SPrint(FullDescription, 255, L"%s at %s on %s", Description, PathName, Volumes[VolumeIndex]->VolName);
+                        AddToolEntry(Volumes[VolumeIndex]->DeviceHandle, PathName, FullDescription, BuiltinIcon(Icon), 'S', FALSE);
+                } // if
+            } // for
+            MyFreePool(PathName);
+            MyFreePool(FileName);
+        } // while Names
+        MyFreePool(DirName);
+    } // while Locations
 } // VOID FindTool()
 
 // Add the second-row tags containing built-in and external tools (EFI shell,
 // reboot, etc.)
 static VOID ScanForTools(VOID) {
-   CHAR16 *FileName = NULL, *VolName = NULL, *MokLocations, Description[256];
-   REFIT_MENU_ENTRY *TempMenuEntry;
-   UINTN i, j, VolumeIndex;
-   UINT64 osind;
-   CHAR8 *b = 0;
-
-   MokLocations = StrDuplicate(MOK_LOCATIONS);
-   if (MokLocations != NULL)
-      MergeStrings(&MokLocations, SelfDirPath, L',');
-
-   for (i = 0; i < NUM_TOOLS; i++) {
-      switch(GlobalConfig.ShowTools[i]) {
-         // NOTE: Be sure that FileName is NULL at the end of each case.
-         case TAG_SHUTDOWN:
-            TempMenuEntry = CopyMenuEntry(&MenuEntryShutdown);
-            TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_SHUTDOWN);
-            AddMenuEntry(&MainMenu, TempMenuEntry);
-            break;
+    CHAR16 *FileName = NULL, *VolName = NULL, *MokLocations, Description[256];
+    REFIT_MENU_ENTRY *TempMenuEntry;
+    UINTN i, j, VolumeIndex;
+    UINT64 osind;
+    CHAR8 *b = 0;
+
+    MokLocations = StrDuplicate(MOK_LOCATIONS);
+    if (MokLocations != NULL)
+        MergeStrings(&MokLocations, SelfDirPath, L',');
+
+    for (i = 0; i < NUM_TOOLS; i++) {
+        switch(GlobalConfig.ShowTools[i]) {
+            // NOTE: Be sure that FileName is NULL at the end of each case.
+            case TAG_SHUTDOWN:
+                TempMenuEntry = CopyMenuEntry(&MenuEntryShutdown);
+                TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_SHUTDOWN);
+                AddMenuEntry(&MainMenu, TempMenuEntry);
+                break;
 
-         case TAG_REBOOT:
-            TempMenuEntry = CopyMenuEntry(&MenuEntryReset);
-            TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_RESET);
-            AddMenuEntry(&MainMenu, TempMenuEntry);
-            break;
+            case TAG_REBOOT:
+                TempMenuEntry = CopyMenuEntry(&MenuEntryReset);
+                TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_RESET);
+                AddMenuEntry(&MainMenu, TempMenuEntry);
+                break;
 
-         case TAG_ABOUT:
-            TempMenuEntry = CopyMenuEntry(&MenuEntryAbout);
-            TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
-            AddMenuEntry(&MainMenu, TempMenuEntry);
-            break;
+            case TAG_ABOUT:
+                TempMenuEntry = CopyMenuEntry(&MenuEntryAbout);
+                TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
+                AddMenuEntry(&MainMenu, TempMenuEntry);
+                break;
 
-         case TAG_EXIT:
-            TempMenuEntry = CopyMenuEntry(&MenuEntryExit);
-            TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_EXIT);
-            AddMenuEntry(&MainMenu, TempMenuEntry);
-            break;
+            case TAG_EXIT:
+                TempMenuEntry = CopyMenuEntry(&MenuEntryExit);
+                TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_EXIT);
+                AddMenuEntry(&MainMenu, TempMenuEntry);
+                break;
 
-         case TAG_FIRMWARE:
-            if (EfivarGetRaw(&GlobalGuid, L"OsIndicationsSupported", &b, &j) == EFI_SUCCESS) {
-               osind = (UINT64)*b;
-               if (osind & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) {
-                  TempMenuEntry = CopyMenuEntry(&MenuEntryFirmware);
-                  TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_FIRMWARE);
-                  AddMenuEntry(&MainMenu, TempMenuEntry);
-               } // if
-            } // if
-            break;
+            case TAG_FIRMWARE:
+                if (EfivarGetRaw(&GlobalGuid, L"OsIndicationsSupported", &b, &j) == EFI_SUCCESS) {
+                    osind = (UINT64)*b;
+                    if (osind & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) {
+                        TempMenuEntry = CopyMenuEntry(&MenuEntryFirmware);
+                        TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_FIRMWARE);
+                        AddMenuEntry(&MainMenu, TempMenuEntry);
+                    } // if
+                } // if
+                break;
 
-         case TAG_SHELL:
-            j = 0;
-            while ((FileName = FindCommaDelimited(SHELL_NAMES, j++)) != NULL) {
-               if (FileExists(SelfRootDir, FileName) && IsValidLoader(SelfRootDir, FileName)) {
-                  AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"EFI Shell", BuiltinIcon(BUILTIN_ICON_TOOL_SHELL),
-                               'S', FALSE);
-               }
-               MyFreePool(FileName);
-            } // while
-            break;
+            case TAG_SHELL:
+                j = 0;
+                while ((FileName = FindCommaDelimited(SHELL_NAMES, j++)) != NULL) {
+                    if (FileExists(SelfRootDir, FileName) && IsValidLoader(SelfRootDir, FileName)) {
+                        AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"EFI Shell", BuiltinIcon(BUILTIN_ICON_TOOL_SHELL),
+                                     'S', FALSE);
+                    }
+                MyFreePool(FileName);
+                } // while
+                break;
 
-         case TAG_GPTSYNC:
-            j = 0;
-            while ((FileName = FindCommaDelimited(GPTSYNC_NAMES, j++)) != NULL) {
-               if (FileExists(SelfRootDir, FileName) && IsValidLoader(SelfRootDir, FileName)) {
-                  AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"Hybrid MBR tool", BuiltinIcon(BUILTIN_ICON_TOOL_PART),
-                               'P', FALSE);
-               } // if
-               MyFreePool(FileName);
-            } // while
-            FileName = NULL;
-            break;
+            case TAG_GPTSYNC:
+                j = 0;
+                while ((FileName = FindCommaDelimited(GPTSYNC_NAMES, j++)) != NULL) {
+                    if (FileExists(SelfRootDir, FileName) && IsValidLoader(SelfRootDir, FileName)) {
+                        AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"Hybrid MBR tool", BuiltinIcon(BUILTIN_ICON_TOOL_PART),
+                                     'P', FALSE);
+                    } // if
+                    MyFreePool(FileName);
+                } // while
+                FileName = NULL;
+                break;
 
-         case TAG_GDISK:
-            j = 0;
-            while ((FileName = FindCommaDelimited(GDISK_NAMES, j++)) != NULL) {
-               if (FileExists(SelfRootDir, FileName) && IsValidLoader(SelfRootDir, FileName)) {
-                  AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"disk partitioning tool",
-                               BuiltinIcon(BUILTIN_ICON_TOOL_PART), 'G', FALSE);
-               } // if
-               MyFreePool(FileName);
-            } // while
-            FileName = NULL;
-            break;
-         
-         case TAG_NETBOOT:
-            j = 0;
-            while ((FileName = FindCommaDelimited(NETBOOT_NAMES, j++)) != NULL) {
-               if (FileExists(SelfRootDir, FileName) && IsValidLoader(SelfRootDir, FileName)) {
-                  AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"Netboot",
-                               BuiltinIcon(BUILTIN_ICON_TOOL_NETBOOT), 'N', FALSE);
-               } // if
-               MyFreePool(FileName);
-            } // while
-            FileName = NULL;
-            break;
+            case TAG_GDISK:
+                j = 0;
+                while ((FileName = FindCommaDelimited(GDISK_NAMES, j++)) != NULL) {
+                    if (FileExists(SelfRootDir, FileName) && IsValidLoader(SelfRootDir, FileName)) {
+                        AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"disk partitioning tool",
+                                     BuiltinIcon(BUILTIN_ICON_TOOL_PART), 'G', FALSE);
+                    } // if
+                    MyFreePool(FileName);
+                } // while
+                FileName = NULL;
+                break;
+            
+            case TAG_NETBOOT:
+                j = 0;
+                while ((FileName = FindCommaDelimited(NETBOOT_NAMES, j++)) != NULL) {
+                    if (FileExists(SelfRootDir, FileName) && IsValidLoader(SelfRootDir, FileName)) {
+                        AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"Netboot",
+                                     BuiltinIcon(BUILTIN_ICON_TOOL_NETBOOT), 'N', FALSE);
+                    } // if
+                    MyFreePool(FileName);
+                } // while
+                FileName = NULL;
+                break;
 
-         case TAG_APPLE_RECOVERY:
-            FileName = StrDuplicate(L"\\com.apple.recovery.boot\\boot.efi");
-            for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
-               if ((Volumes[VolumeIndex]->RootDir != NULL) && (FileExists(Volumes[VolumeIndex]->RootDir, FileName)) &&
-                   IsValidLoader(Volumes[VolumeIndex]->RootDir, FileName)) {
-                  SPrint(Description, 255, L"Apple Recovery on %s", Volumes[VolumeIndex]->VolName);
-                  AddToolEntry(Volumes[VolumeIndex]->DeviceHandle, FileName, Description,
-                               BuiltinIcon(BUILTIN_ICON_TOOL_APPLE_RESCUE), 'R', TRUE);
-               } // if
-            } // for
-            MyFreePool(FileName);
-            FileName = NULL;
-            break;
+            case TAG_APPLE_RECOVERY:
+                FileName = StrDuplicate(L"\\com.apple.recovery.boot\\boot.efi");
+                for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
+                    if ((Volumes[VolumeIndex]->RootDir != NULL) &&
+                        (FileExists(Volumes[VolumeIndex]->RootDir, FileName)) &&
+                        IsValidLoader(Volumes[VolumeIndex]->RootDir, FileName)) {
+                            SPrint(Description, 255, L"Apple Recovery on %s", Volumes[VolumeIndex]->VolName);
+                            AddToolEntry(Volumes[VolumeIndex]->DeviceHandle, FileName, Description,
+                                         BuiltinIcon(BUILTIN_ICON_TOOL_APPLE_RESCUE), 'R', TRUE);
+                    } // if
+                } // for
+                MyFreePool(FileName);
+                FileName = NULL;
+                break;
 
-         case TAG_WINDOWS_RECOVERY:
-            j = 0;
-            while ((FileName = FindCommaDelimited(GlobalConfig.WindowsRecoveryFiles, j++)) != NULL) {
-               SplitVolumeAndFilename(&FileName, &VolName);
-               for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
-                  if ((Volumes[VolumeIndex]->RootDir != NULL) && (FileExists(Volumes[VolumeIndex]->RootDir, FileName)) &&
-                      IsValidLoader(Volumes[VolumeIndex]->RootDir, FileName) &&
-                      ((VolName == NULL) || (StriCmp(VolName, Volumes[VolumeIndex]->VolName) == 0))) {
-                     SPrint(Description, 255, L"Microsoft Recovery on %s", Volumes[VolumeIndex]->VolName);
-                     AddToolEntry(Volumes[VolumeIndex]->DeviceHandle, FileName, Description,
-                                  BuiltinIcon(BUILTIN_ICON_TOOL_WINDOWS_RESCUE), 'R', TRUE);
-                  } // if
-               } // for
-            } // while
-            MyFreePool(FileName);
-            FileName = NULL;
-            MyFreePool(VolName);
-            VolName = NULL;
-            break;
+            case TAG_WINDOWS_RECOVERY:
+                j = 0;
+                while ((FileName = FindCommaDelimited(GlobalConfig.WindowsRecoveryFiles, j++)) != NULL) {
+                    SplitVolumeAndFilename(&FileName, &VolName);
+                    for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
+                        if ((Volumes[VolumeIndex]->RootDir != NULL) &&
+                            (FileExists(Volumes[VolumeIndex]->RootDir, FileName)) &&
+                            IsValidLoader(Volumes[VolumeIndex]->RootDir, FileName) &&
+                            ((VolName == NULL) || MyStriCmp(VolName, Volumes[VolumeIndex]->VolName))) {
+                                SPrint(Description, 255, L"Microsoft Recovery on %s", Volumes[VolumeIndex]->VolName);
+                                AddToolEntry(Volumes[VolumeIndex]->DeviceHandle, FileName, Description,
+                                             BuiltinIcon(BUILTIN_ICON_TOOL_WINDOWS_RESCUE), 'R', TRUE);
+                        } // if
+                    } // for
+                } // while
+                MyFreePool(FileName);
+                FileName = NULL;
+                MyFreePool(VolName);
+                VolName = NULL;
+                break;
 
-         case TAG_MOK_TOOL:
-            FindTool(MokLocations, MOK_NAMES, L"MOK utility", BUILTIN_ICON_TOOL_MOK_TOOL);
-            break;
+            case TAG_MOK_TOOL:
+                FindTool(MokLocations, MOK_NAMES, L"MOK utility", BUILTIN_ICON_TOOL_MOK_TOOL);
+                break;
 
-         case TAG_MEMTEST:
-            FindTool(MEMTEST_LOCATIONS, MEMTEST_NAMES, L"Memory test utility", BUILTIN_ICON_TOOL_MEMTEST);
-            break;
+            case TAG_MEMTEST:
+                FindTool(MEMTEST_LOCATIONS, MEMTEST_NAMES, L"Memory test utility", BUILTIN_ICON_TOOL_MEMTEST);
+                break;
 
-      } // switch()
-   } // for
+        } // switch()
+    } // for
 } // static VOID ScanForTools
 
 // Rescan for boot loaders
 static VOID RescanAll(BOOLEAN DisplayMessage) {
-   EG_PIXEL           BGColor;
-
-   BGColor.b = 255;
-   BGColor.g = 175;
-   BGColor.r = 100;
-   BGColor.a = 0;
-   if (DisplayMessage)
-      egDisplayMessage(L"Scanning for new boot loaders; please wait....", &BGColor);
-   FreeList((VOID ***) &(MainMenu.Entries), &MainMenu.EntryCount);
-   MainMenu.Entries = NULL;
-   MainMenu.EntryCount = 0;
-   ReadConfig(GlobalConfig.ConfigFilename);
-   ConnectAllDriversToAllControllers();
-   ScanVolumes();
-   ScanForBootloaders();
-   ScanForTools();
-   SetupScreen();
+    EG_PIXEL           BGColor;
+
+    BGColor.b = 255;
+    BGColor.g = 175;
+    BGColor.r = 100;
+    BGColor.a = 0;
+    if (DisplayMessage)
+        egDisplayMessage(L"Scanning for new boot loaders; please wait....", &BGColor);
+    FreeList((VOID ***) &(MainMenu.Entries), &MainMenu.EntryCount);
+    MainMenu.Entries = NULL;
+    MainMenu.EntryCount = 0;
+    ReadConfig(GlobalConfig.ConfigFilename);
+    ConnectAllDriversToAllControllers();
+    ScanVolumes();
+    ScanForBootloaders();
+    ScanForTools();
+    SetupScreen();
 } // VOID RescanAll()
 
 #ifdef __MAKEWITH_TIANO
 
 // Minimal initialization function
 static VOID InitializeLib(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) {
-   gST            = SystemTable;
-   //    gImageHandle   = ImageHandle;
-   gBS            = SystemTable->BootServices;
-   //    gRS            = SystemTable->RuntimeServices;
-   gRT = SystemTable->RuntimeServices; // Some BDS functions need gRT to be set
-   EfiGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS);
-
-//   InitializeConsoleSim();
+    gST            = SystemTable;
+    //    gImageHandle   = ImageHandle;
+    gBS            = SystemTable->BootServices;
+    //    gRS            = SystemTable->RuntimeServices;
+    gRT = SystemTable->RuntimeServices; // Some BDS functions need gRT to be set
+    EfiGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS);
 }
 
 #endif
@@ -2051,37 +2049,37 @@ static VOID InitializeLib(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *System
 // Set up our own Secure Boot extensions....
 // Returns TRUE on success, FALSE otherwise
 static BOOLEAN SecureBootSetup(VOID) {
-   EFI_STATUS Status;
-   BOOLEAN    Success = FALSE;
-
-   if (secure_mode() && ShimLoaded()) {
-      Status = security_policy_install();
-      if (Status == EFI_SUCCESS) {
-         Success = TRUE;
-      } else {
-         Print(L"Failed to install MOK Secure Boot extensions");
-      }
-   }
-   return Success;
+    EFI_STATUS Status;
+    BOOLEAN    Success = FALSE;
+
+    if (secure_mode() && ShimLoaded()) {
+        Status = security_policy_install();
+        if (Status == EFI_SUCCESS) {
+            Success = TRUE;
+        } else {
+            Print(L"Failed to install MOK Secure Boot extensions");
+        }
+    }
+    return Success;
 } // VOID SecureBootSetup()
 
 // Remove our own Secure Boot extensions....
 // Returns TRUE on success, FALSE otherwise
 static BOOLEAN SecureBootUninstall(VOID) {
-   EFI_STATUS Status;
-   BOOLEAN    Success = TRUE;
-
-   if (secure_mode()) {
-      Status = security_policy_uninstall();
-      if (Status != EFI_SUCCESS) {
-         Success = FALSE;
-         BeginTextScreen(L"Secure Boot Policy Failure");
-         Print(L"Failed to uninstall MOK Secure Boot extensions; forcing a reboot.");
-         PauseForKey();
-         refit_call4_wrapper(RT->ResetSystem, EfiResetCold, EFI_SUCCESS, 0, NULL);
-      }
-   }
-   return Success;
+    EFI_STATUS Status;
+    BOOLEAN    Success = TRUE;
+
+    if (secure_mode()) {
+        Status = security_policy_uninstall();
+        if (Status != EFI_SUCCESS) {
+            Success = FALSE;
+            BeginTextScreen(L"Secure Boot Policy Failure");
+            Print(L"Failed to uninstall MOK Secure Boot extensions; forcing a reboot.");
+            PauseForKey();
+            refit_call4_wrapper(RT->ResetSystem, EfiResetCold, EFI_SUCCESS, 0, NULL);
+        }
+    }
+    return Success;
 } // VOID SecureBootUninstall
 
 // Sets the global configuration filename; will be CONFIG_FILE_NAME unless the
@@ -2089,29 +2087,29 @@ static BOOLEAN SecureBootUninstall(VOID) {
 // If an error is encountered, leaves the value alone (it should be set to
 // CONFIG_FILE_NAME when GlobalConfig is initialized).
 static VOID SetConfigFilename(EFI_HANDLE ImageHandle) {
-   EFI_LOADED_IMAGE *Info;
-   CHAR16 *Options, *FileName;
-   EFI_STATUS Status;
-   INTN Where;
-
-   Status = refit_call3_wrapper(BS->HandleProtocol, ImageHandle, &LoadedImageProtocol, (VOID **) &Info);
-   if ((Status == EFI_SUCCESS) && (Info->LoadOptionsSize > 0)) {
-      Options = (CHAR16 *) Info->LoadOptions;
-      Where = FindSubString(L" -c ", Options);
-      if (Where >= 0) {
-         FileName = StrDuplicate(&Options[Where + 4]);
-         Where = FindSubString(L" ", FileName);
-         if (Where > 0)
-            FileName[Where] = L'\0';
-
-         if (FileExists(SelfDir, FileName)) {
-            GlobalConfig.ConfigFilename = FileName;
-         } else {
-            Print(L"Specified configuration file (%s) doesn't exist; using\n'refind.conf' default\n", FileName);
-            MyFreePool(FileName);
-         } // if/else
-      } // if
-   } // if
+EFI_LOADED_IMAGE *Info;
+CHAR16 *Options, *FileName;
+EFI_STATUS Status;
+INTN Where;
+
+Status = refit_call3_wrapper(BS->HandleProtocol, ImageHandle, &LoadedImageProtocol, (VOID **) &Info);
+    if ((Status == EFI_SUCCESS) && (Info->LoadOptionsSize > 0)) {
+        Options = (CHAR16 *) Info->LoadOptions;
+        Where = FindSubString(L" -c ", Options);
+        if (Where >= 0) {
+            FileName = StrDuplicate(&Options[Where + 4]);
+            Where = FindSubString(L" ", FileName);
+            if (Where > 0)
+                FileName[Where] = L'\0';
+
+            if (FileExists(SelfDir, FileName)) {
+                GlobalConfig.ConfigFilename = FileName;
+            } else {
+                Print(L"Specified configuration file (%s) doesn't exist; using\n'refind.conf' default\n", FileName);
+                MyFreePool(FileName);
+            } // if/else
+        } // if
+    } // if
 } // VOID SetConfigFilename()
 
 //