From 2eb4a9ca3c35a44bb35b7a0998ff036797a8580e Mon Sep 17 00:00:00 2001
From: srs5694
Date: Thu, 26 Apr 2012 02:56:23 -0400
Subject: [PATCH] Keep .icns files out of tag list when scan_all_linux_kernels
is set; sort entries within each directory by time stamp.
---
NEWS.txt | 26 +++++-
docs/refind/configfile.html | 4 +-
docs/refind/installing.html | 83 +++++++++++++----
docs/refind/linux.html | 57 ++++++++++--
docs/refind/todo.html | 171 ++++++++++++++++++++++++++----------
refind/lib.c | 51 ++++++++---
refind/lib.h | 3 +-
refind/main.c | 115 ++++++++++++++++++++----
refind/menu.c | 10 +--
9 files changed, 410 insertions(+), 110 deletions(-)
diff --git a/NEWS.txt b/NEWS.txt
index 2947edf..6519380 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -1,4 +1,28 @@
-0.3.0 (?/??/2012):
+0.3.1 (?/??/2012):
+------------------
+
+- Modified loader scanning code to sort boot loader entries within a
+ directory by modification time, so that the most recently-modified loader
+ is first among those in a given directory. Thus, if you specify a
+ directory name (or volume name, for loaders stored in the root directory
+ of a volume) as the default_selection, the most recent of those loaders
+ will be the default. This is intended to help with Linux kernel
+ maintenance when using the EFI stub loader; set up this way, the most
+ recent kernel copied to your kernel directory will be the default,
+ obviating the need to adjust the refind.conf file when adding a new
+ kernel. If you want to change the default among those in the default
+ directory, you can use "touch" to adjust the modification timestamp.
+
+- Tweaked code to find loader-specific .icns file so that it finds files
+ for Linux kernels without .efi extensions. In this case, files should be
+ named the same as the kernels they match, but with .icns extensions. For
+ instance, bzImage-3.3.2 should have an icon called bzImage-3.3.2.icns.
+ (The old code would have looked for an icon called bzImage-3.3.icns.)
+
+- Eliminated bogus OS loader tags for filenames that end in ".icns" when
+ the scan_all_linux_kernels option is set.
+
+0.3.0 (4/22/2012):
------------------
- I'm officially upgrading this project's status from "alpha" to "beta" and
diff --git a/docs/refind/configfile.html b/docs/refind/configfile.html
index b43819d..0e736dc 100644
--- a/docs/refind/configfile.html
+++ b/docs/refind/configfile.html
@@ -199,8 +199,8 @@ timeout 20
default_selection |
- A substring of a boot loader's title |
- Sets the default boot OS based on the loader's title, which appears in the main menu when you select the loader; the text reads Boot Title from Disk. You can enter any substring of Title as the default_selection, so long as it's two or more characters in length. Be sure you enter a unique substring, though; rEFInd stops searching when it finds the first match. One-character entries are matched against the first character of the title, except for digits, which refer to the numeric order of the boot loader entries. (Note: In version 0.2.0, only the first character of this entry was used, and was matched against the first character of the title.) |
+ A substring of a boot loader's title; or a numeric position |
+ Sets the default boot OS based on the loader's title, which appears in the main menu beneath the icons when you select the loader. You can enter any substring of the title as the default_selection, so long as it's two or more characters in length. It's best to use a unique substring, since rEFInd stops searching when it finds the first match. Because rEFInd sorts entries within a directory in descending order by file modification time, if you specify a directory (or volume name, for loaders in a partition's root directory) as the default_selection, the most recent loader in that directory will be the default. One-character entries are matched against the first character of the title, except for digits, which refer to the numeric order of the boot loader entries. (Note: In version 0.2.0, only the first character of this entry was used, and was matched against the first character of the title.) |
diff --git a/docs/refind/installing.html b/docs/refind/installing.html
index e7dcaef..ee18e52 100644
--- a/docs/refind/installing.html
+++ b/docs/refind/installing.html
@@ -14,7 +14,7 @@
by Roderick W. Smith, rodsmith@rodsbooks.com
- Originally written: 3/14/2012; last Web page update: 4/22/2012, referencing rEFInd 0.3.0
+ Originally written: 3/14/2012; last Web page update: 4/24/2012, referencing rEFInd 0.3.0
I'm a technical writer and consultant specializing in Linux technologies. 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!
@@ -113,6 +113,8 @@ Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 191284 16604 174681 9% /boot/efi
+
+
This example shows that /dev/sda1 is mounted at /boot/efi, which is a typical configuration. (The ESP can be on another disk or partition, but /dev/sda1 is the most common place for an ESP.) If your output shows /boot or / under the Mounted on column, then your ESP isn't mounted. If you get a df: `/boot/efi': No such file or directory error message, then the /boot/efi directory doesn't even exist. In such cases, you may need to jump through some extra hoops, as described on my EFI Boot Loader Installation page.
Assuming the ESP is mounted at /boot/efi, you can install the rEFInd files as follows (you must be root to issue these commands, or precede each of them with sudo):
@@ -127,8 +129,6 @@ Filesystem 1K-blocks Used Available Use% Mounted on
Rename the configuration file by typing mv refind.conf-sample refind.conf. Consult the Editing the rEFInd Configuration File page for information on how to adjust your options.
-
-
On a UEFI-based system, type efibootmgr -c -l \\EFI\\refind\\refind_x64.efi -L rEFInd to add rEFInd to your EFI's list of available boot loaders, which it stores in NVRAM. (Adjust the path to the binary as required if you install somewhere else.) You may need to install this program on some systems; it's a standard part of most distributions' repositories.
@@ -145,25 +145,67 @@ Filesystem 1K-blocks Used Available Use% Mounted on
Installing rEFInd Using Mac OS X
-
+
The procedure for installing rEFInd on a Mac is similar to that for installing it under Linux, except that you can (and probably should) install it to OS X's system partition or some other HFS+ partition rather than to the ESP, and you must use the bless utility rather than efibootmgr. To be precise, you should follow these steps:
-- Open a Terminal window in which you'll type the following commands.
-
-- If you want to install rEFInd on your ESP, you must first mount it. You can do this by typing mkdir /Volumes/esp followed by sudo mount_msdos /dev/disk0s1 /Volumes/esp. Note that this step is optional, and in fact I've had problems blessing a boot loader on the ESP, so I don't recommend doing this. Also, you may need to change /dev/disk0s1 to something else if your ESP is at an unusual location. Use a tool such as my GPT fdisk (gdisk) to examine your partition table to find your ESP if necessary.
-
-- Type sudo mkdir -p /efi/refind to create a suitable directory for rEFInd. If you want to place rEFInd on the ESP or some other partition, you should adjust the pathname appropriately, as in /Volumes/esp/efi/refind. Alternatively, you can use the Finder to create the directory.
-
-- Copy the files in the refind subdirectory of the rEFInd binary package to the like-named directory you've just created. You can do this in the Finder or by typing sudo cp -r refind/* /efi/refind/ in your Terminal window after changing into the rEFInd package's main directory.
-
-- Remove the file for the version of rEFInd you're not using, as in sudo rm /efi/refind/refind_ia32.efi on a Mac with a 64-bit EFI or sudo rm /efi/refind/refind_x64.efi on a Mac with a 32-bit EFI.
-
-- If this is your first installation, type sudo mv /efi/refind/refind.conf-sample /efi/refind/refind.conf (adjusting the path as necessary) to rename the sample configuration file so that it will serve as a real configuration file. (Again, you can do this with the Finder, if you prefer.)
-
-- Type sudo bless --setBoot --folder /efi/refind --file /efi/refind/refind_x64.efi to tell the computer to use rEFInd as the primary boot program. (Adjust the path and filename as necessary if you're placing rEFInd somewhere else or using the 32-bit version.) In theory, you can bless a boot file on an ESP by adding --mount /Volumes/mounpoint to the command, where /Volumes/mounpoint is the location where you've mounted the partition. In practice, though, I've never gotten this to work. (If you know the trick to blessing a boot program on an ESP, please drop me a line.)
+- Open a Terminal window in which you'll type the following
+ commands.
+
+- If you want to install rEFInd on your ESP, you must first mount it. You
+ can do this by typing mkdir /Volumes/esp followed by
+ sudo mount -t msdos /dev/disk0s1 /Volumes/esp. Note
+ that this step is usually optional, and it makes the procedure a bit
+ more complex, so you might want to forego it. On the other hand,
+ installing to the ESP is required if you're using the whole-disk
+ encryption feature of OS X 10.7. Note that you may need to change
+ /dev/disk0s1 to something else if your ESP is at an unusual
+ location. Use a tool such as my GPT fdisk (gdisk)
+ to examine your partition table to find your ESP if necessary.
+
+- Type sudo mkdir -p /efi/refind to create a suitable
+ directory for rEFInd. If you want to place rEFInd on the ESP or some
+ other partition, you should adjust the pathname appropriately, as in
+ /Volumes/esp/efi/refind. Alternatively, you can use the Finder
+ to create the directory.
+
+- Copy the files in the refind subdirectory of the rEFInd binary
+ package to the like-named directory you've just created. You can do
+ this in the Finder or by typing sudo cp -r refind/*
+ /efi/refind/ in your Terminal window after changing into the
+ rEFInd package's main directory.
+
+- Remove the file for the version of rEFInd you're not using, as in
+ sudo rm /efi/refind/refind_ia32.efi on a Mac with a
+ 64-bit EFI or sudo rm /efi/refind/refind_x64.efi on a
+ Mac with a 32-bit EFI.
+
+- If this is your first installation, type sudo mv
+ /efi/refind/refind.conf-sample /efi/refind/refind.conf
+ (adjusting the path as necessary) to rename the sample configuration
+ file so that it will serve as a real configuration file. (Again, you
+ can do this with the Finder, if you prefer.)
+
+- "Bless" rEFInd by typing one of the following two commands:
+
+ - If you're installing rEFInd to an ordinary HFS+ volume, type sudo bless --setBoot --folder /efi/refind --file
+ /efi/refind/refind_x64.efi. (Adjust the path and filename as
+ necessary if you're placing rEFInd somewhere else or using the
+ 32-bit version.)
+ - If you're installing rEFInd on the ESP, type sudo bless --mount /Volumes/esp --setBoot --file
+ /Volumes/esp/efi/refind/refind_x64.efi, adjusting the mount
+ point and exact path to the file as appropriate for your
+ installation.
+
+ As per the Warning earlier, do not use bless's
+ --info option to try to confirm the change to the boot status
+ unless you're certain you do not have an Advanced Format hard
+ disk.
@@ -264,6 +306,13 @@ Filesystem 1K-blocks Used Available Use% Mounted on
protective MBR. You can obtain the file from the original rEFIt package.
+Drivers—You can install drivers to extend the capabilities
+ of the EFI. Most notably, filesystem drivers for ext2fs and ReiserFS
+ are available. These can enable you to boot a Linux kernel with EFI
+ stub support from an ext2fs, ext3fs, or ReiserFS partition. See the Using EFI Drivers page for more on this
+ topic.
+
I've seen links to other versions of these tools from time to time on the Web, so if you try one of these programs and it crashes or behaves strangely, try performing a Web search; you may turn up something that works better for you than the one to which I've linked.
diff --git a/docs/refind/linux.html b/docs/refind/linux.html
index 9232a3b..a0e985c 100644
--- a/docs/refind/linux.html
+++ b/docs/refind/linux.html
@@ -123,20 +123,48 @@ another possibility.
-- rEFInd looks for boot loaders whose names include the strings bzImage or vmlinuz and that end in .efi. For instance, bzImage-3.3.0.efi or vmlinuz-3.3.0-fc17.efi would match, and trigger subsequent steps in this procedure. Note that to use this system, you must give your kernel file a .efi extension, at least on the ESP (or other boot loader partition)!
+- rEFInd looks for boot loaders whose names include the strings
+ bzImage or vmlinuz and that end in .efi. For
+ instance, bzImage-3.3.0.efi or vmlinuz-3.3.0-fc17.efi
+ would match, and trigger subsequent steps in this procedure. Beginning
+ with version 0.3.0, if you uncomment the
+ scan_all_linux_kernels option in refind.conf, rEFInd
+ will also scan for kernels without a .efi filename
+ extension. This option is not the default, though, because it can pick
+ up old kernels that lack EFI stub loader support and even non-kernel
+ files, such as icon files named to give a kernel a unique icon.
-- rEFInd looks for an initial RAM disk in the same directory as the kernel file. A matching initial RAM disk has a name that begins with init and that includes the same version string as the kernel. The version string is defined as the part of the filename from the first digit to the last digit, inclusive. Note that the version string can include non-digits. For instance, the version string for bzImage-3.3.0.efi is 3.3.0, which matches initramfs-3.3.0.bz; and vmlinuz-3.3.0-fc17.efi's version string is 3.3.0-fc17, which matches initrd-3.3.0-fc17.img. Many other matches are possible. If an initial RAM disk is identified, rEFInd passes a suitable initrd= option to the kernel when it boots.
+- rEFInd looks for an initial RAM disk in the same directory as the
+ kernel file. A matching initial RAM disk has a name that begins with
+ init and that includes the same version string as the kernel.
+ The version string is defined as the part of the filename from the
+ first digit to the last digit, inclusive. Note that the version string
+ can include non-digits. For instance, the version string for
+ bzImage-3.3.0.efi is 3.3.0, which matches
+ initramfs-3.3.0.bz; and vmlinuz-3.3.0-fc17.efi's
+ version string is 3.3.0-fc17, which matches
+ initrd-3.3.0-fc17.img. Many other matches are possible. If an
+ initial RAM disk is identified, rEFInd passes a suitable
+ initrd= option to the kernel when it boots.
-- rEFInd looks for a file called refind_linux.conf in the same directory as the kernel file. This file is a practical requirement for booting from an auto-detected kernel. It consists of a series of lines, each of which consists of a label followed by a series of kernel options. The first line sets default options, and subsequent lines set options that are accessible from the main menu tag's submenu screen.
+- rEFInd looks for a file called refind_linux.conf in the same
+ directory as the kernel file. This file is a practical requirement for
+ booting from an auto-detected kernel. It consists of a series of lines,
+ each of which consists of a label followed by a series of kernel
+ options. The first line sets default options, and subsequent lines set
+ options that are accessible from the main menu tag's submenu
+ screen.
The intent of this system is that distribution maintainers can place their kernels, initial RAM disks, and a refind_linux.conf file in their own subdirectory on the ESP. rEFInd will detect their kernels and create one main menu entry for each kernel. Each entry will implement as many options as there are lines in the refind_linux.conf file. In this way, two or more distributions can each maintain their boot loader entries, without being too concerned about who maintains rEFInd as a whole.
+The scan_all_linux_kernels option is intended to help users and distribution maintainers when rEFInd is used in conjunction with a Linux filesystem driver for EFI or when the ESP is mounted as the Linux /boot partition. In these cases, if all the kernels in Linux's /boot directory include EFI stub loader support, rEFInd will automatically detect and use kernels installed in the usual way, such as via an automatic system update. You won't even need to move or rename your kernels. You will need to set up a refind_linux.conf file and you may need to install a driver or set the also_scan_dirs option in refind.conf; but these are one-time requirements. Set up in this way, ongoing maintenance to handle kernel updates drops to zero!
+
As an example, consider the following file configuration:
@@ -174,18 +202,33 @@ total 17943
Your kernels must be compiled with EFI stub loader support.
-You can't set a submenu option to boot via a different boot loader, such as ELILO or GRUB; all the submenu options apply to a single boot loader—that is, a single kernel. (rEFInd will still detect other boot loaders and provide separate main-menu tags for them, though.)
+You can't set a submenu option to boot via a different boot loader,
+ such as ELILO or GRUB; all the submenu options apply to a single boot
+ loader—that is, a single kernel. (rEFInd will still detect other
+ boot loaders and provide separate main-menu tags for them,
+ though.)
-If an installation includes two or more kernel files, each one receives its own main-menu entry; you can't combine them together in one menu item. This is essentially a corollary of the preceding limitation. The result can be an overburdened main menu if your system has many kernels.
+If an installation includes two or more kernel files, each one receives
+ its own main-menu entry; you can't combine them together in one menu
+ item. This is essentially a corollary of the preceding limitation. The
+ result can be an overburdened main menu if your system has many
+ kernels.
-All the kernels in a given directory use the same refind_linux.conf file. If you need to set different options for different kernels, you'll need to place those kernels in different directories.
+All the kernels in a given directory use the same
+ refind_linux.conf file. If you need to set different options
+ for different kernels, you'll need to place those kernels in different
+ directories.
-You must place your kernels in a directory other than the one that holds the main rEFInd .efi file. This is because rEFInd does not scan its own directory for boot loaders.
+You must place your kernels in a directory other than the one that
+ holds the main rEFInd .efi file. This is because rEFInd does
+ not scan its own directory for boot loaders.
Ordinarily, a kernel booted in this way must reside on the ESP, or at least on another FAT partition. On a Macintosh, though, you can use HFS+ to house your kernel files. In fact, that may be necessary; my Mac Mini hangs when I try to boot a Linux kernel via an EFI stub loader from the computer's ESP, but it works fine when booting from an HFS+ partition. If you use EFI drivers, though, you can place your kernel on any filesystem for which an EFI driver exists. This list is currently rather limited (ext2fs/ext3fs, ReiserFS, ISO-9660, and HFS+), but even just one or two options might help a lot if you've got an undersized ESP or if copying your kernel file to the ESP is a hassle you'd rather avoid.
+Beginning with version 0.3.1, rEFInd sorts boot loader entries within each directory by time stamp, so that the most recent entry comes first. Thus, if you specify a directory name (or a volume label, for loaders stored in a volume's root directory) as the default_selection, rEFInd will make the most recent loader in the directory the default. This can obviate the need to adjust this configuration parameter when you add a new kernel; chances are you want the most recently-added kernel to be the default, and rEFInd makes it so when you set the default_selection in this way. If you don't want the latest kernel to become the default, you can use touch to give the desired kernel (or other boot loader) in the directory a more recent time stamp, or you can set default_selection to a value that uniquely identifies your desired default loader.
+
On the whole, this method of configuration has a lot going for it. For distribution maintainers, if you place your Linux kernel files (with EFI stub support) on the ESP, with suitable filenames, matching initial RAM disk files, and a refind_linux.conf file, then any rEFInd 0.2.3 or later installation should detect your files, even if the user installs another distribution with another rEFInd that takes over from yours. (If the user, or this other rEFInd installation, disables auto-detection, this won't work.)
diff --git a/docs/refind/todo.html b/docs/refind/todo.html
index 09e78ea..a6e06bf 100644
--- a/docs/refind/todo.html
+++ b/docs/refind/todo.html
@@ -97,55 +97,132 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com
-- Testing! rEFIt was complex enough that changes such as the ones I've made have the potential to disrupt the program's operation in unexpected ways. Since the initial 0.2.0 release, I've continued to add features to rEFInd, and every new feature is another way for bugs to get into the program. I can only test on a handful of systems with a limited number of configurations. Therefore, if you try rEFInd and run into bugs, please report them to me!
-
-- Currently, rEFInd can detect whether it's compiled for x86 or x86-64 systems and displays this information in its "About" screen (AboutrEFInd() in main.c). I'd like to add detection for Itanium and ARM systems, but I have no way to test such changes.
-
-- I have little talent with graphics manipulation programs, so rEFInd's boot logo, such as it is, is pretty weak. If you have artistic talent and would like to create a rEFInd logo, please feel free to send it to me. I won't make any final decision about changes until at least June 30 of 2012.
+- Testing! rEFIt was complex enough that changes such as the ones I've
+ made have the potential to disrupt the program's operation in
+ unexpected ways. Since the initial 0.2.0 release, I've continued to add
+ features to rEFInd, and every new feature is another way for bugs to
+ get into the program. I can only test on a handful of systems with a
+ limited number of configurations. Therefore, if you try rEFInd and run
+ into bugs, please report them to me!
+
+- Currently, rEFInd can detect whether it's compiled for x86 or
+ x86-64 systems and displays this information in its "About"
+ screen (AboutrEFInd() in main.c). I'd like to add detection for Itanium
+ and ARM systems, but I have no way to test such changes.
+
+- I have little talent with graphics manipulation programs, so rEFInd's
+ boot logo, such as it is, is pretty weak. If you have artistic talent
+ and would like to create a rEFInd logo, please feel free to send it to
+ me. I won't make any final decision about changes until at least June
+ 30 of 2012.
- rEFIt's original design, and hence rEFInd's design, enables easy
-theming by replacing icon files. If you'd like to design a new theme for
-rEFInd, feel free to submit it. I might or might not replace the icons it
-uses now (most of which come from the Oxygen Icons package), but I may
-provide a way to make selecting a theme from one of several installed
-themes easy, and provide links to themes on this Web site (or even host
-them on the project's Sourceforge page). For more information on designing themes for rEFInd, see the Theming rEFInd page.
-
-- The code could be more flexible in its handling of the sizes of various graphical elements, and particularly drawn text. Prior to version 0.2.2, submenu text was invisible on UEFI-based PCs with 800x600 and smaller displays because of an inability to properly crop the graphics fields that hold the text. With version 0.2.2, I've put a band-aid on this problem by reducing the field size so that it now works on 800x600 displays, but smaller displays still suffer from this problem. This is just an example of the inflexibility of certain layout issues within rEFInd.
-
-- Text mode has a known display glitch: Not all loaders are shown until you use the cursor keys to move down the list, effectively "drawing" the "invisible" tags. This obviously needs to be fixed.
-
-- Although the ICNS file format used by rEFInd supports multiple image sizes, if a size that rEFInd needs isn't present in the file, rEFInd can't use the icon. The ability to scale images to the desired size would be useful.
-
-- EFI supports network boots. rEFInd doesn't, but it would be nice if it would.
-
-- I would like to be able to specify the volume on which a boot loader resides using a partition GUID value, but extracting a GUID from the partition data is harder than extracting the volume's label or counting up the filesystem numbers.
-
-- It would be useful to be able to specify paths to boot loaders and/or initial RAM disks relative to the rEFInd directory (or the boot loader's directory, in the case of initrds).
-
-- There's currently no way to create a manual boot stanza for a BIOS-booted OS. This isn't a big priority for me personally, but I can see how it could be for some people.
-
-- I'd like to find a way to get rEFInd to launch BIOS boot loaders on UEFI-based systems. This option currently works only on Macs—or at least, I've not gotten it to work on any of my UEFI-based PCs. (I have an idea about this, but haven't yet investigated it in detail. If you'd like to help on this, e-mail me for my thoughts.)
-
-- The Gigabyte Hybrid EFI has a bug that causes the allegedly case-insensitive StriCmp() function to perform a case-sensitive comparison. This causes any number of bugs in file matching. For instance: Changing the case of icon filename extensions (or various other parts of icon filenames) causes icons to be replaced by ugly "generic" ones; and rEFInd sometimes appears in its own menu (the firmware sometimes returns an all-caps version of the filename, but other times returns the filename with the correct case, causing a mismatch if the path includes lowercase elements). Some of these problems can be overcome by converting both strings to be compared to one case before doing the comparison, but others aren't so easy, since I think StriCmp() is being called internally to the EFI. In any event, it'd be nice to fix some of these problems. OTOH, this is a workaround for a bug on just one EFI implementation, and a dismal one at that, so I'm inclined to just let it go.
-
-- 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.
-
-- The Page Up and Page Down keys work in a rather strange way—a result of an admittedly quick fix on my part to a problem with a data structure that makes implementation of scrolling harder than it ought to be.
-
-- I'd like to find a way to enable users to enter customizations for boot options and then save them to the refind.conf file.
-
-- Auto-detected boot loaders are currently displayed in an arbitrary order, aside from the crude internal/external/optical distinctions, which can be affected by the order of options in scanfor. I'd like to sort entries by file timestamp within each directory, with the newest entry first. This will be beneficial because using the directory name as the entry in default_selection will then return the most recent boot loader in that directory, which is most likely the desired result when you upgrade a Linux kernel with an EFI stub loader. (As it is, to guarantee use of the most recent kernel, you must update refind.conf.) There might also be other ways to sort entries to some beneficial end, but I haven't thought of any.
-
-- It should be possible to override specific auto-detected boot loader settings—say, to disable one specific boot loader or change its icon.
-
-- A way to read boot options set via efibootmgr, bless, or similar options from NVRAM to add to the boot set would be useful.
-
-- A way to examine and change the NVRAM settings could be useful. This would enable a CD-based boot of rEFInd to fix a broken disk boot. Perhaps this could be done via a separate tool that could be launched much like the shell or gptsync.
-
-- I'd like to find a way to have rEFInd re-scan removable media when they're inserted.
-
-- The code is in need of review to search for memory leaks and similar problems.
+ theming by replacing icon files. If you'd like to design a new theme
+ for rEFInd, feel free to submit it. I might or might not replace the
+ icons it uses now (most of which come from the Oxygen Icons package),
+ but I may provide a way to make selecting a theme from one of several
+ installed themes easy, and provide links to themes on this Web site (or
+ even host them on the project's Sourceforge page). For more information
+ on designing themes for rEFInd, see the Theming
+ rEFInd page.
+
+- The code could be more flexible in its handling of the sizes of various
+ graphical elements, and particularly drawn text. Prior to version
+ 0.2.2, submenu text was invisible on UEFI-based PCs with 800x600 and
+ smaller displays because of an inability to properly crop the graphics
+ fields that hold the text. With version 0.2.2, I've put a band-aid on
+ this problem by reducing the field size so that it now works on 800x600
+ displays, but smaller displays still suffer from this problem. This is
+ just an example of the inflexibility of certain layout issues within
+ rEFInd.
+
+- Text mode has a known display glitch: Not all loaders are shown until
+ you use the cursor keys to move down the list, effectively "drawing"
+ the "invisible" tags. This obviously needs to be fixed.
+
+- Although the ICNS file format used by rEFInd supports multiple image
+ sizes, if a size that rEFInd needs isn't present in the file, rEFInd
+ can't use the icon. The ability to scale images to the desired size
+ would be useful.
+
+- EFI supports network boots. rEFInd doesn't, but it would be nice if it
+ would.
+
+- I would like to be able to specify the volume on which a boot loader
+ resides using a partition GUID value, but extracting a GUID from the
+ partition data is harder than extracting the volume's label or counting
+ up the filesystem numbers.
+
+- It would be useful to be able to specify paths to boot loaders and/or
+ initial RAM disks relative to the rEFInd directory (or the boot
+ loader's directory, in the case of initrds).
+
+- There's currently no way to create a manual boot stanza for a
+ BIOS-booted OS. This isn't a big priority for me personally, but I can
+ see how it could be for some people.
+
+- I'd like to find a way to get rEFInd to launch BIOS boot loaders on
+ UEFI-based systems. This option currently works only on Macs—or
+ at least, I've not gotten it to work on any of my UEFI-based PCs. (I
+ have an idea about this, but haven't yet investigated it in detail. If
+ you'd like to help on this, e-mail me for my
+ thoughts.)
+
+- The Gigabyte Hybrid
+ EFI has a bug that causes the allegedly case-insensitive
+ StriCmp() function to perform a case-sensitive comparison.
+ This causes any number of bugs in file matching. For instance: Changing
+ the case of icon filename extensions (or various other parts of icon
+ filenames) causes icons to be replaced by ugly "generic" ones; and
+ rEFInd sometimes appears in its own menu (the firmware sometimes
+ returns an all-caps version of the filename, but other times returns
+ the filename with the correct case, causing a mismatch if the path
+ includes lowercase elements). Some of these problems can be overcome by
+ converting both strings to be compared to one case before doing the
+ comparison, but others aren't so easy, since I think StriCmp()
+ is being called internally to the EFI. In any event, it'd be nice to
+ fix some of these problems. OTOH, this is a workaround for a bug on
+ just one EFI implementation, and a dismal one at that, so I'm inclined
+ to just let it go.
+
+- 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.
+
+- The Page Up and Page Down keys work in a rather strange way—a
+ result of an admittedly quick fix on my part to a problem with a data
+ structure that makes implementation of scrolling harder than it ought
+ to be.
+
+- The Shutdown option works correctly on Macs, but not on UEFI-based PCs.
+ On such systems, Shutdown reboots the computer. This should be
+ fixed.
+
+- I'd like to find a way to enable users to enter customizations for boot
+ options and then save them to the refind.conf file.
+
+- It should be possible to override specific auto-detected boot loader
+ settings—say, to disable one specific boot loader or change its
+ icon.
+
+- A way to read boot options set via efibootmgr, bless,
+ or similar options from NVRAM to add to the boot set would be
+ useful.
+
+- A way to examine and change the NVRAM settings could be useful. This
+ would enable a CD-based boot of rEFInd to fix a broken disk boot.
+ Perhaps this could be done via a separate tool that could be launched
+ much like the shell or gptsync.
+
+- I'd like to find a way to have rEFInd re-scan removable media when
+ they're inserted.
+
+- I'd like to give the user the ability to set custom options on a
+ per-boot basis, similar to what's possible in GRUB.
+
+- The code is in need of review to search for memory leaks and similar
+ problems.
diff --git a/refind/lib.c b/refind/lib.c
index 9685005..333e0c1 100644
--- a/refind/lib.c
+++ b/refind/lib.c
@@ -1024,20 +1024,20 @@ CHAR16 * Basename(IN CHAR16 *Path)
return FileName;
}
-VOID ReplaceExtension(IN OUT CHAR16 *Path, IN CHAR16 *Extension)
+// Replaces a filename extension of ".efi" with the specified string
+// (Extension). If the input Path doesn't end in ".efi", Extension
+// is added to the existing filename.
+VOID ReplaceEfiExtension(IN OUT CHAR16 *Path, IN CHAR16 *Extension)
{
- UINTN i;
+ UINTN PathLen;
- for (i = StrLen(Path); i >= 0; i--) {
- if (Path[i] == '.') {
- Path[i] = 0;
- break;
- }
- if (Path[i] == '\\' || Path[i] == '/')
- break;
- }
+ PathLen = StrLen(Path);
+ // Note: Do StriCmp() twice to work around Gigabyte Hybrid EFI case-sensitivity bug....
+ if ((PathLen >= 4) && ((StriCmp(&Path[PathLen - 4], L".efi") == 0) || (StriCmp(&Path[PathLen - 4], L".EFI") == 0))) {
+ Path[PathLen - 4] = 0;
+ } // if
StrCat(Path, Extension);
-}
+} // VOID ReplaceEfiExtension()
//
// memory string search
@@ -1118,6 +1118,35 @@ VOID MergeStrings(IN OUT CHAR16 **First, IN CHAR16 *Second, CHAR16 AddChar) {
} // if/else
} // static CHAR16* MergeStrings()
+// Takes an input pathname (*Path) and returns the part of the filename from
+// the final dot onwards, converted to lowercase. If the filename includes
+// no dots, or if the input is NULL, returns an empty (but allocated) string.
+// The calling function is responsible for freeing the memory associated with
+// the return value.
+CHAR16 *FindExtension(IN CHAR16 *Path) {
+ CHAR16 *Extension;
+ BOOLEAN Found = FALSE, FoundSlash = FALSE;
+ UINTN i;
+
+ Extension = AllocateZeroPool(sizeof(CHAR16));
+ if (Path) {
+ i = StrLen(Path);
+ while ((!Found) && (!FoundSlash) && (i >= 0)) {
+ if (Path[i] == L'.')
+ Found = TRUE;
+ else if ((Path[i] == L'/') || (Path[i] == L'\\'))
+ FoundSlash = TRUE;
+ if (!Found)
+ i--;
+ } // while
+ if (Found) {
+ MergeStrings(&Extension, &Path[i], 0);
+ StrLwr(Extension);
+ } // if (Found)
+ } // if
+ return (Extension);
+} // CHAR16 *FindExtension
+
// Takes an input pathname (*Path) and locates the final directory component
// of that name. For instance, if the input path is 'EFI\foo\bar.efi', this
// function returns the string 'foo'.
diff --git a/refind/lib.h b/refind/lib.h
index d888b98..8b63c22 100644
--- a/refind/lib.h
+++ b/refind/lib.h
@@ -91,13 +91,14 @@ BOOLEAN DirIterNext(IN OUT REFIT_DIR_ITER *DirIter, IN UINTN FilterMode, IN CHAR
EFI_STATUS DirIterClose(IN OUT REFIT_DIR_ITER *DirIter);
CHAR16 * Basename(IN CHAR16 *Path);
-VOID ReplaceExtension(IN OUT CHAR16 *Path, IN CHAR16 *Extension);
+VOID ReplaceEfiExtension(IN OUT CHAR16 *Path, IN CHAR16 *Extension);
INTN FindMem(IN VOID *Buffer, IN UINTN BufferLength, IN VOID *SearchString, IN UINTN SearchStringLength);
VOID ReinitVolumes(VOID);
BOOLEAN StriSubCmp(IN CHAR16 *TargetStr, IN CHAR16 *BigStr);
VOID MergeStrings(IN OUT CHAR16 **First, IN CHAR16 *Second, CHAR16 AddChar);
+CHAR16 *FindExtension(IN CHAR16 *Path);
CHAR16 *FindLastDirName(IN CHAR16 *Path);
CHAR16 *FindPath(IN CHAR16* FullPath);
CHAR16 *FindNumbers(IN CHAR16 *InString);
diff --git a/refind/main.c b/refind/main.c
index 35c125a..21d8aa8 100644
--- a/refind/main.c
+++ b/refind/main.c
@@ -88,6 +88,14 @@ static REFIT_MENU_SCREEN AboutMenu = { L"About", NULL, 0, NULL, 0, NULL, 0,
REFIT_CONFIG GlobalConfig = { FALSE, FALSE, 0, 0, 20, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL,
{TAG_SHELL, TAG_ABOUT, TAG_SHUTDOWN, TAG_REBOOT, 0, 0, 0, 0, 0 }};
+// Structure used to hold boot loader filenames and time stamps in
+// a linked list; used to sort entries within a directory.
+struct LOADER_LIST {
+ CHAR16 *FileName;
+ EFI_TIME TimeStamp;
+ struct LOADER_LIST *NextEntry;
+};
+
//
// misc functions
//
@@ -96,7 +104,7 @@ static VOID AboutrEFInd(VOID)
{
if (AboutMenu.EntryCount == 0) {
AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
- AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.3.0");
+ AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.3.0.2");
AddMenuInfoLine(&AboutMenu, L"");
AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer");
AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012 Roderick W. Smith");
@@ -556,7 +564,7 @@ VOID SetLoaderDefaults(LOADER_ENTRY *Entry, CHAR16 *LoaderPath, IN REFIT_VOLUME
// locate a custom icon for the loader
StrCpy(IconFileName, LoaderPath);
- ReplaceExtension(IconFileName, L".icns");
+ ReplaceEfiExtension(IconFileName, L".icns");
if (FileExists(Volume->RootDir, IconFileName)) {
Entry->me.Image = LoadIcns(Volume->RootDir, IconFileName, 128);
} else if ((StrLen(PathOnly) == 0) && (Volume->VolIconImage != NULL)) {
@@ -626,7 +634,8 @@ LOADER_ENTRY * AddLoaderEntry(IN CHAR16 *LoaderPath, IN CHAR16 *LoaderTitle, IN
CleanUpPathNameSlashes(LoaderPath);
Entry = InitializeLoaderEntry(NULL);
if (Entry != NULL) {
- Entry->Title = StrDuplicate(LoaderTitle);
+ Entry->Title = StrDuplicate((LoaderTitle != NULL) ? LoaderTitle : LoaderPath);
+// Entry->Title = StrDuplicate(LoaderTitle);
Entry->me.Title = PoolPrint(L"Boot %s from %s", (LoaderTitle != NULL) ? LoaderTitle : LoaderPath, Volume->VolName);
Entry->me.Row = 0;
Entry->me.BadgeImage = Volume->VolBadgeImage;
@@ -641,24 +650,85 @@ LOADER_ENTRY * AddLoaderEntry(IN CHAR16 *LoaderPath, IN CHAR16 *LoaderTitle, IN
return(Entry);
} // LOADER_ENTRY * AddLoaderEntry()
+// Returns -1 if (Time1 < Time2), +1 if (Time1 > Time2), or 0 if
+// (Time1 == Time2). Precision is only to the nearest second; since
+// this is used for sorting boot loader entries, differences smaller
+// than this are likely to be meaningless (and unlikely!).
+INTN TimeComp(EFI_TIME *Time1, 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 has a limited
+ // purpose.
+ 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);
+} // 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;
+ FreePool(Temp->FileName);
+ FreePool(Temp);
+ } // while
+} // static VOID CleanUpLoaderList()
+
// Scan an individual directory for EFI boot loader files and, if found,
-// add them to the list.
+// add them to the list. Sorts the entries within the loader directory
+// so that the most recent one appears first in the list.
static VOID ScanLoaderDir(IN REFIT_VOLUME *Volume, IN CHAR16 *Path, IN CHAR16 *Pattern)
{
EFI_STATUS Status;
REFIT_DIR_ITER DirIter;
EFI_FILE_INFO *DirEntry;
- CHAR16 FileName[256];
+ CHAR16 FileName[256], *Extension;
+ struct LOADER_LIST *LoaderList = NULL, *NewLoader;
if (!SelfDirPath || !Path || ((StriCmp(Path, SelfDirPath) == 0) && Volume != SelfVolume) ||
(StriCmp(Path, SelfDirPath) != 0)) {
// 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(DirEntry->FileName, L"TextMode.efi") == 0 ||
StriCmp(DirEntry->FileName, L"ebounce.efi") == 0 ||
StriCmp(DirEntry->FileName, L"GraphicsConsole.efi") == 0 ||
+ StriCmp(Extension, L".icns") == 0 ||
StriSubCmp(L"shell", DirEntry->FileName))
continue; // skip this
@@ -666,8 +736,20 @@ static VOID ScanLoaderDir(IN REFIT_VOLUME *Volume, IN CHAR16 *Path, IN CHAR16 *P
SPrint(FileName, 255, L"\\%s\\%s", Path, DirEntry->FileName);
else
SPrint(FileName, 255, L"\\%s", DirEntry->FileName);
- AddLoaderEntry(FileName, NULL, Volume);
- }
+ NewLoader = AllocateZeroPool(sizeof(struct LOADER_LIST));
+ if (NewLoader != NULL) {
+ NewLoader->FileName = StrDuplicate(FileName);
+ NewLoader->TimeStamp = DirEntry->ModificationTime;
+ LoaderList = AddLoaderListEntry(LoaderList, NewLoader);
+ } // if
+ FreePool(Extension);
+ } // while
+ NewLoader = LoaderList;
+ while (NewLoader != NULL) {
+ AddLoaderEntry(NewLoader->FileName, NULL, Volume);
+ NewLoader = NewLoader->NextEntry;
+ } // while
+ CleanUpLoaderList(LoaderList);
Status = DirIterClose(&DirIter);
if (Status != EFI_NOT_FOUND) {
if (Path)
@@ -727,12 +809,8 @@ static VOID ScanEfiFiles(REFIT_VOLUME *Volume) {
// Scan user-specified (or additional default) directories....
i = 0;
while ((Directory = FindCommaDelimited(GlobalConfig.AlsoScan, i++)) != NULL) {
+ CleanUpPathNameSlashes(Directory);
Length = StrLen(Directory);
- // Some EFI implementations won't read a directory if the path ends in
- // a backslash, so eliminate this character, if it's present....
- while ((Length > 0) && (Directory[Length - 1] == L'\\')) {
- Directory[--Length] = 0;
- } // while
if (Length > 0)
ScanLoaderDir(Volume, Directory, MatchPatterns);
FreePool(Directory);
@@ -1132,6 +1210,7 @@ static UINTN ScanDriverDir(IN CHAR16 *Path)
EFI_FILE_INFO *DirEntry;
CHAR16 FileName[256];
+ CleanUpPathNameSlashes(Path);
// look through contents of the directory
DirIterOpen(SelfRootDir, Path, &DirIter);
while (DirIterNext(&DirIter, 2, LOADER_MATCH_PATTERNS, &DirEntry)) {
@@ -1219,6 +1298,9 @@ Done:
return Status;
} /* EFI_STATUS ConnectAllDriversToAllControllers() */
+// Load all EFI drivers from rEFInd's "drivers" subdirectory and from the
+// directories specified by the user in the "scan_driver_dirs" configuration
+// file line.
static VOID LoadDrivers(VOID)
{
CHAR16 *Directory;
@@ -1226,17 +1308,14 @@ static VOID LoadDrivers(VOID)
// load drivers from the "drivers" subdirectory of rEFInd's home directory
Directory = StrDuplicate(SelfDirPath);
+ CleanUpPathNameSlashes(Directory);
MergeStrings(&Directory, L"drivers", L'\\');
NumFound += ScanDriverDir(Directory);
// Scan additional user-specified driver directories....
while ((Directory = FindCommaDelimited(GlobalConfig.DriverDirs, i++)) != NULL) {
+ CleanUpPathNameSlashes(Directory);
Length = StrLen(Directory);
- // Some EFI implementations won't read a directory if the path ends in
- // a backslash, so eliminate this character, if it's present....
- while ((Length > 0) && (Directory[Length - 1] == L'\\')) {
- Directory[--Length] = 0;
- } // while
if (Length > 0)
NumFound += ScanDriverDir(Directory);
FreePool(Directory);
@@ -1245,7 +1324,7 @@ static VOID LoadDrivers(VOID)
// connect all devices
if (NumFound > 0)
ConnectAllDriversToAllControllers();
-}
+} /* static VOID LoadDrivers() */
static VOID ScanForBootloaders(VOID) {
UINTN i;
diff --git a/refind/menu.c b/refind/menu.c
index 4a7f1c9..8b86c35 100644
--- a/refind/menu.c
+++ b/refind/menu.c
@@ -251,8 +251,7 @@ static INTN FindMenuShortcutEntry(IN REFIT_MENU_SCREEN *Screen, IN CHAR16 *Short
Shortcut[0] -= ('a' - 'A');
if (Shortcut[0]) {
for (i = 0; i < Screen->EntryCount; i++) {
- if (Screen->Entries[i]->ShortcutDigit == Shortcut[0] ||
- Screen->Entries[i]->ShortcutLetter == Shortcut[0]) {
+ if (Screen->Entries[i]->ShortcutDigit == Shortcut[0] || Screen->Entries[i]->ShortcutLetter == Shortcut[0]) {
return i;
} // if
} // for
@@ -807,10 +806,10 @@ VOID MainMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, IN UINT
UINTN RunMenu(IN REFIT_MENU_SCREEN *Screen, OUT REFIT_MENU_ENTRY **ChosenEntry)
{
MENU_STYLE_FUNC Style = TextMenuStyle;
-
+
if (AllowGraphicsMode)
Style = GraphicsMenuStyle;
-
+
return RunGenericMenu(Screen, Style, -1, ChosenEntry);
}
@@ -823,8 +822,7 @@ UINTN RunMainMenu(IN REFIT_MENU_SCREEN *Screen, IN CHAR16* DefaultSelection, OUT
UINTN DefaultEntryIndex = -1;
if (DefaultSelection != NULL) {
- // Find a menu entry whose shortcut is the first character of DefaultSelection, or
- // whose
+ // Find a menu entry that includes *DefaultSelection as a substring
DefaultEntryIndex = FindMenuShortcutEntry(Screen, DefaultSelection);
// If that didn't work, should we scan more characters? For now, no.
}
--
2.39.2