STATIC EFI_INPUT_READ_KEY_EX g_org_read_key_ex = NULL;
STATIC EFI_INPUT_READ_KEY g_org_read_key = NULL;
+STATIC EFI_LOCATE_HANDLE g_org_locate_handle = NULL;
+
+BOOLEAN ventoy_is_cdrom_dp_exist(VOID)
+{
+ UINTN i = 0;
+ UINTN Count = 0;
+ EFI_HANDLE *Handles = NULL;
+ EFI_STATUS Status = EFI_SUCCESS;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL;
+
+ Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiDevicePathProtocolGuid,
+ NULL, &Count, &Handles);
+ if (EFI_ERROR(Status))
+ {
+ return FALSE;
+ }
+
+ for (i = 0; i < Count; i++)
+ {
+ Status = gBS->HandleProtocol(Handles[i], &gEfiDevicePathProtocolGuid, (VOID **)&DevicePath);
+ if (EFI_ERROR(Status))
+ {
+ continue;
+ }
+
+ while (!IsDevicePathEnd(DevicePath))
+ {
+ if (MEDIA_DEVICE_PATH == DevicePath->Type && MEDIA_CDROM_DP == DevicePath->SubType)
+ {
+ FreePool(Handles);
+ return TRUE;
+ }
+
+ DevicePath = NextDevicePathNode(DevicePath);
+ }
+ }
+
+ FreePool(Handles);
+ return FALSE;
+}
+
#if 0
/* Block IO procotol */
#endif
MapLba, secRead * 2048, pCurBuf);
if (EFI_ERROR(Status))
{
- debug("Raw disk read block failed %r", Status);
+ debug("Raw disk read block failed %r LBA:%lu Count:%u", Status, MapLba, secRead);
return Status;
}
if (i < Count)
{
Status = gBS->ConnectController(ControllerHandle, DrvHandles, NULL, TRUE);
- debug("Connect partition driver:<%r>", Status);
+ debug("ventoy_connect_driver:<%s> <%r>", DrvName, Status);
goto end;
}
if (i < Count)
{
Status = gBS->ConnectController(ControllerHandle, DrvHandles, NULL, TRUE);
- debug("Connect partition driver:<%r>", Status);
+ debug("ventoy_connect_driver:<%s> <%r>", DrvName, Status);
goto end;
}
EFI_BLOCK_IO_PROTOCOL *pBlockIo = &(gBlockData.BlockIo);
ventoy_fill_device_path();
+
+ debug("install block io protocol %p", ImageHandle);
+ ventoy_debug_pause();
gBlockData.Media.BlockSize = 2048;
gBlockData.Media.LastBlock = ImgSize / 2048 - 1;
Status = ventoy_connect_driver(gBlockData.Handle, L"Disk I/O Driver");
debug("Connect disk IO driver %r", Status);
- ventoy_debug_pause();
Status = ventoy_connect_driver(gBlockData.Handle, L"Partition Driver");
debug("Connect partition driver %r", Status);
ventoy_wrapper_file_set_pos(EFI_FILE_HANDLE This, UINT64 Position)
{
(VOID)This;
+
+ if (Position <= g_efi_file_replace.FileSizeBytes)
+ {
+ g_efi_file_replace.CurPos = Position;
+ }
+ else
+ {
+ g_efi_file_replace.CurPos = g_efi_file_replace.FileSizeBytes;
+ }
- g_efi_file_replace.CurPos = Position;
return EFI_SUCCESS;
}
CHAR8 TmpName[256];
ventoy_virt_chunk *virt = NULL;
+ debug("## ventoy_wrapper_file_open <%s> ", Name);
+
Status = g_original_fopen(This, New, Name, Mode, Attributes);
if (EFI_ERROR(Status))
{
return Status;
}
}
+
+ if (StrCmp(Name, L"\\EFI\\BOOT") == 0)
+ {
+ (*New)->Open = ventoy_wrapper_file_open;
+ }
}
return Status;
return EFI_SUCCESS;
}
+#if 0
+/* Fixup the 1st cdrom influnce for Windows boot */
+#endif
+
+STATIC EFI_STATUS EFIAPI ventoy_wrapper_locate_handle
+(
+ IN EFI_LOCATE_SEARCH_TYPE SearchType,
+ IN EFI_GUID *Protocol, OPTIONAL
+ IN VOID *SearchKey, OPTIONAL
+ IN OUT UINTN *BufferSize,
+ OUT EFI_HANDLE *Buffer
+)
+{
+ UINTN i;
+ EFI_HANDLE Handle = NULL;
+ EFI_STATUS Status = EFI_SUCCESS;
+
+ Status = g_org_locate_handle(SearchType, Protocol, SearchKey, BufferSize, Buffer);
+
+ if (EFI_SUCCESS == Status && Protocol && CompareGuid(&gEfiBlockIoProtocolGuid, Protocol))
+ {
+ for (i = 0; i < (*BufferSize) / sizeof(EFI_HANDLE); i++)
+ {
+ if (Buffer[i] == gBlockData.Handle)
+ {
+ Handle = Buffer[0];
+ Buffer[0] = Buffer[i];
+ Buffer[i] = Handle;
+ break;
+ }
+ }
+ }
+
+ return Status;
+}
+
+EFI_STATUS ventoy_hook_1st_cdrom_start(VOID)
+{
+ g_org_locate_handle = gBS->LocateHandle;
+ gBS->LocateHandle = ventoy_wrapper_locate_handle;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS ventoy_hook_1st_cdrom_stop(VOID)
+{
+ gBS->LocateHandle = g_org_locate_handle;
+ g_org_locate_handle = NULL;
+
+ return EFI_SUCCESS;
+}
+