From 953397f78420efbd81d4ab60a2c01da0d2c19711 Mon Sep 17 00:00:00 2001 From: srs5694 Date: Sat, 19 May 2012 01:31:28 -0400 Subject: [PATCH] Tweaks to disc-eject functionality. --- NEWS.txt | 6 ++++-- refind/lib.c | 12 ++++++++---- refind/lib.h | 2 +- refind/menu.c | 7 ++++--- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/NEWS.txt b/NEWS.txt index b133402..84e1371 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,8 +1,10 @@ 0.3.6 (?/??/2012): ------------------ -- Added new feature to eject CDs (and other removable media): Press F12 - to eject all such media. +- Added new feature to eject CDs (and other removable media): Press F12 to + eject all such media. This function works only on some Macs, though (it + relies on an Apple-specific EFI extension, and this extension isn't even + implemented on all Macs, much less on UEFI-based PCs). - Fixed a problem that could cause GRUB 2 to fail to read its configuration file when launched from rEFInd. diff --git a/refind/lib.c b/refind/lib.c index 2735fea..be95e0c 100644 --- a/refind/lib.c +++ b/refind/lib.c @@ -1281,16 +1281,17 @@ CHAR16 *FindCommaDelimited(IN CHAR16 *InString, IN UINTN Index) { static EFI_GUID AppleRemovableMediaGuid = APPLE_REMOVABLE_MEDIA_PROTOCOL_GUID; -// Eject all removable media -VOID EjectMedia(VOID) { +// Eject all removable media. +// Returns TRUE if any media were ejected, FALSE otherwise. +BOOLEAN EjectMedia(VOID) { EFI_STATUS Status; - UINTN HandleIndex, HandleCount = 0; + UINTN HandleIndex, HandleCount = 0, Ejected = 0; EFI_HANDLE *Handles, Handle; APPLE_REMOVABLE_MEDIA_PROTOCOL *Ejectable; Status = LibLocateHandle(ByProtocol, &AppleRemovableMediaGuid, NULL, &HandleCount, &Handles); if (EFI_ERROR(Status) || HandleCount == 0) - return; // probably not an Apple system + return (FALSE); // probably not an Apple system for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) { Handle = Handles[HandleIndex]; @@ -1298,6 +1299,9 @@ VOID EjectMedia(VOID) { if (EFI_ERROR(Status)) continue; Status = refit_call1_wrapper(Ejectable->Eject, Ejectable); + if (!EFI_ERROR(Status)) + Ejected++; } FreePool(Handles); + return (Ejected > 0); } // VOID EjectMedia() diff --git a/refind/lib.h b/refind/lib.h index d502f8a..f7e9eda 100644 --- a/refind/lib.h +++ b/refind/lib.h @@ -105,6 +105,6 @@ CHAR16 *FindPath(IN CHAR16* FullPath); CHAR16 *FindNumbers(IN CHAR16 *InString); CHAR16 *FindCommaDelimited(IN CHAR16 *InString, IN UINTN Index); -VOID EjectMedia(VOID); +BOOLEAN EjectMedia(VOID); #endif \ No newline at end of file diff --git a/refind/menu.c b/refind/menu.c index 1ed2aa9..d35cd11 100644 --- a/refind/menu.c +++ b/refind/menu.c @@ -461,9 +461,10 @@ static UINTN RunGenericMenu(IN REFIT_MENU_SCREEN *Screen, IN MENU_STYLE_FUNC Sty case SCAN_F10: egScreenShot(); break; - case 0x0016: // F12 - EjectMedia(); - break; + case 0x0016: // F12 + if (EjectMedia()) + MenuExit = MENU_EXIT_ESCAPE; + break; } switch (key.UnicodeChar) { case CHAR_LINEFEED: -- 2.39.2