X-Git-Url: https://code.delx.au/refind/blobdiff_plain/d2370de648f795ccdf7fe76786c9516568cbe529..39f21d099c9fb310bae28b54dc68d266ed610ed7:/refind/lib.c diff --git a/refind/lib.c b/refind/lib.c index 958bb52..3c9e4c4 100644 --- a/refind/lib.c +++ b/refind/lib.c @@ -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)