]> code.delx.au - refind/blobdiff - refind/lib.c
New ability to specify volume labels in "dont_scan_dirs" token to
[refind] / refind / lib.c
index 958bb525712565ecb778d99379a76f09411f41f0..3c9e4c4b66a4d28beb4bb056970cd2ae1cbc66f7 100644 (file)
@@ -929,7 +929,7 @@ VOID ScanVolumes(VOID)
     MBR_PARTITION_INFO      *MbrTable;
     UINTN                   PartitionIndex;
     UINT8                   *SectorBuffer1, *SectorBuffer2;
-    UINTN                   SectorSum, i;
+    UINTN                   SectorSum, i, VolNumber = 0;
 
     MyFreePool(Volumes);
     Volumes = NULL;
@@ -949,6 +949,8 @@ VOID ScanVolumes(VOID)
         Volume = AllocateZeroPool(sizeof(REFIT_VOLUME));
         Volume->DeviceHandle = Handles[HandleIndex];
         ScanVolume(Volume);
+        if (Volume->IsReadable)
+           Volume->VolNumber = VolNumber++;
 
         AddListElement((VOID ***) &Volumes, &VolumesCount, Volume);
 
@@ -1520,6 +1522,39 @@ VOID FindVolumeAndFilename(IN EFI_DEVICE_PATH *loadpath, OUT REFIT_VOLUME **Devi
    MyFreePool(DeviceString);
 } // VOID FindVolumeAndFilename()
 
+// Splits a volume/filename string (e.g., "fs0:\EFI\BOOT") into separate
+// volume and filename components (e.g., "fs0" and "\EFI\BOOT"), returning
+// the filename component in the original *Path variable and the split-off
+// volume component in the *VolName variable.
+// Returns TRUE if both components are found, FALSE otherwise.
+BOOLEAN SplitVolumeAndFilename(IN OUT CHAR16 **Path, OUT CHAR16 **VolName) {
+   UINTN i = 0, Length;
+   CHAR16 *Filename;
+
+   if (*Path == NULL)
+      return FALSE;
+
+   if (*VolName != NULL) {
+      MyFreePool(*VolName);
+      *VolName = NULL;
+   }
+
+   Length = StrLen(*Path);
+   while ((i < Length) && ((*Path)[i] != L':')) {
+      i++;
+   } // while
+
+   if (i < Length) {
+      Filename = StrDuplicate((*Path) + i + 1);
+      (*Path)[i] = 0;
+      *VolName = *Path;
+      *Path = Filename;
+      return TRUE;
+   } else {
+      return FALSE;
+   }
+} // BOOLEAN SplitVolumeAndFilename()
+
 // Returns all the digits in the input string, including intervening
 // non-digit characters. For instance, if InString is "foo-3.3.4-7.img",
 // this function returns "3.3.4-7". If InString contains no digits,
@@ -1636,18 +1671,18 @@ BOOLEAN EjectMedia(VOID) {
 } // VOID EjectMedia()
 
 
-// // Return the GUID as a string, suitable for display to the user. Note that the calling
-// // function is responsible for freeing the allocated memory.
-// CHAR16 * GuidAsString(EFI_GUID *GuidData) {
-//    CHAR16 *TheString;
-// 
-//    TheString = AllocateZeroPool(42 * sizeof(CHAR16));
-//    if (TheString != 0) {
-//       SPrint (TheString, 82, L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-//               (UINTN)GuidData->Data1, (UINTN)GuidData->Data2, (UINTN)GuidData->Data3,
-//               (UINTN)GuidData->Data4[0], (UINTN)GuidData->Data4[1], (UINTN)GuidData->Data4[2],
-//               (UINTN)GuidData->Data4[3], (UINTN)GuidData->Data4[4], (UINTN)GuidData->Data4[5],
-//               (UINTN)GuidData->Data4[6], (UINTN)GuidData->Data4[7]);
-//    }
-//    return TheString;
-// } // GuidAsString(EFI_GUID *GuidData)
+// Return the GUID as a string, suitable for display to the user. Note that the calling
+// function is responsible for freeing the allocated memory.
+CHAR16 * GuidAsString(EFI_GUID *GuidData) {
+   CHAR16 *TheString;
+
+   TheString = AllocateZeroPool(42 * sizeof(CHAR16));
+   if (TheString != 0) {
+      SPrint (TheString, 82, L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+              (UINTN)GuidData->Data1, (UINTN)GuidData->Data2, (UINTN)GuidData->Data3,
+              (UINTN)GuidData->Data4[0], (UINTN)GuidData->Data4[1], (UINTN)GuidData->Data4[2],
+              (UINTN)GuidData->Data4[3], (UINTN)GuidData->Data4[4], (UINTN)GuidData->Data4[5],
+              (UINTN)GuidData->Data4[6], (UINTN)GuidData->Data4[7]);
+   }
+   return TheString;
+} // GuidAsString(EFI_GUID *GuidData)