1 /******************************************************************************
4 * Copyright (c) 2021, 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/>.
24 #define VDISK_MAGIC_LEN 32
26 #define VDISK_BLOCK_DEVICE_PATH_GUID \
27 { 0x6ed2134e, 0xc2ea, 0x4943, { 0x99, 0x54, 0xa7, 0x76, 0xe5, 0x9c, 0x12, 0xc3 }}
29 #define VDISK_BLOCK_DEVICE_PATH_NAME L"vdisk"
31 #if defined (MDE_CPU_IA32)
32 #define VENTOY_UEFI_DESC L"IA32 UEFI"
33 #elif defined (MDE_CPU_X64)
34 #define VENTOY_UEFI_DESC L"X64 UEFI"
35 #elif defined (MDE_CPU_EBC)
36 #elif defined (MDE_CPU_ARM)
37 #define VENTOY_UEFI_DESC L"ARM UEFI"
38 #elif defined (MDE_CPU_AARCH64)
39 #define VENTOY_UEFI_DESC L"ARM64 UEFI"
41 #error Unknown Processor Type
44 typedef struct vdisk_block_data
47 EFI_BLOCK_IO_MEDIA Media
; /* Media descriptor */
48 EFI_BLOCK_IO_PROTOCOL BlockIo
; /* Block I/O protocol */
50 UINTN DevicePathCompareLen
;
51 EFI_DEVICE_PATH_PROTOCOL
*Path
; /* Device path protocol */
53 EFI_HANDLE RawBlockIoHandle
;
54 EFI_BLOCK_IO_PROTOCOL
*pRawBlockIo
;
55 EFI_DEVICE_PATH_PROTOCOL
*pDiskDevPath
;
57 /* ventoy disk part2 ESP */
58 EFI_HANDLE DiskFsHandle
;
59 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*pDiskFs
;
60 EFI_DEVICE_PATH_PROTOCOL
*pDiskFsDevPath
;
62 EFI_HANDLE IsoDriverImage
;
66 #define debug(expr, ...) if (gVDiskDebugPrint) VDiskDebug("[VDISK] "expr"\r\n", ##__VA_ARGS__)
67 #define trace(expr, ...) VDiskDebug("[VDISK] "expr"\r\n", ##__VA_ARGS__)
68 #define sleep(sec) gBS->Stall(1000000 * (sec))
70 #define vdisk_debug_pause() \
71 if (gVDiskDebugPrint) \
74 gST->ConOut->OutputString(gST->ConOut, L"[VDISK] ###### Press Enter to continue... ######\r\n");\
75 gST->ConIn->Reset(gST->ConIn, FALSE); \
76 gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &__Index);\
79 extern BOOLEAN gVDiskDebugPrint
;
80 VOID EFIAPI
VDiskDebug(IN CONST CHAR8
*Format
, ...);
81 EFI_STATUS EFIAPI vdisk_block_io_read
83 IN EFI_BLOCK_IO_PROTOCOL
*This
,
90 extern UINT8
*g_disk_buf_addr
;
91 extern UINT64 g_disk_buf_size
;
92 extern vdisk_block_data gVDiskBlockData
;
93 EFI_STATUS EFIAPI
vdisk_install_blockio(IN EFI_HANDLE ImageHandle
, IN UINT64 ImgSize
);
94 int vdisk_get_vdisk_raw(UINT8
**buf
, UINT32
*size
);