+STATIC UINTN ventoy_get_current_device_path_id(VOID)
+{
+ UINTN i = 0;
+ UINTN Count = 0;
+ UINTN NameLen = 0;
+ UINTN MaxId = 0;
+ UINTN CurId = 0;
+ BOOLEAN Find = FALSE;
+ EFI_HANDLE *Handles = NULL;
+ EFI_STATUS Status = EFI_SUCCESS;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL;
+ VENDOR_DEVICE_PATH *venPath = NULL;
+
+ NameLen = StrSize(L"ventoy_xxx");
+
+ Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiDevicePathProtocolGuid,
+ NULL, &Count, &Handles);
+ if (EFI_ERROR(Status))
+ {
+ return 0;
+ }
+
+ for (i = 0; i < Count; i++)
+ {
+ Status = gBS->HandleProtocol(Handles[i], &gEfiDevicePathProtocolGuid, (VOID **)&DevicePath);
+ if (EFI_ERROR(Status))
+ {
+ continue;
+ }
+
+ if (DevicePath->Type == HARDWARE_DEVICE_PATH && DevicePath->SubType == HW_VENDOR_DP)
+ {
+ venPath = (VENDOR_DEVICE_PATH *)DevicePath;
+ if (CompareGuid(&venPath->Guid, &gVtoyBlockDevicePathGuid))
+ {
+ CurId = StrDecimalToUintn((CHAR16 *)(venPath + 1) + StrLen(L"ventoy_"));
+ MaxId = MAX(MaxId, CurId);
+ Find = TRUE;
+ }
+ }
+ }
+
+ FreePool(Handles);
+
+ return Find ? (MaxId + 1) : 0;
+}