1 /******************************************************************************
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include <Library/DebugLib.h>
23 #include <Library/PrintLib.h>
24 #include <Library/UefiLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/DevicePathLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/UefiRuntimeServicesTableLib.h>
30 #include <Library/UefiApplicationEntryPoint.h>
31 #include <Protocol/LoadedImage.h>
32 #include <Guid/FileInfo.h>
33 #include <Guid/FileSystemInfo.h>
34 #include <Protocol/BlockIo.h>
35 #include <Protocol/RamDisk.h>
36 #include <Protocol/SimpleFileSystem.h>
37 #include <Protocol/DriverBinding.h>
40 UINT8
*g_iso_data_buf
= NULL
;
41 UINTN g_iso_buf_size
= 0;
42 BOOLEAN gMemdiskMode
= FALSE
;
43 BOOLEAN gSector512Mode
= FALSE
;
45 ventoy_sector_flag
*g_sector_flag
= NULL
;
46 UINT32 g_sector_flag_num
= 0;
48 EFI_FILE_OPEN g_original_fopen
= NULL
;
49 EFI_FILE_CLOSE g_original_fclose
= NULL
;
50 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME g_original_open_volume
= NULL
;
52 /* EFI block device vendor device path GUID */
53 EFI_GUID gVtoyBlockDevicePathGuid
= VTOY_BLOCK_DEVICE_PATH_GUID
;
55 #define VENTOY_ISO9660_SECTOR_OVERFLOW 2097152
57 BOOLEAN g_fixup_iso9660_secover_enable
= FALSE
;
58 BOOLEAN g_fixup_iso9660_secover_start
= FALSE
;
59 UINT64 g_fixup_iso9660_secover_1st_secs
= 0;
60 UINT64 g_fixup_iso9660_secover_cur_secs
= 0;
61 UINT64 g_fixup_iso9660_secover_tot_secs
= 0;
63 STATIC UINTN g_keyboard_hook_count
= 0;
64 STATIC BOOLEAN g_blockio_start_record_bcd
= FALSE
;
65 STATIC BOOLEAN g_blockio_bcd_read_done
= FALSE
;
67 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*g_con_simple_input_ex
= NULL
;
68 STATIC EFI_INPUT_READ_KEY_EX g_org_read_key_ex
= NULL
;
69 STATIC EFI_INPUT_READ_KEY g_org_read_key
= NULL
;
71 STATIC EFI_LOCATE_HANDLE g_org_locate_handle
= NULL
;
73 STATIC UINT8 g_sector_buf
[2048];
74 STATIC EFI_BLOCK_READ g_sector_2048_read
= NULL
;
75 STATIC EFI_BLOCK_WRITE g_sector_2048_write
= NULL
;
77 STATIC UINTN g_DriverBindWrapperCnt
= 0;
78 STATIC DRIVER_BIND_WRAPPER g_DriverBindWrapperList
[MAX_DRIVER_BIND_WRAPPER
];
80 BOOLEAN
ventoy_is_cdrom_dp_exist(VOID
)
84 EFI_HANDLE
*Handles
= NULL
;
85 EFI_STATUS Status
= EFI_SUCCESS
;
86 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
= NULL
;
88 Status
= gBS
->LocateHandleBuffer(ByProtocol
, &gEfiDevicePathProtocolGuid
,
89 NULL
, &Count
, &Handles
);
90 if (EFI_ERROR(Status
))
95 for (i
= 0; i
< Count
; i
++)
97 Status
= gBS
->HandleProtocol(Handles
[i
], &gEfiDevicePathProtocolGuid
, (VOID
**)&DevicePath
);
98 if (EFI_ERROR(Status
))
103 while (!IsDevicePathEnd(DevicePath
))
105 if (MEDIA_DEVICE_PATH
== DevicePath
->Type
&& MEDIA_CDROM_DP
== DevicePath
->SubType
)
111 DevicePath
= NextDevicePathNode(DevicePath
);
120 /* Block IO procotol */
123 EFI_STATUS EFIAPI ventoy_block_io_reset
125 IN EFI_BLOCK_IO_PROTOCOL
*This
,
126 IN BOOLEAN ExtendedVerification
130 (VOID
)ExtendedVerification
;
134 STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
141 EFI_STATUS Status
= EFI_SUCCESS
;
146 UINT64 ReadStart
= 0;
148 UINT64 OverrideStart
= 0;
149 UINT64 OverrideEnd
= 0;
150 UINT8
*pCurBuf
= (UINT8
*)Buffer
;
151 ventoy_img_chunk
*pchunk
= g_chunk
;
152 ventoy_override_chunk
*pOverride
= g_override_chunk
;
153 EFI_BLOCK_IO_PROTOCOL
*pRawBlockIo
= gBlockData
.pRawBlockIo
;
155 debug("read iso sector %lu count %u Buffer:%p Align:%u", Sector
, Count
, Buffer
, pRawBlockIo
->Media
->IoAlign
);
157 ReadStart
= Sector
* 2048;
158 ReadEnd
= (Sector
+ Count
) * 2048;
160 for (i
= 0; Count
> 0 && i
< g_img_chunk_num
; i
++, pchunk
++)
162 if (Sector
>= pchunk
->img_start_sector
&& Sector
<= pchunk
->img_end_sector
)
164 if (g_chain
->disk_sector_size
== 512)
166 MapLba
= (Sector
- pchunk
->img_start_sector
) * 4 + pchunk
->disk_start_sector
;
168 else if (g_chain
->disk_sector_size
== 1024)
170 MapLba
= (Sector
- pchunk
->img_start_sector
) * 2 + pchunk
->disk_start_sector
;
172 else if (g_chain
->disk_sector_size
== 2048)
174 MapLba
= (Sector
- pchunk
->img_start_sector
) + pchunk
->disk_start_sector
;
176 else if (g_chain
->disk_sector_size
== 4096)
178 MapLba
= ((Sector
- pchunk
->img_start_sector
) >> 1) + pchunk
->disk_start_sector
;
181 secLeft
= pchunk
->img_end_sector
+ 1 - Sector
;
182 secRead
= (Count
< secLeft
) ? Count
: secLeft
;
184 Status
= pRawBlockIo
->ReadBlocks(pRawBlockIo
, pRawBlockIo
->Media
->MediaId
,
185 MapLba
, secRead
* 2048, pCurBuf
);
186 if (EFI_ERROR(Status
))
188 debug("Raw disk read block failed %r LBA:%lu Count:%u %p", Status
, MapLba
, secRead
, pCurBuf
);
194 pCurBuf
+= secRead
* 2048;
198 if (ReadStart
> g_chain
->real_img_size_in_bytes
)
204 pCurBuf
= (UINT8
*)Buffer
;
205 for (i
= 0; i
< g_override_chunk_num
; i
++, pOverride
++)
207 OverrideStart
= pOverride
->img_offset
;
208 OverrideEnd
= pOverride
->img_offset
+ pOverride
->override_size
;
210 if (OverrideStart
>= ReadEnd
|| ReadStart
>= OverrideEnd
)
215 if (ReadStart
<= OverrideStart
)
217 if (ReadEnd
<= OverrideEnd
)
219 CopyMem(pCurBuf
+ OverrideStart
- ReadStart
, pOverride
->override_data
, ReadEnd
- OverrideStart
);
223 CopyMem(pCurBuf
+ OverrideStart
- ReadStart
, pOverride
->override_data
, pOverride
->override_size
);
228 if (ReadEnd
<= OverrideEnd
)
230 CopyMem(pCurBuf
, pOverride
->override_data
+ ReadStart
- OverrideStart
, ReadEnd
- ReadStart
);
234 CopyMem(pCurBuf
, pOverride
->override_data
+ ReadStart
- OverrideStart
, OverrideEnd
- ReadStart
);
238 if (g_fixup_iso9660_secover_enable
&& (!g_fixup_iso9660_secover_start
) &&
239 pOverride
->override_size
== sizeof(ventoy_iso9660_override
))
241 ventoy_iso9660_override
*dirent
= (ventoy_iso9660_override
*)pOverride
->override_data
;
242 if (dirent
->first_sector
>= VENTOY_ISO9660_SECTOR_OVERFLOW
)
244 g_fixup_iso9660_secover_start
= TRUE
;
245 g_fixup_iso9660_secover_cur_secs
= 0;
250 if (g_blockio_start_record_bcd
&& FALSE
== g_blockio_bcd_read_done
)
252 if (*(UINT32
*)Buffer
== 0x66676572)
254 g_blockio_bcd_read_done
= TRUE
;
261 STATIC EFI_STATUS EFIAPI ventoy_write_iso_sector
268 EFI_STATUS Status
= EFI_SUCCESS
;
273 UINT64 ReadStart
= 0;
275 UINT8
*pCurBuf
= (UINT8
*)Buffer
;
276 ventoy_img_chunk
*pchunk
= g_chunk
;
277 EFI_BLOCK_IO_PROTOCOL
*pRawBlockIo
= gBlockData
.pRawBlockIo
;
279 debug("write iso sector %lu count %u", Sector
, Count
);
281 ReadStart
= Sector
* 2048;
282 ReadEnd
= (Sector
+ Count
) * 2048;
284 for (i
= 0; Count
> 0 && i
< g_img_chunk_num
; i
++, pchunk
++)
286 if (Sector
>= pchunk
->img_start_sector
&& Sector
<= pchunk
->img_end_sector
)
288 if (g_chain
->disk_sector_size
== 512)
290 MapLba
= (Sector
- pchunk
->img_start_sector
) * 4 + pchunk
->disk_start_sector
;
292 else if (g_chain
->disk_sector_size
== 1024)
294 MapLba
= (Sector
- pchunk
->img_start_sector
) * 2 + pchunk
->disk_start_sector
;
296 else if (g_chain
->disk_sector_size
== 2048)
298 MapLba
= (Sector
- pchunk
->img_start_sector
) + pchunk
->disk_start_sector
;
300 else if (g_chain
->disk_sector_size
== 4096)
302 MapLba
= ((Sector
- pchunk
->img_start_sector
) >> 1) + pchunk
->disk_start_sector
;
306 secLeft
= pchunk
->img_end_sector
+ 1 - Sector
;
307 secRead
= (Count
< secLeft
) ? Count
: secLeft
;
309 Status
= pRawBlockIo
->WriteBlocks(pRawBlockIo
, pRawBlockIo
->Media
->MediaId
,
310 MapLba
, secRead
* 2048, pCurBuf
);
311 if (EFI_ERROR(Status
))
313 debug("Raw disk write block failed %r LBA:%lu Count:%u", Status
, MapLba
, secRead
);
319 pCurBuf
+= secRead
* 2048;
326 EFI_STATUS EFIAPI ventoy_block_io_ramdisk_write
328 IN EFI_BLOCK_IO_PROTOCOL
*This
,
343 return EFI_WRITE_PROTECTED
;
346 CopyMem(g_iso_data_buf
+ (Lba
* 2048), Buffer
, BufferSize
);
351 EFI_STATUS EFIAPI ventoy_block_io_ramdisk_read
353 IN EFI_BLOCK_IO_PROTOCOL
*This
,
360 //debug("### ventoy_block_io_ramdisk_read sector:%u count:%u", (UINT32)Lba, (UINT32)BufferSize / 2048);
365 CopyMem(Buffer
, g_iso_data_buf
+ (Lba
* 2048), BufferSize
);
367 if (g_blockio_start_record_bcd
&& FALSE
== g_blockio_bcd_read_done
)
369 if (*(UINT32
*)Buffer
== 0x66676572)
371 g_blockio_bcd_read_done
= TRUE
;
378 EFI_LBA EFIAPI
ventoy_fixup_iso9660_sector(IN EFI_LBA Lba
, UINT32 secNum
)
382 if (g_fixup_iso9660_secover_cur_secs
> 0)
384 Lba
+= VENTOY_ISO9660_SECTOR_OVERFLOW
;
385 g_fixup_iso9660_secover_cur_secs
+= secNum
;
386 if (g_fixup_iso9660_secover_cur_secs
>= g_fixup_iso9660_secover_tot_secs
)
388 g_fixup_iso9660_secover_start
= FALSE
;
394 ventoy_iso9660_override
*dirent
;
395 ventoy_override_chunk
*pOverride
;
397 for (i
= 0, pOverride
= g_override_chunk
; i
< g_override_chunk_num
; i
++, pOverride
++)
399 dirent
= (ventoy_iso9660_override
*)pOverride
->override_data
;
400 if (Lba
== dirent
->first_sector
)
402 g_fixup_iso9660_secover_start
= FALSE
;
407 if (g_fixup_iso9660_secover_start
)
409 for (i
= 0, pOverride
= g_override_chunk
; i
< g_override_chunk_num
; i
++, pOverride
++)
411 dirent
= (ventoy_iso9660_override
*)pOverride
->override_data
;
412 if (Lba
+ VENTOY_ISO9660_SECTOR_OVERFLOW
== dirent
->first_sector
)
414 g_fixup_iso9660_secover_tot_secs
= (dirent
->size
+ 2047) / 2048;
415 g_fixup_iso9660_secover_cur_secs
= secNum
;
416 if (g_fixup_iso9660_secover_cur_secs
>= g_fixup_iso9660_secover_tot_secs
)
418 g_fixup_iso9660_secover_start
= FALSE
;
420 Lba
+= VENTOY_ISO9660_SECTOR_OVERFLOW
;
431 EFI_STATUS EFIAPI ventoy_block_io_read_real
433 IN EFI_BLOCK_IO_PROTOCOL
*This
,
450 ventoy_sector_flag
*cur_flag
;
451 ventoy_virt_chunk
*node
;
453 debug("### block_io_read_real sector:%u count:%u Buffer:%p", (UINT32
)Lba
, (UINT32
)BufferSize
/ 2048, Buffer
);
455 secNum
= BufferSize
/ 2048;
457 /* Workaround for SSTR PE loader error */
458 if (g_fixup_iso9660_secover_start
)
460 Lba
= ventoy_fixup_iso9660_sector(Lba
, secNum
);
465 if (offset
+ BufferSize
<= g_chain
->real_img_size_in_bytes
)
467 return ventoy_read_iso_sector(Lba
, secNum
, Buffer
);
469 else if (offset
< g_chain
->real_img_size_in_bytes
)
471 TmpNum
= (g_chain
->real_img_size_in_bytes
- offset
) / 2048;
472 ventoy_read_iso_sector(Lba
, TmpNum
, Buffer
);
476 Buffer
= (UINT8
*)Buffer
+ (g_chain
->real_img_size_in_bytes
- offset
);
480 VirtSec
= g_chain
->virt_img_size_in_bytes
/ 2048;
485 else if (Lba
+ secNum
> VirtSec
)
487 secNum
= VirtSec
- Lba
;
490 debug("XXX block_io_read_real sector:%u count:%u Buffer:%p", (UINT32
)Lba
, (UINT32
)BufferSize
/ 2048, Buffer
);
492 if (secNum
> g_sector_flag_num
)
494 cur_flag
= AllocatePool(secNum
* sizeof(ventoy_sector_flag
));
495 if (NULL
== cur_flag
)
497 return EFI_OUT_OF_RESOURCES
;
500 FreePool(g_sector_flag
);
501 g_sector_flag
= cur_flag
;
502 g_sector_flag_num
= secNum
;
505 for (curlba
= Lba
, cur_flag
= g_sector_flag
, j
= 0; j
< secNum
; j
++, curlba
++, cur_flag
++)
508 for (node
= g_virt_chunk
, i
= 0; i
< g_virt_chunk_num
; i
++, node
++)
510 if (curlba
>= node
->mem_sector_start
&& curlba
< node
->mem_sector_end
)
512 CopyMem((UINT8
*)Buffer
+ j
* 2048,
513 (char *)g_virt_chunk
+ node
->mem_sector_offset
+ (curlba
- node
->mem_sector_start
) * 2048,
518 else if (curlba
>= node
->remap_sector_start
&& curlba
< node
->remap_sector_end
)
520 cur_flag
->remap_lba
= node
->org_sector_start
+ curlba
- node
->remap_sector_start
;
527 for (curlba
= Lba
, cur_flag
= g_sector_flag
, j
= 0; j
< secNum
; j
++, curlba
++, cur_flag
++)
529 if (cur_flag
->flag
== 2)
533 lastbuffer
= (UINT8
*)Buffer
+ j
* 2048;
534 lastlba
= cur_flag
->remap_lba
;
537 else if (lastlba
+ lbacount
== cur_flag
->remap_lba
)
543 ventoy_read_iso_sector(lastlba
, lbacount
, lastbuffer
);
544 lastbuffer
= (UINT8
*)Buffer
+ j
* 2048;
545 lastlba
= cur_flag
->remap_lba
;
553 ventoy_read_iso_sector(lastlba
, lbacount
, lastbuffer
);
559 EFI_STATUS EFIAPI ventoy_block_io_read
561 IN EFI_BLOCK_IO_PROTOCOL
*This
,
570 EFI_STATUS Status
= EFI_OUT_OF_RESOURCES
;
572 if (gBlockData
.pRawBlockIo
&& gBlockData
.pRawBlockIo
->Media
)
574 IoAlign
= gBlockData
.pRawBlockIo
->Media
->IoAlign
;
577 if ((IoAlign
== 0) || (((UINTN
) Buffer
& (IoAlign
- 1)) == 0))
579 Status
= ventoy_block_io_read_real(This
, MediaId
, Lba
, BufferSize
, Buffer
);
583 NewBuf
= AllocatePages(EFI_SIZE_TO_PAGES(BufferSize
+ IoAlign
));
586 Status
= ventoy_block_io_read_real(This
, MediaId
, Lba
, BufferSize
, NewBuf
);
587 CopyMem(Buffer
, NewBuf
, BufferSize
);
588 FreePages(NewBuf
, EFI_SIZE_TO_PAGES(BufferSize
+ IoAlign
));
595 EFI_STATUS EFIAPI ventoy_block_io_write
597 IN EFI_BLOCK_IO_PROTOCOL
*This
,
612 return EFI_WRITE_PROTECTED
;
615 secNum
= BufferSize
/ 2048;
618 return ventoy_write_iso_sector(Lba
, secNum
, Buffer
);
621 EFI_STATUS EFIAPI
ventoy_block_io_flush(IN EFI_BLOCK_IO_PROTOCOL
*This
)
628 EFI_STATUS EFIAPI
ventoy_fill_device_path(VOID
)
631 UINT8 TmpBuf
[128] = {0};
632 VENDOR_DEVICE_PATH
*venPath
= NULL
;
634 venPath
= (VENDOR_DEVICE_PATH
*)TmpBuf
;
635 NameLen
= StrSize(VTOY_BLOCK_DEVICE_PATH_NAME
);
636 venPath
->Header
.Type
= HARDWARE_DEVICE_PATH
;
637 venPath
->Header
.SubType
= HW_VENDOR_DP
;
638 venPath
->Header
.Length
[0] = sizeof(VENDOR_DEVICE_PATH
) + NameLen
;
639 venPath
->Header
.Length
[1] = 0;
640 CopyMem(&venPath
->Guid
, &gVtoyBlockDevicePathGuid
, sizeof(EFI_GUID
));
641 CopyMem(venPath
+ 1, VTOY_BLOCK_DEVICE_PATH_NAME
, NameLen
);
643 gBlockData
.Path
= AppendDevicePathNode(NULL
, (EFI_DEVICE_PATH_PROTOCOL
*)TmpBuf
);
644 gBlockData
.DevicePathCompareLen
= sizeof(VENDOR_DEVICE_PATH
) + NameLen
;
646 debug("gBlockData.Path=<%s>\n", ConvertDevicePathToText(gBlockData
.Path
, FALSE
, FALSE
));
651 EFI_STATUS EFIAPI
ventoy_connect_driver(IN EFI_HANDLE ControllerHandle
, IN CONST CHAR16
*DrvName
)
655 CHAR16
*DriverName
= NULL
;
656 EFI_HANDLE
*Handles
= NULL
;
657 EFI_HANDLE DrvHandles
[2] = { NULL
};
658 EFI_STATUS Status
= EFI_SUCCESS
;
659 EFI_COMPONENT_NAME_PROTOCOL
*NameProtocol
= NULL
;
660 EFI_COMPONENT_NAME2_PROTOCOL
*Name2Protocol
= NULL
;
662 debug("ventoy_connect_driver <%s>...", DrvName
);
664 Status
= gBS
->LocateHandleBuffer(ByProtocol
, &gEfiComponentName2ProtocolGuid
,
665 NULL
, &Count
, &Handles
);
666 if (EFI_ERROR(Status
))
671 for (i
= 0; i
< Count
; i
++)
673 Status
= gBS
->HandleProtocol(Handles
[i
], &gEfiComponentName2ProtocolGuid
, (VOID
**)&Name2Protocol
);
674 if (EFI_ERROR(Status
))
679 VENTOY_GET_COMPONENT_NAME(Name2Protocol
, DriverName
);
681 if (StrStr(DriverName
, DrvName
))
683 debug("Find driver name2:<%s>: <%s>", DriverName
, DrvName
);
684 DrvHandles
[0] = Handles
[i
];
691 Status
= gBS
->ConnectController(ControllerHandle
, DrvHandles
, NULL
, TRUE
);
692 debug("ventoy_connect_driver:<%s> <%r>", DrvName
, Status
);
696 debug("%s NOT found, now try COMPONENT_NAME", DrvName
);
702 Status
= gBS
->LocateHandleBuffer(ByProtocol
, &gEfiComponentNameProtocolGuid
,
703 NULL
, &Count
, &Handles
);
704 if (EFI_ERROR(Status
))
709 for (i
= 0; i
< Count
; i
++)
711 Status
= gBS
->HandleProtocol(Handles
[i
], &gEfiComponentNameProtocolGuid
, (VOID
**)&NameProtocol
);
712 if (EFI_ERROR(Status
))
717 VENTOY_GET_COMPONENT_NAME(NameProtocol
, DriverName
);
719 if (StrStr(DriverName
, DrvName
))
721 debug("Find driver name:<%s>: <%s>", DriverName
, DrvName
);
722 DrvHandles
[0] = Handles
[i
];
729 Status
= gBS
->ConnectController(ControllerHandle
, DrvHandles
, NULL
, TRUE
);
730 debug("ventoy_connect_driver:<%s> <%r>", DrvName
, Status
);
734 Status
= EFI_NOT_FOUND
;
743 STATIC BOOLEAN
ventoy_filesystem_need_wrapper(IN CONST CHAR16
*DrvName
)
746 CHAR16 UpperDrvName
[256];
748 StrCpyS(UpperDrvName
, 256, DrvName
);
750 for (i
= 0; i
< 256 && UpperDrvName
[i
]; i
++)
752 if (UpperDrvName
[i
] >= 'a' && UpperDrvName
[i
] <= 'z')
754 UpperDrvName
[i
] = 'A' + (UpperDrvName
[i
] - 'a');
759 * suppress some file system drivers
760 * 1. rEFInd File System Driver
764 if (StrStr(UpperDrvName
, L
"ISO9660") || StrStr(UpperDrvName
, L
"UDF"))
769 if (StrStr(UpperDrvName
, L
"REFIND") && StrStr(UpperDrvName
, L
"FILE SYSTEM"))
777 STATIC VOID ventoy_add_filesystem_wrapper
779 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBindProtocol
,
780 IN CONST CHAR16
*DriverName
785 if (g_DriverBindWrapperCnt
>= MAX_DRIVER_BIND_WRAPPER
)
787 debug("driver binding wrapper overflow %lu", g_DriverBindWrapperCnt
);
791 if (!ventoy_filesystem_need_wrapper(DriverName
))
796 for (j
= 0; j
< g_DriverBindWrapperCnt
; j
++)
798 if (g_DriverBindWrapperList
[j
].DriverBinding
== DriverBindProtocol
)
800 debug("Duplicate driverbinding <%s> %p %lu %lu", DriverName
, DriverBindProtocol
, j
, g_DriverBindWrapperCnt
);
805 if (j
>= g_DriverBindWrapperCnt
)
807 g_DriverBindWrapperList
[g_DriverBindWrapperCnt
].DriverBinding
= DriverBindProtocol
;
808 g_DriverBindWrapperList
[g_DriverBindWrapperCnt
].pfOldSupport
= DriverBindProtocol
->Supported
;
809 g_DriverBindWrapperCnt
++;
810 debug("Add driverbinding <%s> %p %lu", DriverName
, DriverBindProtocol
, g_DriverBindWrapperCnt
);
814 STATIC EFI_STATUS
ventoy_find_filesystem_driverbind(VOID
)
818 CHAR16
*DriverName
= NULL
;
819 EFI_HANDLE
*Handles
= NULL
;
820 EFI_STATUS Status
= EFI_SUCCESS
;
821 EFI_COMPONENT_NAME_PROTOCOL
*NameProtocol
= NULL
;
822 EFI_COMPONENT_NAME2_PROTOCOL
*Name2Protocol
= NULL
;
823 EFI_DRIVER_BINDING_PROTOCOL
*DriverBindProtocol
= NULL
;
825 debug("ventoy_find_filesystem_driverbind...");
827 Status
= gBS
->LocateHandleBuffer(ByProtocol
, &gEfiComponentName2ProtocolGuid
,
828 NULL
, &Count
, &Handles
);
829 if (EFI_ERROR(Status
))
834 for (i
= 0; i
< Count
; i
++)
836 Status
= gBS
->HandleProtocol(Handles
[i
], &gEfiComponentName2ProtocolGuid
, (VOID
**)&Name2Protocol
);
837 if (EFI_ERROR(Status
))
842 VENTOY_GET_COMPONENT_NAME(Name2Protocol
, DriverName
);
844 Status
= gBS
->HandleProtocol(Handles
[i
], &gEfiDriverBindingProtocolGuid
, (VOID
**)&DriverBindProtocol
);
845 if (EFI_ERROR(Status
))
847 debug("### 2 No DriverBind <%s> <%r>", DriverName
, Status
);
851 ventoy_add_filesystem_wrapper(DriverBindProtocol
, DriverName
);
858 Status
= gBS
->LocateHandleBuffer(ByProtocol
, &gEfiComponentNameProtocolGuid
,
859 NULL
, &Count
, &Handles
);
860 if (EFI_ERROR(Status
))
865 for (i
= 0; i
< Count
; i
++)
867 Status
= gBS
->HandleProtocol(Handles
[i
], &gEfiComponentNameProtocolGuid
, (VOID
**)&NameProtocol
);
868 if (EFI_ERROR(Status
))
874 VENTOY_GET_COMPONENT_NAME(NameProtocol
, DriverName
);
876 Status
= gBS
->HandleProtocol(Handles
[i
], &gEfiDriverBindingProtocolGuid
, (VOID
**)&DriverBindProtocol
);
877 if (EFI_ERROR(Status
))
879 debug("### 1 No DriverBind <%s> <%r>", DriverName
, Status
);
883 ventoy_add_filesystem_wrapper(DriverBindProtocol
, DriverName
);
891 STATIC EFI_STATUS EFIAPI ventoy_wrapper_driver_bind_support
893 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
894 IN EFI_HANDLE ControllerHandle
,
895 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
899 EFI_STATUS Status
= EFI_SUCCESS
;
900 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
= NULL
;
901 EFI_DRIVER_BINDING_SUPPORTED pfOldSupport
= NULL
;
903 for (i
= 0; i
< g_DriverBindWrapperCnt
; i
++)
905 if (g_DriverBindWrapperList
[i
].DriverBinding
== This
)
907 pfOldSupport
= g_DriverBindWrapperList
[i
].pfOldSupport
;
912 debug("ventoy_wrapper_driver_bind_support %lu %p", i
, pfOldSupport
);
916 return EFI_UNSUPPORTED
;
919 Status
= gBS
->HandleProtocol(ControllerHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&DevicePath
);
920 if (EFI_ERROR(Status
))
925 if (0 == CompareMem(gBlockData
.Path
, DevicePath
, gBlockData
.DevicePathCompareLen
))
927 debug("return EFI_UNSUPPORTED for ventoy");
928 return EFI_UNSUPPORTED
;
932 return pfOldSupport(This
, ControllerHandle
, RemainingDevicePath
);
935 EFI_STATUS
ventoy_disable_ex_filesystem(VOID
)
939 ventoy_find_filesystem_driverbind();
941 for (i
= 0; i
< g_DriverBindWrapperCnt
; i
++)
943 g_DriverBindWrapperList
[i
].DriverBinding
->Supported
= ventoy_wrapper_driver_bind_support
;
946 debug("Wrapper Ex Driver Binding %lu", g_DriverBindWrapperCnt
);
947 ventoy_debug_pause();
952 EFI_STATUS
ventoy_enable_ex_filesystem(VOID
)
956 for (i
= 0; i
< g_DriverBindWrapperCnt
; i
++)
958 g_DriverBindWrapperList
[i
].DriverBinding
->Supported
= g_DriverBindWrapperList
[i
].pfOldSupport
;
960 g_DriverBindWrapperCnt
= 0;
965 EFI_STATUS EFIAPI ventoy_block_io_read_512
967 IN EFI_BLOCK_IO_PROTOCOL
*This
,
976 UINT8
*CurBuf
= NULL
;
977 EFI_STATUS Status
= EFI_SUCCESS
;
979 debug("ventoy_block_io_read_512 %lu %lu Buffer:%p\n", Lba
, BufferSize
/ 512, Buffer
);
981 CurBuf
= (UINT8
*)Buffer
;
986 Status
|= g_sector_2048_read(This
, MediaId
, Lba
/ 4, 2048, g_sector_buf
);
988 if (BufferSize
<= (4 - Mod
) * 512)
990 CopyMem(CurBuf
, g_sector_buf
+ Mod
* 512, BufferSize
);
995 ReadSize
= (4 - Mod
) * 512;
996 CopyMem(CurBuf
, g_sector_buf
+ Mod
* 512, ReadSize
);
999 BufferSize
-= ReadSize
;
1003 if (BufferSize
>= 2048)
1005 ReadSize
= BufferSize
/ 2048 * 2048;
1007 Status
|= g_sector_2048_read(This
, MediaId
, Lba
/ 4, ReadSize
, CurBuf
);
1010 Lba
+= ReadSize
/ 512;
1011 BufferSize
-= ReadSize
;
1016 Status
|= g_sector_2048_read(This
, MediaId
, Lba
/ 4, 2048, g_sector_buf
);
1017 CopyMem(CurBuf
, g_sector_buf
, BufferSize
);
1023 EFI_STATUS EFIAPI ventoy_block_io_write_512
1025 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1028 IN UINTN BufferSize
,
1034 UINT8
*CurBuf
= NULL
;
1035 EFI_STATUS Status
= EFI_SUCCESS
;
1037 debug("ventoy_block_io_write_512 %lu %lu\n", Lba
, BufferSize
/ 512);
1039 CurBuf
= (UINT8
*)Buffer
;
1044 Status
|= g_sector_2048_read(This
, MediaId
, Lba
/ 4, 2048, g_sector_buf
);
1046 if (BufferSize
<= (4 - Mod
) * 512)
1048 CopyMem(g_sector_buf
+ Mod
* 512, CurBuf
, BufferSize
);
1049 return g_sector_2048_write(This
, MediaId
, Lba
/ 4, 2048, g_sector_buf
);
1053 ReadSize
= (4 - Mod
) * 512;
1054 CopyMem(g_sector_buf
+ Mod
* 512, CurBuf
, ReadSize
);
1055 g_sector_2048_write(This
, MediaId
, Lba
/ 4, 2048, g_sector_buf
);
1059 BufferSize
-= ReadSize
;
1063 if (BufferSize
>= 2048)
1065 ReadSize
= BufferSize
/ 2048 * 2048;
1067 Status
|= g_sector_2048_write(This
, MediaId
, Lba
/ 4, ReadSize
, CurBuf
);
1070 Lba
+= ReadSize
/ 512;
1071 BufferSize
-= ReadSize
;
1076 Status
|= g_sector_2048_read(This
, MediaId
, Lba
/ 4, 2048, g_sector_buf
);
1078 CopyMem(g_sector_buf
, CurBuf
, BufferSize
);
1079 g_sector_2048_write(This
, MediaId
, Lba
/ 4, 2048, g_sector_buf
);
1085 EFI_STATUS EFIAPI
ventoy_install_blockio(IN EFI_HANDLE ImageHandle
, IN UINT64 ImgSize
)
1087 EFI_STATUS Status
= EFI_SUCCESS
;
1088 EFI_BLOCK_IO_PROTOCOL
*pBlockIo
= &(gBlockData
.BlockIo
);
1090 ventoy_fill_device_path();
1092 debug("install block io protocol %p", ImageHandle
);
1093 ventoy_debug_pause();
1097 gBlockData
.Media
.BlockSize
= 512;
1098 gBlockData
.Media
.LastBlock
= ImgSize
/ 512 - 1;
1102 gBlockData
.Media
.BlockSize
= 2048;
1103 gBlockData
.Media
.LastBlock
= ImgSize
/ 2048 - 1;
1106 gBlockData
.Media
.ReadOnly
= TRUE
;
1107 gBlockData
.Media
.MediaPresent
= 1;
1108 gBlockData
.Media
.LogicalBlocksPerPhysicalBlock
= 1;
1110 pBlockIo
->Revision
= EFI_BLOCK_IO_PROTOCOL_REVISION3
;
1111 pBlockIo
->Media
= &(gBlockData
.Media
);
1112 pBlockIo
->Reset
= ventoy_block_io_reset
;
1116 g_sector_2048_read
= gMemdiskMode
? ventoy_block_io_ramdisk_read
: ventoy_block_io_read
;
1117 g_sector_2048_write
= gMemdiskMode
? ventoy_block_io_ramdisk_write
: ventoy_block_io_write
;
1118 pBlockIo
->ReadBlocks
= ventoy_block_io_read_512
;
1119 pBlockIo
->WriteBlocks
= ventoy_block_io_write_512
;
1123 pBlockIo
->ReadBlocks
= gMemdiskMode
? ventoy_block_io_ramdisk_read
: ventoy_block_io_read
;
1124 pBlockIo
->WriteBlocks
= ventoy_block_io_write
;
1127 pBlockIo
->FlushBlocks
= ventoy_block_io_flush
;
1129 Status
= gBS
->InstallMultipleProtocolInterfaces(&gBlockData
.Handle
,
1130 &gEfiBlockIoProtocolGuid
, &gBlockData
.BlockIo
,
1131 &gEfiDevicePathProtocolGuid
, gBlockData
.Path
,
1133 debug("Install protocol %r %p", Status
, gBlockData
.Handle
);
1134 if (EFI_ERROR(Status
))
1139 Status
= ventoy_connect_driver(gBlockData
.Handle
, L
"Disk I/O Driver");
1140 debug("Connect disk IO driver %r", Status
);
1142 Status
= ventoy_connect_driver(gBlockData
.Handle
, L
"Partition Driver");
1143 debug("Connect partition driver %r", Status
);
1144 if (EFI_ERROR(Status
))
1146 Status
= gBS
->ConnectController(gBlockData
.Handle
, NULL
, NULL
, TRUE
);
1147 debug("Connect all controller %r", Status
);
1150 ventoy_debug_pause();
1156 /* For file replace */
1159 STATIC EFI_STATUS EFIAPI
1160 ventoy_wrapper_fs_open(EFI_FILE_HANDLE This
, EFI_FILE_HANDLE
*New
, CHAR16
*Name
, UINT64 Mode
, UINT64 Attributes
)
1170 STATIC EFI_STATUS EFIAPI
1171 ventoy_wrapper_file_open_ex(EFI_FILE_HANDLE This
, EFI_FILE_HANDLE
*New
, CHAR16
*Name
, UINT64 Mode
, UINT64 Attributes
, EFI_FILE_IO_TOKEN
*Token
)
1173 return ventoy_wrapper_fs_open(This
, New
, Name
, Mode
, Attributes
);
1176 STATIC EFI_STATUS EFIAPI
1177 ventoy_wrapper_file_delete(EFI_FILE_HANDLE This
)
1183 STATIC EFI_STATUS EFIAPI
1184 ventoy_wrapper_file_set_info(EFI_FILE_HANDLE This
, EFI_GUID
*Type
, UINTN Len
, VOID
*Data
)
1189 STATIC EFI_STATUS EFIAPI
1190 ventoy_wrapper_file_flush(EFI_FILE_HANDLE This
)
1197 STATIC EFI_STATUS EFIAPI
1198 ventoy_wrapper_file_flush_ex(EFI_FILE_HANDLE This
, EFI_FILE_IO_TOKEN
*Token
)
1206 STATIC EFI_STATUS EFIAPI
1207 ventoy_wrapper_file_write(EFI_FILE_HANDLE This
, UINTN
*Len
, VOID
*Data
)
1213 return EFI_WRITE_PROTECTED
;
1216 STATIC EFI_STATUS EFIAPI
1217 ventoy_wrapper_file_write_ex(IN EFI_FILE_PROTOCOL
*This
, IN OUT EFI_FILE_IO_TOKEN
*Token
)
1219 return ventoy_wrapper_file_write(This
, &(Token
->BufferSize
), Token
->Buffer
);
1223 STATIC EFI_STATUS EFIAPI
1224 ventoy_wrapper_file_close(EFI_FILE_HANDLE This
)
1231 STATIC EFI_STATUS EFIAPI
1232 ventoy_wrapper_file_set_pos(EFI_FILE_HANDLE This
, UINT64 Position
)
1236 if (Position
<= g_efi_file_replace
.FileSizeBytes
)
1238 g_efi_file_replace
.CurPos
= Position
;
1242 g_efi_file_replace
.CurPos
= g_efi_file_replace
.FileSizeBytes
;
1248 STATIC EFI_STATUS EFIAPI
1249 ventoy_wrapper_file_get_pos(EFI_FILE_HANDLE This
, UINT64
*Position
)
1253 *Position
= g_efi_file_replace
.CurPos
;
1259 STATIC EFI_STATUS EFIAPI
1260 ventoy_wrapper_file_get_info(EFI_FILE_HANDLE This
, EFI_GUID
*Type
, UINTN
*Len
, VOID
*Data
)
1262 EFI_FILE_INFO
*Info
= (EFI_FILE_INFO
*) Data
;
1264 debug("ventoy_wrapper_file_get_info ... %u", *Len
);
1266 if (!CompareGuid(Type
, &gEfiFileInfoGuid
))
1268 return EFI_INVALID_PARAMETER
;
1274 return EFI_BUFFER_TOO_SMALL
;
1277 ZeroMem(Data
, sizeof(EFI_FILE_INFO
));
1279 Info
->Size
= sizeof(EFI_FILE_INFO
);
1280 Info
->FileSize
= g_efi_file_replace
.FileSizeBytes
;
1281 Info
->PhysicalSize
= g_efi_file_replace
.FileSizeBytes
;
1282 Info
->Attribute
= EFI_FILE_READ_ONLY
;
1283 //Info->FileName = EFI_FILE_READ_ONLY;
1290 STATIC EFI_STATUS EFIAPI
1291 ventoy_wrapper_file_read(EFI_FILE_HANDLE This
, UINTN
*Len
, VOID
*Data
)
1294 UINTN ReadLen
= *Len
;
1298 debug("ventoy_wrapper_file_read ... %u", *Len
);
1300 if (g_efi_file_replace
.CurPos
+ ReadLen
> g_efi_file_replace
.FileSizeBytes
)
1302 ReadLen
= g_efi_file_replace
.FileSizeBytes
- g_efi_file_replace
.CurPos
;
1305 Lba
= g_efi_file_replace
.CurPos
/ 2048 + g_efi_file_replace
.BlockIoSectorStart
;
1307 ventoy_block_io_read(NULL
, 0, Lba
, ReadLen
, Data
);
1311 g_efi_file_replace
.CurPos
+= ReadLen
;
1316 STATIC EFI_STATUS EFIAPI
1317 ventoy_wrapper_file_read_ex(IN EFI_FILE_PROTOCOL
*This
, IN OUT EFI_FILE_IO_TOKEN
*Token
)
1319 return ventoy_wrapper_file_read(This
, &(Token
->BufferSize
), Token
->Buffer
);
1322 STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL
*File
)
1324 File
->Revision
= EFI_FILE_PROTOCOL_REVISION2
;
1325 File
->Open
= ventoy_wrapper_fs_open
;
1326 File
->Close
= ventoy_wrapper_file_close
;
1327 File
->Delete
= ventoy_wrapper_file_delete
;
1328 File
->Read
= ventoy_wrapper_file_read
;
1329 File
->Write
= ventoy_wrapper_file_write
;
1330 File
->GetPosition
= ventoy_wrapper_file_get_pos
;
1331 File
->SetPosition
= ventoy_wrapper_file_set_pos
;
1332 File
->GetInfo
= ventoy_wrapper_file_get_info
;
1333 File
->SetInfo
= ventoy_wrapper_file_set_info
;
1334 File
->Flush
= ventoy_wrapper_file_flush
;
1335 File
->OpenEx
= ventoy_wrapper_file_open_ex
;
1336 File
->ReadEx
= ventoy_wrapper_file_read_ex
;
1337 File
->WriteEx
= ventoy_wrapper_file_write_ex
;
1338 File
->FlushEx
= ventoy_wrapper_file_flush_ex
;
1343 STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
1345 EFI_FILE_HANDLE This
,
1346 EFI_FILE_HANDLE
*New
,
1355 EFI_STATUS Status
= EFI_SUCCESS
;
1357 ventoy_virt_chunk
*virt
= NULL
;
1359 debug("## ventoy_wrapper_file_open <%s> ", Name
);
1361 Status
= g_original_fopen(This
, New
, Name
, Mode
, Attributes
);
1362 if (EFI_ERROR(Status
))
1367 if (g_file_replace_list
&& g_file_replace_list
->magic
== GRUB_FILE_REPLACE_MAGIC
&&
1368 g_file_replace_list
->new_file_virtual_id
< g_virt_chunk_num
)
1370 AsciiSPrint(TmpName
, sizeof(TmpName
), "%s", Name
);
1371 for (j
= 0; j
< 4; j
++)
1373 if (0 == AsciiStrCmp(g_file_replace_list
[i
].old_file_name
[j
], TmpName
))
1375 g_original_fclose(*New
);
1376 *New
= &g_efi_file_replace
.WrapperHandle
;
1377 ventoy_wrapper_file_procotol(*New
);
1379 virt
= g_virt_chunk
+ g_file_replace_list
->new_file_virtual_id
;
1381 Sectors
= (virt
->mem_sector_end
- virt
->mem_sector_start
) + (virt
->remap_sector_end
- virt
->remap_sector_start
);
1383 g_efi_file_replace
.BlockIoSectorStart
= virt
->mem_sector_start
;
1384 g_efi_file_replace
.FileSizeBytes
= Sectors
* 2048;
1388 debug("## ventoy_wrapper_file_open <%s> BlockStart:%lu Sectors:%lu Bytes:%lu", Name
,
1389 g_efi_file_replace
.BlockIoSectorStart
, Sectors
, Sectors
* 2048);
1397 if (StrCmp(Name
, L
"\\EFI\\BOOT") == 0)
1399 (*New
)->Open
= ventoy_wrapper_file_open
;
1406 EFI_STATUS EFIAPI ventoy_wrapper_open_volume
1408 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*This
,
1409 OUT EFI_FILE_PROTOCOL
**Root
1412 EFI_STATUS Status
= EFI_SUCCESS
;
1414 Status
= g_original_open_volume(This
, Root
);
1415 if (!EFI_ERROR(Status
))
1417 g_original_fopen
= (*Root
)->Open
;
1418 g_original_fclose
= (*Root
)->Close
;
1419 (*Root
)->Open
= ventoy_wrapper_file_open
;
1425 EFI_STATUS EFIAPI
ventoy_wrapper_push_openvolume(IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME OpenVolume
)
1427 g_original_open_volume
= OpenVolume
;
1432 /* For auto skip Windows 'Press any key to boot from CD or DVD ...' */
1435 STATIC EFI_STATUS EFIAPI ventoy_wrapper_read_key_ex
1437 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
1438 OUT EFI_KEY_DATA
*KeyData
1441 /* only hook once before BCD file read */
1442 if (g_keyboard_hook_count
== 0 && g_blockio_bcd_read_done
== FALSE
)
1444 g_keyboard_hook_count
++;
1446 KeyData
->Key
.ScanCode
= SCAN_DELETE
;
1447 KeyData
->Key
.UnicodeChar
= 0;
1448 KeyData
->KeyState
.KeyShiftState
= 0;
1449 KeyData
->KeyState
.KeyToggleState
= 0;
1454 return g_org_read_key_ex(This
, KeyData
);
1457 EFI_STATUS EFIAPI ventoy_wrapper_read_key
1459 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
1460 OUT EFI_INPUT_KEY
*Key
1463 /* only hook once before BCD file read */
1464 if (g_keyboard_hook_count
== 0 && g_blockio_bcd_read_done
== FALSE
)
1466 g_keyboard_hook_count
++;
1468 Key
->ScanCode
= SCAN_DELETE
;
1469 Key
->UnicodeChar
= 0;
1473 return g_org_read_key(This
, Key
);
1476 EFI_STATUS
ventoy_hook_keyboard_start(VOID
)
1478 g_blockio_start_record_bcd
= TRUE
;
1479 g_blockio_bcd_read_done
= FALSE
;
1480 g_keyboard_hook_count
= 0;
1482 if (g_con_simple_input_ex
)
1484 g_org_read_key_ex
= g_con_simple_input_ex
->ReadKeyStrokeEx
;
1485 g_con_simple_input_ex
->ReadKeyStrokeEx
= ventoy_wrapper_read_key_ex
;
1488 g_org_read_key
= gST
->ConIn
->ReadKeyStroke
;
1489 gST
->ConIn
->ReadKeyStroke
= ventoy_wrapper_read_key
;
1494 EFI_STATUS
ventoy_hook_keyboard_stop(VOID
)
1496 g_blockio_start_record_bcd
= FALSE
;
1497 g_blockio_bcd_read_done
= FALSE
;
1498 g_keyboard_hook_count
= 0;
1500 if (g_con_simple_input_ex
)
1502 g_con_simple_input_ex
->ReadKeyStrokeEx
= g_org_read_key_ex
;
1505 gST
->ConIn
->ReadKeyStroke
= g_org_read_key
;
1511 /* Fixup the 1st cdrom influnce for Windows boot */
1514 STATIC EFI_STATUS EFIAPI ventoy_wrapper_locate_handle
1516 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
1517 IN EFI_GUID
*Protocol
, OPTIONAL
1518 IN VOID
*SearchKey
, OPTIONAL
1519 IN OUT UINTN
*BufferSize
,
1520 OUT EFI_HANDLE
*Buffer
1524 EFI_HANDLE Handle
= NULL
;
1525 EFI_STATUS Status
= EFI_SUCCESS
;
1527 Status
= g_org_locate_handle(SearchType
, Protocol
, SearchKey
, BufferSize
, Buffer
);
1529 if (EFI_SUCCESS
== Status
&& Protocol
&& CompareGuid(&gEfiBlockIoProtocolGuid
, Protocol
))
1531 for (i
= 0; i
< (*BufferSize
) / sizeof(EFI_HANDLE
); i
++)
1533 if (Buffer
[i
] == gBlockData
.Handle
)
1536 Buffer
[0] = Buffer
[i
];
1546 EFI_STATUS
ventoy_hook_1st_cdrom_start(VOID
)
1548 g_org_locate_handle
= gBS
->LocateHandle
;
1549 gBS
->LocateHandle
= ventoy_wrapper_locate_handle
;
1554 EFI_STATUS
ventoy_hook_1st_cdrom_stop(VOID
)
1556 gBS
->LocateHandle
= g_org_locate_handle
;
1557 g_org_locate_handle
= NULL
;