From 9bc87a77ec5a46dad543c5729ad6280f0d87a2c4 Mon Sep 17 00:00:00 2001 From: srs5694 Date: Fri, 9 Nov 2012 19:13:55 -0500 Subject: [PATCH] Added support for "volume" token in "submenuentry" items in manual boot stanzas. --- refind/config.c | 75 +++++++++++++++++++++++++++---------------------- refind/main.c | 2 +- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/refind/config.c b/refind/config.c index a2c36fe..e70d6b2 100644 --- a/refind/config.c +++ b/refind/config.c @@ -436,6 +436,39 @@ VOID ReadConfig(VOID) MyFreePool(File.Buffer); } /* VOID ReadConfig() */ +// Finds a volume with the specified Identifier (a volume label or a number +// followed by a colon, for the moment). If found, sets *Volume to point to +// that volume. If not, leaves it unchanged. +// Returns TRUE if a match was found, FALSE if not. +static BOOLEAN FindVolume(REFIT_VOLUME **Volume, CHAR16 *Identifier) { + UINTN i = 0, CountedVolumes = 0; + INTN Number = -1; + BOOLEAN Found = FALSE; + + if ((StrLen(Identifier) >= 2) && (Identifier[StrLen(Identifier) - 1] == L':') && + (Identifier[0] >= L'0') && (Identifier[0] <= L'9')) { + Number = (INTN) Atoi(Identifier); + } + while ((i < VolumesCount) && (!Found)) { + if (Number >= 0) { // User specified a volume by number + if (Volumes[i]->IsReadable) { + if (CountedVolumes == Number) { + *Volume = Volumes[i]; + Found = TRUE; + } + CountedVolumes++; + } // if + } else { // User specified a volume by label + if (StriCmp(Identifier, Volumes[i]->VolName) == 0) { + *Volume = Volumes[i]; + Found = TRUE; + } // if + } // if/else + i++; + } // while() + return (Found); +} // static VOID FindVolume() + static VOID AddSubmenu(LOADER_ENTRY *Entry, REFIT_FILE *File, REFIT_VOLUME *Volume, CHAR16 *Title) { REFIT_MENU_SCREEN *SubScreen; LOADER_ENTRY *SubEntry; @@ -458,6 +491,15 @@ static VOID AddSubmenu(LOADER_ENTRY *Entry, REFIT_FILE *File, REFIT_VOLUME *Volu SubEntry->LoaderPath = StrDuplicate(TokenList[1]); SubEntry->DevicePath = FileDevicePath(Volume->DeviceHandle, SubEntry->LoaderPath); + } else if ((StriCmp(TokenList[0], L"volume") == 0) && (TokenCount > 1)) { + if (FindVolume(&Volume, TokenList[1])) { + MyFreePool(SubEntry->me.Title); + SubEntry->me.Title = AllocateZeroPool(256 * sizeof(CHAR16)); + SPrint(SubEntry->me.Title, 255, L"Boot %s from %s", (Title != NULL) ? Title : L"Unknown", Volume->VolName); + SubEntry->me.BadgeImage = Volume->VolBadgeImage; + SubEntry->VolName = Volume->VolName; + } // if match found + } else if (StriCmp(TokenList[0], L"initrd") == 0) { MyFreePool(SubEntry->InitrdPath); SubEntry->InitrdPath = NULL; @@ -497,39 +539,6 @@ static VOID AddSubmenu(LOADER_ENTRY *Entry, REFIT_FILE *File, REFIT_VOLUME *Volu Entry->me.SubScreen = SubScreen; } // VOID AddSubmenu() -// Finds a volume with the specified Identifier (a volume label or a number -// followed by a colon, for the moment). If found, sets *Volume to point to -// that volume. If not, leaves it unchanged. -// Returns TRUE if a match was found, FALSE if not. -static BOOLEAN FindVolume(REFIT_VOLUME **Volume, CHAR16 *Identifier) { - UINTN i = 0, CountedVolumes = 0; - INTN Number = -1; - BOOLEAN Found = FALSE; - - if ((StrLen(Identifier) >= 2) && (Identifier[StrLen(Identifier) - 1] == L':') && - (Identifier[0] >= L'0') && (Identifier[0] <= L'9')) { - Number = (INTN) Atoi(Identifier); - } - while ((i < VolumesCount) && (!Found)) { - if (Number >= 0) { // User specified a volume by number - if (Volumes[i]->IsReadable) { - if (CountedVolumes == Number) { - *Volume = Volumes[i]; - Found = TRUE; - } - CountedVolumes++; - } // if - } else { // User specified a volume by label - if (StriCmp(Identifier, Volumes[i]->VolName) == 0) { - *Volume = Volumes[i]; - Found = TRUE; - } // if - } // if/else - i++; - } // while() - return (Found); -} // static VOID FindVolume() - // Adds the options from a SINGLE refind.conf stanza to a new loader entry and returns // that entry. The calling function is then responsible for adding the entry to the // list of entries. diff --git a/refind/main.c b/refind/main.c index 11a4181..721dbe7 100644 --- a/refind/main.c +++ b/refind/main.c @@ -115,7 +115,7 @@ static VOID AboutrEFInd(VOID) if (AboutMenu.EntryCount == 0) { AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT); - AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.4.7.1"); + AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.4.7.2"); AddMenuInfoLine(&AboutMenu, L""); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer"); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012 Roderick W. Smith"); -- 2.39.2