]> code.delx.au - refind/blobdiff - refind/lib.c
Added "dont_scan_dirs" option to configuration file.
[refind] / refind / lib.c
index 2735fea54172624867e037100c740f4cce020ffd..71f76c57b9294ab41c53aa5c5017c78bed1bf844 100644 (file)
@@ -1200,7 +1200,8 @@ CHAR16 *FindLastDirName(IN CHAR16 *Path) {
 
 // Returns the directory portion of a pathname. For instance,
 // if FullPath is 'EFI\foo\bar.efi', this function returns the
-// string 'EFI\foo'.
+// string 'EFI\foo'. The calling function is responsible for
+// freeing the returned string's memory.
 CHAR16 *FindPath(IN CHAR16* FullPath) {
    UINTN i, LastBackslash = 0;
    CHAR16 *PathOnly;
@@ -1278,19 +1279,36 @@ CHAR16 *FindCommaDelimited(IN CHAR16 *InString, IN UINTN Index) {
    return (FoundString);
 } // CHAR16 *FindCommaDelimited()
 
+// 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).
+BOOLEAN IsIn(IN CHAR16 *SmallString, IN CHAR16 *List) {
+   UINTN     i = 0;
+   BOOLEAN   Found = FALSE;
+   CHAR16    *OneElement;
+
+   if (SmallString && List) {
+      while (!Found && (OneElement = FindCommaDelimited(List, i++))) {
+         if (StriCmp(OneElement, SmallString) == 0)
+            Found = TRUE;
+      } // while
+   } // if
+   return Found;
+} // BOOLEAN IsIn()
 
 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 +1316,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()