]> code.delx.au - refind/blobdiff - refind/lib.c
Tweaks to disc-eject functionality.
[refind] / refind / lib.c
index c7c5734b877a31bbfa81825bdbe65421b88ecf1f..be95e0c23d703f2058b39466a3582d3dab1eb0fe 100644 (file)
@@ -47,6 +47,7 @@
 #include "icns.h"
 #include "screen.h"
 #include "refit_call_wrapper.h"
+#include "RemovableMedia.h"
 
 // variables
 
@@ -366,13 +367,14 @@ static VOID ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT BOOLEAN *Bootabl
             Volume->OSIconName = L"grub,linux";
             Volume->OSName = L"Linux";
 
-        // GRUB in BIOS boot partition:
-        } else if (FindMem(SectorBuffer, 512, "Geom\0Read\0 Error", 16) >= 0) {
-            Volume->HasBootCode = TRUE;
-            Volume->OSIconName = L"grub,linux";
-            Volume->OSName = L"Linux";
-            Volume->VolName = L"BIOS Boot Partition";
-            *Bootable = TRUE;
+//         // Below doesn't produce a bootable entry, so commented out for the moment....
+//         // GRUB in BIOS boot partition:
+//         } else if (FindMem(SectorBuffer, 512, "Geom\0Read\0 Error", 16) >= 0) {
+//             Volume->HasBootCode = TRUE;
+//             Volume->OSIconName = L"grub,linux";
+//             Volume->OSName = L"Linux";
+//             Volume->VolName = L"BIOS Boot Partition";
+//             *Bootable = TRUE;
 
         } else if ((*((UINT32 *)(SectorBuffer + 502)) == 0 &&
                     *((UINT32 *)(SectorBuffer + 506)) == 50000 &&
@@ -1275,3 +1277,31 @@ CHAR16 *FindCommaDelimited(IN CHAR16 *InString, IN UINTN Index) {
    } // if
    return (FoundString);
 } // CHAR16 *FindCommaDelimited()
+
+
+static EFI_GUID AppleRemovableMediaGuid = APPLE_REMOVABLE_MEDIA_PROTOCOL_GUID;
+
+// Eject all removable media.
+// Returns TRUE if any media were ejected, FALSE otherwise.
+BOOLEAN EjectMedia(VOID) {
+   EFI_STATUS                      Status;
+   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 (FALSE); // probably not an Apple system
+
+   for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
+      Handle = Handles[HandleIndex];
+      Status = refit_call3_wrapper(BS->HandleProtocol, Handle, &AppleRemovableMediaGuid, (VOID **) &Ejectable);
+      if (EFI_ERROR(Status))
+         continue;
+      Status = refit_call1_wrapper(Ejectable->Eject, Ejectable);
+      if (!EFI_ERROR(Status))
+         Ejected++;
+   }
+   FreePool(Handles);
+   return (Ejected > 0);
+} // VOID EjectMedia()