1.1.11
Some checks failed
Ventoy CI / build (push) Has been cancelled
Mirror GitHub to Gitee / Sync-GitHub-to-Gitee (push) Has been cancelled

. Fix the display issue when UEFI boot Windows/WinPE
. #3537
. #3532
. Add VT_WINDOWS_DISK_NONVTOY_CLOSEST_XXX  VT_LINUX_DISK_NONVTOY_CLOSEST_XXX
This commit is contained in:
longpanda
2026-04-05 23:11:45 +08:00
parent d35b8431fe
commit 167c87402c
12 changed files with 786 additions and 587 deletions

View File

@@ -7,12 +7,12 @@
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the * published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>. * along with this program; if not, see <http://www.gnu.org/licenses/>.
* *
@@ -76,7 +76,7 @@ STATIC EFI_EXIT_BOOT_SERVICES g_org_exit_boot_service = NULL;
/* Boot filename */ /* Boot filename */
UINTN gBootFileStartIndex = 1; UINTN gBootFileStartIndex = 1;
CONST CHAR16 *gEfiBootFileName[] = CONST CHAR16 *gEfiBootFileName[] =
{ {
L"@", L"@",
EFI_REMOVABLE_MEDIA_FILE_NAME, EFI_REMOVABLE_MEDIA_FILE_NAME,
@@ -101,7 +101,7 @@ CONST CHAR16 *gEfiBootFileName[] =
L"\\EFI\\BOOT\\bootaa64.efi", L"\\EFI\\BOOT\\bootaa64.efi",
L"\\efi\\boot\\bootaa64.efi", L"\\efi\\boot\\bootaa64.efi",
#endif #endif
}; };
VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...) VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...)
@@ -112,14 +112,14 @@ VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...)
VA_START (Marker, Format); VA_START (Marker, Format);
UnicodeVSPrintAsciiFormat(Buffer, sizeof(Buffer), Format, Marker); UnicodeVSPrintAsciiFormat(Buffer, sizeof(Buffer), Format, Marker);
VA_END (Marker); VA_END (Marker);
gST->ConOut->OutputString(gST->ConOut, Buffer); gST->ConOut->OutputString(gST->ConOut, Buffer);
} }
VOID EFIAPI ventoy_clear_input(VOID) VOID EFIAPI ventoy_clear_input(VOID)
{ {
EFI_INPUT_KEY Key; EFI_INPUT_KEY Key;
gST->ConIn->Reset(gST->ConIn, FALSE); gST->ConIn->Reset(gST->ConIn, FALSE);
while (EFI_SUCCESS == gST->ConIn->ReadKeyStroke(gST->ConIn, &Key)) while (EFI_SUCCESS == gST->ConIn->ReadKeyStroke(gST->ConIn, &Key))
{ {
@@ -142,7 +142,7 @@ static void EFIAPI ventoy_dump_img_chunk(ventoy_chain_head *chain)
for (i = 0; i < chain->img_chunk_num; i++) for (i = 0; i < chain->img_chunk_num; i++)
{ {
debug("%2u: [ %u - %u ] <==> [ %llu - %llu ]", debug("%2u: [ %u - %u ] <==> [ %llu - %llu ]",
i, chunk[i].img_start_sector, chunk[i].img_end_sector, i, chunk[i].img_start_sector, chunk[i].img_end_sector,
chunk[i].disk_start_sector, chunk[i].disk_end_sector); chunk[i].disk_start_sector, chunk[i].disk_end_sector);
if (i > 0 && (chunk[i].img_start_sector != chunk[i - 1].img_end_sector + 1)) if (i > 0 && (chunk[i].img_start_sector != chunk[i - 1].img_end_sector + 1))
@@ -161,7 +161,7 @@ static void EFIAPI ventoy_dump_img_chunk(ventoy_chain_head *chain)
{ {
debug("image chunk size check failed %d", errcnt); debug("image chunk size check failed %d", errcnt);
} }
ventoy_debug_pause(); ventoy_debug_pause();
} }
@@ -169,7 +169,7 @@ static void EFIAPI ventoy_dump_override_chunk(ventoy_chain_head *chain)
{ {
UINT32 i; UINT32 i;
ventoy_override_chunk *chunk; ventoy_override_chunk *chunk;
chunk = (ventoy_override_chunk *)((char *)chain + chain->override_chunk_offset); chunk = (ventoy_override_chunk *)((char *)chain + chain->override_chunk_offset);
debug("##################### ventoy_dump_override_chunk #######################"); debug("##################### ventoy_dump_override_chunk #######################");
@@ -186,7 +186,7 @@ static void EFIAPI ventoy_dump_virt_chunk(ventoy_chain_head *chain)
{ {
UINT32 i; UINT32 i;
ventoy_virt_chunk *node; ventoy_virt_chunk *node;
debug("##################### ventoy_dump_virt_chunk #######################"); debug("##################### ventoy_dump_virt_chunk #######################");
debug("virt_chunk_offset=%u", chain->virt_chunk_offset); debug("virt_chunk_offset=%u", chain->virt_chunk_offset);
debug("virt_chunk_num=%u", chain->virt_chunk_num); debug("virt_chunk_num=%u", chain->virt_chunk_num);
@@ -194,7 +194,7 @@ static void EFIAPI ventoy_dump_virt_chunk(ventoy_chain_head *chain)
node = (ventoy_virt_chunk *)((char *)chain + chain->virt_chunk_offset); node = (ventoy_virt_chunk *)((char *)chain + chain->virt_chunk_offset);
for (i = 0; i < chain->virt_chunk_num; i++, node++) for (i = 0; i < chain->virt_chunk_num; i++, node++)
{ {
debug("%2u: mem:[ %u, %u, %u ] remap:[ %u, %u, %u ]", i, debug("%2u: mem:[ %u, %u, %u ] remap:[ %u, %u, %u ]", i,
node->mem_sector_start, node->mem_sector_start,
node->mem_sector_end, node->mem_sector_end,
node->mem_sector_offset, node->mem_sector_offset,
@@ -202,7 +202,7 @@ static void EFIAPI ventoy_dump_virt_chunk(ventoy_chain_head *chain)
node->remap_sector_end, node->remap_sector_end,
node->org_sector_start); node->org_sector_start);
} }
ventoy_debug_pause(); ventoy_debug_pause();
} }
@@ -211,7 +211,7 @@ static void EFIAPI ventoy_dump_chain(ventoy_chain_head *chain)
UINT32 i = 0; UINT32 i = 0;
UINT8 chksum = 0; UINT8 chksum = 0;
UINT8 *guid; UINT8 *guid;
guid = chain->os_param.vtoy_disk_guid; guid = chain->os_param.vtoy_disk_guid;
for (i = 0; i < sizeof(ventoy_os_param); i++) for (i = 0; i < sizeof(ventoy_os_param); i++)
{ {
@@ -229,10 +229,10 @@ static void EFIAPI ventoy_dump_chain(ventoy_chain_head *chain)
debug("os_param->vtoy_img_size=<%llu>", chain->os_param.vtoy_img_size); debug("os_param->vtoy_img_size=<%llu>", chain->os_param.vtoy_img_size);
debug("os_param->vtoy_img_location_addr=<0x%llx>", chain->os_param.vtoy_img_location_addr); debug("os_param->vtoy_img_location_addr=<0x%llx>", chain->os_param.vtoy_img_location_addr);
debug("os_param->vtoy_img_location_len=<%u>", chain->os_param.vtoy_img_location_len); debug("os_param->vtoy_img_location_len=<%u>", chain->os_param.vtoy_img_location_len);
debug("os_param->vtoy_reserved=<%u %u %u %u %u %u %u>", debug("os_param->vtoy_reserved=<%u %u %u %u %u %u %u>",
g_os_param_reserved[0], g_os_param_reserved[0],
g_os_param_reserved[1], g_os_param_reserved[1],
g_os_param_reserved[2], g_os_param_reserved[2],
g_os_param_reserved[3], g_os_param_reserved[3],
g_os_param_reserved[4], g_os_param_reserved[4],
g_os_param_reserved[5], g_os_param_reserved[5],
@@ -240,7 +240,7 @@ static void EFIAPI ventoy_dump_chain(ventoy_chain_head *chain)
); );
ventoy_debug_pause(); ventoy_debug_pause();
debug("chain->disk_drive=0x%x", chain->disk_drive); debug("chain->disk_drive=0x%x", chain->disk_drive);
debug("chain->disk_sector_size=%u", chain->disk_sector_size); debug("chain->disk_sector_size=%u", chain->disk_sector_size);
debug("chain->real_img_size_in_bytes=%llu", chain->real_img_size_in_bytes); debug("chain->real_img_size_in_bytes=%llu", chain->real_img_size_in_bytes);
@@ -252,7 +252,7 @@ static void EFIAPI ventoy_dump_chain(ventoy_chain_head *chain)
debug("chain->override_chunk_num=%u", chain->override_chunk_num); debug("chain->override_chunk_num=%u", chain->override_chunk_num);
ventoy_debug_pause(); ventoy_debug_pause();
ventoy_dump_img_chunk(chain); ventoy_dump_img_chunk(chain);
ventoy_dump_override_chunk(chain); ventoy_dump_override_chunk(chain);
ventoy_dump_virt_chunk(chain); ventoy_dump_virt_chunk(chain);
@@ -344,7 +344,7 @@ EFI_HANDLE EFIAPI ventoy_get_parent_handle(IN EFI_DEVICE_PATH_PROTOCOL *pDevPath
EFI_DEVICE_PATH_PROTOCOL *pLastNode = NULL; EFI_DEVICE_PATH_PROTOCOL *pLastNode = NULL;
EFI_DEVICE_PATH_PROTOCOL *pCurNode = NULL; EFI_DEVICE_PATH_PROTOCOL *pCurNode = NULL;
EFI_DEVICE_PATH_PROTOCOL *pTmpDevPath = NULL; EFI_DEVICE_PATH_PROTOCOL *pTmpDevPath = NULL;
pTmpDevPath = DuplicateDevicePath(pDevPath); pTmpDevPath = DuplicateDevicePath(pDevPath);
if (!pTmpDevPath) if (!pTmpDevPath)
{ {
@@ -387,8 +387,8 @@ EFI_STATUS EFIAPI ventoy_save_ramdisk_param(VOID)
{ {
debug("find previous ramdisk variable <%llu>", g_backup_ramdisk_param.DiskSize); debug("find previous ramdisk variable <%llu>", g_backup_ramdisk_param.DiskSize);
} }
Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid, Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(g_ramdisk_param), &(g_ramdisk_param)); sizeof(g_ramdisk_param), &(g_ramdisk_param));
debug("set ramdisk variable %r", Status); debug("set ramdisk variable %r", Status);
@@ -403,14 +403,14 @@ EFI_STATUS EFIAPI ventoy_delete_ramdisk_param(VOID)
if (g_backup_ramdisk_param.DiskSize > 0 && g_backup_ramdisk_param.PhyAddr > 0) if (g_backup_ramdisk_param.DiskSize > 0 && g_backup_ramdisk_param.PhyAddr > 0)
{ {
Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid, Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(g_backup_ramdisk_param), &g_backup_ramdisk_param); sizeof(g_backup_ramdisk_param), &g_backup_ramdisk_param);
debug("resotre ramdisk variable %r", Status); debug("resotre ramdisk variable %r", Status);
} }
else else
{ {
Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid, Status = gRT->SetVariable(L"VentoyRamDisk", &VarGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
0, NULL); 0, NULL);
debug("delete ramdisk variable %r", Status); debug("delete ramdisk variable %r", Status);
@@ -432,7 +432,7 @@ EFI_STATUS EFIAPI ventoy_save_variable(VOID)
debug("find previous efi variable <%a>", g_backup_os_param_var.vtoy_img_path); debug("find previous efi variable <%a>", g_backup_os_param_var.vtoy_img_path);
} }
Status = gRT->SetVariable(L"VentoyOsParam", &VarGuid, Status = gRT->SetVariable(L"VentoyOsParam", &VarGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(g_chain->os_param), &(g_chain->os_param)); sizeof(g_chain->os_param), &(g_chain->os_param));
debug("set efi variable %r", Status); debug("set efi variable %r", Status);
@@ -447,14 +447,14 @@ EFI_STATUS EFIAPI ventoy_delete_variable(VOID)
if (0 == CompareMem(&(g_backup_os_param_var.guid), &VarGuid, sizeof(EFI_GUID))) if (0 == CompareMem(&(g_backup_os_param_var.guid), &VarGuid, sizeof(EFI_GUID)))
{ {
Status = gRT->SetVariable(L"VentoyOsParam", &VarGuid, Status = gRT->SetVariable(L"VentoyOsParam", &VarGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(g_backup_os_param_var), &(g_backup_os_param_var)); sizeof(g_backup_os_param_var), &(g_backup_os_param_var));
debug("restore efi variable %r", Status); debug("restore efi variable %r", Status);
} }
else else
{ {
Status = gRT->SetVariable(L"VentoyOsParam", &VarGuid, Status = gRT->SetVariable(L"VentoyOsParam", &VarGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
0, NULL); 0, NULL);
debug("delete efi variable %r", Status); debug("delete efi variable %r", Status);
@@ -481,7 +481,7 @@ STATIC VOID ventoy_warn_invalid_device(VOID)
gST->ConOut->OutputString(gST->ConOut, L"This is NOT a standard Ventoy device and is NOT supported.\r\n\r\n"); gST->ConOut->OutputString(gST->ConOut, L"This is NOT a standard Ventoy device and is NOT supported.\r\n\r\n");
gST->ConOut->OutputString(gST->ConOut, L"You should follow the official instructions in https://www.ventoy.net\r\n"); gST->ConOut->OutputString(gST->ConOut, L"You should follow the official instructions in https://www.ventoy.net\r\n");
gST->ConOut->OutputString(gST->ConOut, L"\r\n\r\nWill exit after 10 seconds ...... "); gST->ConOut->OutputString(gST->ConOut, L"\r\n\r\nWill exit after 10 seconds ...... ");
sleep(10); sleep(10);
@@ -489,7 +489,7 @@ STATIC VOID ventoy_warn_invalid_device(VOID)
#else #else
STATIC VOID ventoy_warn_invalid_device(VOID) STATIC VOID ventoy_warn_invalid_device(VOID)
{ {
} }
#endif #endif
@@ -513,19 +513,19 @@ STATIC EFI_STATUS EFIAPI ventoy_load_image
pFilePath->Header.Length[0] = FileNameLen + sizeof(EFI_DEVICE_PATH_PROTOCOL); pFilePath->Header.Length[0] = FileNameLen + sizeof(EFI_DEVICE_PATH_PROTOCOL);
pFilePath->Header.Length[1] = 0; pFilePath->Header.Length[1] = 0;
CopyMem(pFilePath->PathName, FileName, FileNameLen); CopyMem(pFilePath->PathName, FileName, FileNameLen);
pImgPath = AppendDevicePathNode(pDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)pFilePath); pImgPath = AppendDevicePathNode(pDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)pFilePath);
if (!pImgPath) if (!pImgPath)
{ {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
Status = gBS->LoadImage(FALSE, ImageHandle, pImgPath, NULL, 0, Image); Status = gBS->LoadImage(FALSE, ImageHandle, pImgPath, NULL, 0, Image);
debug("Load Image File %r DP: <%s>", Status, ConvertDevicePathToText(pImgPath, FALSE, FALSE)); debug("Load Image File %r DP: <%s>", Status, ConvertDevicePathToText(pImgPath, FALSE, FALSE));
FreePool(pImgPath); FreePool(pImgPath);
return Status; return Status;
} }
@@ -547,7 +547,7 @@ STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk(IN EFI_HANDLE ImageHandle)
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiBlockIoProtocolGuid, Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiBlockIoProtocolGuid,
NULL, &Count, &Handles); NULL, &Count, &Handles);
if (EFI_ERROR(Status)) if (EFI_ERROR(Status))
{ {
@@ -591,16 +591,16 @@ STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk(IN EFI_HANDLE ImageHandle)
ventoy_warn_invalid_device(); ventoy_warn_invalid_device();
} }
} }
gBlockData.RawBlockIoHandle = Handles[i]; gBlockData.RawBlockIoHandle = Handles[i];
gBlockData.pRawBlockIo = pBlockIo; gBlockData.pRawBlockIo = pBlockIo;
gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid, gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid,
(VOID **)&(gBlockData.pDiskDevPath), (VOID **)&(gBlockData.pDiskDevPath),
ImageHandle, ImageHandle,
Handles[i], Handles[i],
EFI_OPEN_PROTOCOL_GET_PROTOCOL); EFI_OPEN_PROTOCOL_GET_PROTOCOL);
debug("Find Ventoy Disk Sig Handle:%p DP:%s", Handles[i], debug("Find Ventoy Disk Sig Handle:%p DP:%s", Handles[i],
ConvertDevicePathToText(gBlockData.pDiskDevPath, FALSE, FALSE)); ConvertDevicePathToText(gBlockData.pDiskDevPath, FALSE, FALSE));
break; break;
} }
@@ -629,7 +629,7 @@ STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk_fs(IN EFI_HANDLE ImageHandle)
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *pFile = NULL; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *pFile = NULL;
EFI_DEVICE_PATH_PROTOCOL *pDevPath = NULL; EFI_DEVICE_PATH_PROTOCOL *pDevPath = NULL;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid,
NULL, &Count, &Handles); NULL, &Count, &Handles);
if (EFI_ERROR(Status)) if (EFI_ERROR(Status))
{ {
@@ -646,7 +646,7 @@ STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk_fs(IN EFI_HANDLE ImageHandle)
continue; continue;
} }
Status = gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid, Status = gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid,
(VOID **)&pDevPath, (VOID **)&pDevPath,
ImageHandle, ImageHandle,
Handles[i], Handles[i],
@@ -683,29 +683,29 @@ STATIC EFI_STATUS EFIAPI ventoy_load_isoefi_driver(IN EFI_HANDLE ImageHandle)
if (gIsoUdf) if (gIsoUdf)
{ {
Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath, Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath,
gUdfEfiDriverPath, gUdfEfiDriverPath,
sizeof(gUdfEfiDriverPath), sizeof(gUdfEfiDriverPath),
&Image); &Image);
debug("load iso UDF efi driver status:%r", Status); debug("load iso UDF efi driver status:%r", Status);
} }
else else
{ {
Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath, Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath,
gIso9660EfiDriverPath, gIso9660EfiDriverPath,
sizeof(gIso9660EfiDriverPath), sizeof(gIso9660EfiDriverPath),
&Image); &Image);
debug("load iso 9660 efi driver status:%r", Status); debug("load iso 9660 efi driver status:%r", Status);
} }
if (gDebugPrint) if (gDebugPrint)
{ {
gRT->SetVariable(L"FS_LOGGING", &gShellVariableGuid, gRT->SetVariable(L"FS_LOGGING", &gShellVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(LogVar), LogVar); sizeof(LogVar), LogVar);
} }
gRT->SetVariable(L"FS_NAME_NOCASE", &gShellVariableGuid, gRT->SetVariable(L"FS_NAME_NOCASE", &gShellVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(LogVar), LogVar); sizeof(LogVar), LogVar);
@@ -732,7 +732,7 @@ STATIC EFI_STATUS ventoy_proc_img_replace_name(ventoy_grub_param_file_replace *r
} }
AsciiStrCpyS(tmp, sizeof(tmp), replace->old_file_name[0]); AsciiStrCpyS(tmp, sizeof(tmp), replace->old_file_name[0]);
for (i = 0; i < 256 && tmp[i]; i++) for (i = 0; i < 256 && tmp[i]; i++)
{ {
if (tmp[i] == '/') if (tmp[i] == '/')
@@ -755,7 +755,7 @@ EFI_STATUS EFIAPI ventoy_get_variable_wrapper
) )
{ {
EFI_STATUS Status = EFI_SUCCESS; EFI_STATUS Status = EFI_SUCCESS;
Status = g_org_get_variable(VariableName, VendorGuid, Attributes, DataSize, Data); Status = g_org_get_variable(VariableName, VendorGuid, Attributes, DataSize, Data);
if (StrCmp(VariableName, L"SecureBoot") == 0) if (StrCmp(VariableName, L"SecureBoot") == 0)
{ {
@@ -779,7 +779,7 @@ EFI_STATUS EFIAPI ventoy_exit_boot_service_wrapper
gRT->GetVariable = g_org_get_variable; gRT->GetVariable = g_org_get_variable;
g_org_get_variable = NULL; g_org_get_variable = NULL;
} }
return g_org_exit_boot_service(ImageHandle, MapKey); return g_org_exit_boot_service(ImageHandle, MapKey);
} }
@@ -803,12 +803,12 @@ STATIC EFI_STATUS EFIAPI ventoy_disable_secure_boot(IN EFI_HANDLE ImageHandle)
/* step1: wrapper security protocol. */ /* step1: wrapper security protocol. */
/* Do we still need it since we have been loaded ? */ /* Do we still need it since we have been loaded ? */
/* step2: fake SecureBoot variable */ /* step2: fake SecureBoot variable */
g_org_exit_boot_service = gBS->ExitBootServices; g_org_exit_boot_service = gBS->ExitBootServices;
gBS->ExitBootServices = ventoy_exit_boot_service_wrapper; gBS->ExitBootServices = ventoy_exit_boot_service_wrapper;
g_org_get_variable = gRT->GetVariable; g_org_get_variable = gRT->GetVariable;
gRT->GetVariable = ventoy_get_variable_wrapper; gRT->GetVariable = ventoy_get_variable_wrapper;
@@ -817,7 +817,7 @@ STATIC EFI_STATUS EFIAPI ventoy_disable_secure_boot(IN EFI_HANDLE ImageHandle)
STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle) STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
{ {
UINT32 i = 0; UINT32 i = 0;
UINT32 old_cnt = 0; UINT32 old_cnt = 0;
UINTN size = 0; UINTN size = 0;
@@ -846,12 +846,12 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
{ {
gDebugPrint = TRUE; gDebugPrint = TRUE;
} }
if (StrStr(pCmdLine, L"fallback")) if (StrStr(pCmdLine, L"fallback"))
{ {
gBootFallBack = TRUE; gBootFallBack = TRUE;
} }
if (StrStr(pCmdLine, L"dotefi")) if (StrStr(pCmdLine, L"dotefi"))
{ {
gDotEfiBoot = TRUE; gDotEfiBoot = TRUE;
@@ -861,7 +861,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
{ {
gLoadIsoEfi = TRUE; gLoadIsoEfi = TRUE;
} }
if (StrStr(pCmdLine, L"iso_udf")) if (StrStr(pCmdLine, L"iso_udf"))
{ {
gIsoUdf = TRUE; gIsoUdf = TRUE;
@@ -899,7 +899,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
{ {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
pGrubParam = (ventoy_grub_param *)StrHexToUintn(pPos + StrLen(L"env_param=")); pGrubParam = (ventoy_grub_param *)StrHexToUintn(pPos + StrLen(L"env_param="));
grub_env_set = pGrubParam->grub_env_set; grub_env_set = pGrubParam->grub_env_set;
grub_env_get = pGrubParam->grub_env_get; grub_env_get = pGrubParam->grub_env_get;
@@ -914,7 +914,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
ventoy_warn_invalid_device(); ventoy_warn_invalid_device();
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
g_file_replace_list = &pGrubParam->file_replace; g_file_replace_list = &pGrubParam->file_replace;
old_cnt = g_file_replace_list->old_file_cnt; old_cnt = g_file_replace_list->old_file_cnt;
debug("file replace: magic:0x%x virtid:%u name count:%u <%a> <%a> <%a> <%a>", debug("file replace: magic:0x%x virtid:%u name count:%u <%a> <%a> <%a> <%a>",
@@ -927,7 +927,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
old_cnt > 3 ? g_file_replace_list->old_file_name[3] : "" old_cnt > 3 ? g_file_replace_list->old_file_name[3] : ""
); );
for (i = 0; i < VTOY_MAX_CONF_REPLACE; i++) for (i = 0; i < VTOY_MAX_CONF_REPLACE; i++)
{ {
replace = pGrubParam->img_replace + i; replace = pGrubParam->img_replace + i;
@@ -948,7 +948,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
} }
} }
pPos = StrStr(pCmdLine, L"mem:"); pPos = StrStr(pCmdLine, L"mem:");
chain = (ventoy_chain_head *)StrHexToUintn(pPos + 4); chain = (ventoy_chain_head *)StrHexToUintn(pPos + 4);
@@ -977,7 +977,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
debug("This is normal mode"); debug("This is normal mode");
g_chain = AllocatePool(size); g_chain = AllocatePool(size);
CopyMem(g_chain, chain, size); CopyMem(g_chain, chain, size);
g_chunk = (ventoy_img_chunk *)((char *)g_chain + g_chain->img_chunk_offset); g_chunk = (ventoy_img_chunk *)((char *)g_chain + g_chain->img_chunk_offset);
g_img_chunk_num = g_chain->img_chunk_num; g_img_chunk_num = g_chain->img_chunk_num;
g_override_chunk = (ventoy_override_chunk *)((char *)g_chain + g_chain->override_chunk_offset); g_override_chunk = (ventoy_override_chunk *)((char *)g_chain + g_chain->override_chunk_offset);
@@ -997,7 +997,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
{ {
g_hook_keyboard = TRUE; g_hook_keyboard = TRUE;
} }
if (g_os_param_reserved[5] == 1 && g_os_param_reserved[2] == ventoy_chain_linux) if (g_os_param_reserved[5] == 1 && g_os_param_reserved[2] == ventoy_chain_linux)
{ {
ventoy_disable_secure_boot(ImageHandle); ventoy_disable_secure_boot(ImageHandle);
@@ -1024,7 +1024,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
} }
g_fix_windows_1st_cdrom_issue = FALSE; g_fix_windows_1st_cdrom_issue = FALSE;
if (ventoy_chain_windows == g_os_param_reserved[2] || if (ventoy_chain_windows == g_os_param_reserved[2] ||
ventoy_chain_wim == g_os_param_reserved[2]) ventoy_chain_wim == g_os_param_reserved[2])
{ {
if (ventoy_is_cdrom_dp_exist()) if (ventoy_is_cdrom_dp_exist())
@@ -1066,7 +1066,7 @@ EFI_STATUS EFIAPI ventoy_clean_env(VOID)
if (!gMemdiskMode) if (!gMemdiskMode)
{ {
FreePool(g_chain); FreePool(g_chain);
} }
return EFI_SUCCESS; return EFI_SUCCESS;
@@ -1126,7 +1126,7 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
Count = 0; Count = 0;
Handles = NULL; Handles = NULL;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid,
NULL, &Count, &Handles); NULL, &Count, &Handles);
if (EFI_ERROR(Status)) if (EFI_ERROR(Status))
{ {
@@ -1145,7 +1145,7 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
debug("FS:%u Protocol:%p OpenVolume:%p", i, pFile, pFile->OpenVolume); debug("FS:%u Protocol:%p OpenVolume:%p", i, pFile, pFile->OpenVolume);
Status = gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid, Status = gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid,
(VOID **)&pDevPath, (VOID **)&pDevPath,
ImageHandle, ImageHandle,
Handles[i], Handles[i],
@@ -1165,7 +1165,7 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
for (j = gBootFileStartIndex; j < ARRAY_SIZE(gEfiBootFileName); j++) for (j = gBootFileStartIndex; j < ARRAY_SIZE(gEfiBootFileName); j++)
{ {
Status = ventoy_load_image(ImageHandle, pDevPath, gEfiBootFileName[j], Status = ventoy_load_image(ImageHandle, pDevPath, gEfiBootFileName[j],
StrSize(gEfiBootFileName[j]), &Image); StrSize(gEfiBootFileName[j]), &Image);
if (EFI_SUCCESS == Status) if (EFI_SUCCESS == Status)
{ {
@@ -1187,7 +1187,7 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
{ {
gST->ConIn->Reset(gST->ConIn, FALSE); gST->ConIn->Reset(gST->ConIn, FALSE);
} }
if ((g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC) || g_img_replace_list) if ((g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC) || g_img_replace_list)
{ {
ventoy_wrapper_push_openvolume(pFile->OpenVolume); ventoy_wrapper_push_openvolume(pFile->OpenVolume);
@@ -1199,7 +1199,7 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
//ventoy_wrapper_system(); //ventoy_wrapper_system();
Status = gBS->StartImage(Image, NULL, NULL); Status = gBS->StartImage(Image, NULL, NULL);
ventoy_hook_stop(); ventoy_hook_stop();
if (EFI_ERROR(Status)) if (EFI_ERROR(Status))
{ {
debug("Failed to start image %r", Status); debug("Failed to start image %r", Status);
@@ -1217,7 +1217,7 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
{ {
break; break;
} }
debug("Fs not found, now wait and retry..."); debug("Fs not found, now wait and retry...");
sleep(1); sleep(1);
} }
@@ -1239,7 +1239,7 @@ EFI_STATUS EFIAPI VentoyEfiMain
{ {
EFI_STATUS Status = EFI_SUCCESS; EFI_STATUS Status = EFI_SUCCESS;
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *Protocol; EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *Protocol;
g_sector_flag_num = 512; /* initial value */ g_sector_flag_num = 512; /* initial value */
g_sector_flag = AllocatePool(g_sector_flag_num * sizeof(ventoy_sector_flag)); g_sector_flag = AllocatePool(g_sector_flag_num * sizeof(ventoy_sector_flag));
@@ -1263,6 +1263,11 @@ EFI_STATUS EFIAPI VentoyEfiMain
return Status; return Status;
} }
if (g_os_param_reserved[11] == 1)
{
ventoy_lock_max_res();
}
ventoy_disable_ex_filesystem(); ventoy_disable_ex_filesystem();
if (gMemdiskMode) if (gMemdiskMode)
@@ -1278,12 +1283,12 @@ EFI_STATUS EFIAPI VentoyEfiMain
ventoy_find_iso_disk_fs(ImageHandle); ventoy_find_iso_disk_fs(ImageHandle);
ventoy_load_isoefi_driver(ImageHandle); ventoy_load_isoefi_driver(ImageHandle);
} }
ventoy_install_blockio(ImageHandle, g_iso_buf_size); ventoy_install_blockio(ImageHandle, g_iso_buf_size);
ventoy_debug_pause(); ventoy_debug_pause();
Status = ventoy_boot(ImageHandle); Status = ventoy_boot(ImageHandle);
ventoy_delete_ramdisk_param(); ventoy_delete_ramdisk_param();
if (gLoadIsoEfi && gBlockData.IsoDriverImage) if (gLoadIsoEfi && gBlockData.IsoDriverImage)
@@ -1310,14 +1315,14 @@ EFI_STATUS EFIAPI VentoyEfiMain
} }
ventoy_debug_pause(); ventoy_debug_pause();
ventoy_install_blockio(ImageHandle, g_chain->virt_img_size_in_bytes); ventoy_install_blockio(ImageHandle, g_chain->virt_img_size_in_bytes);
ventoy_debug_pause(); ventoy_debug_pause();
Status = ventoy_boot(ImageHandle); Status = ventoy_boot(ImageHandle);
} }
ventoy_clean_env(); ventoy_clean_env();
} }
@@ -1330,17 +1335,22 @@ EFI_STATUS EFIAPI VentoyEfiMain
sleep(30); sleep(30);
} }
} }
ventoy_clear_input(); ventoy_clear_input();
gST->ConOut->ClearScreen(gST->ConOut); gST->ConOut->ClearScreen(gST->ConOut);
if (gDotEfiBoot && (EFI_NOT_FOUND == Status)) if (gDotEfiBoot && (EFI_NOT_FOUND == Status))
{ {
grub_env_set("vtoy_dotefi_retry", "YES"); grub_env_set("vtoy_dotefi_retry", "YES");
} }
ventoy_enable_ex_filesystem(); ventoy_enable_ex_filesystem();
if (g_os_param_reserved[11] == 1)
{
ventoy_unlock_max_res();
}
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@@ -7,17 +7,17 @@
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the * published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>. * along with this program; if not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#ifndef __VENTOY_H__ #ifndef __VENTOY_H__
#define __VENTOY_H__ #define __VENTOY_H__
@@ -54,7 +54,7 @@ typedef struct ventoy_image_disk_region
typedef struct ventoy_image_location typedef struct ventoy_image_location
{ {
ventoy_guid guid; ventoy_guid guid;
/* image sector size, currently this value is always 2048 */ /* image sector size, currently this value is always 2048 */
UINT32 image_sector_size; UINT32 image_sector_size;
@@ -62,10 +62,10 @@ typedef struct ventoy_image_location
UINT32 disk_sector_size; UINT32 disk_sector_size;
UINT32 region_count; UINT32 region_count;
/* /*
* disk region data * disk region data
* If the image file has more than one fragments in disk, * If the image file has more than one fragments in disk,
* there will be more than one region data here. * there will be more than one region data here.
* *
*/ */
@@ -86,7 +86,7 @@ typedef struct ventoy_os_param
char vtoy_img_path[384]; // It seems to be enough, utf-8 format char vtoy_img_path[384]; // It seems to be enough, utf-8 format
UINT64 vtoy_img_size; // image file size in bytes UINT64 vtoy_img_size; // image file size in bytes
/* /*
* Ventoy will write a copy of ventoy_image_location data into runtime memory * Ventoy will write a copy of ventoy_image_location data into runtime memory
* this is the physically address and length of that memory. * this is the physically address and length of that memory.
* Address 0 means no such data exist. * Address 0 means no such data exist.
@@ -95,7 +95,7 @@ typedef struct ventoy_os_param
*/ */
UINT64 vtoy_img_location_addr; UINT64 vtoy_img_location_addr;
UINT32 vtoy_img_location_len; UINT32 vtoy_img_location_len;
UINT64 vtoy_reserved[4]; // Internal use by ventoy UINT64 vtoy_reserved[4]; // Internal use by ventoy
UINT8 vtoy_disk_signature[4]; UINT8 vtoy_disk_signature[4];
@@ -124,7 +124,7 @@ typedef struct ventoy_chain_head
UINT64 virt_img_size_in_bytes; UINT64 virt_img_size_in_bytes;
UINT32 boot_catalog; UINT32 boot_catalog;
UINT8 boot_catalog_sector[2048]; UINT8 boot_catalog_sector[2048];
UINT32 img_chunk_offset; UINT32 img_chunk_offset;
UINT32 img_chunk_num; UINT32 img_chunk_num;
@@ -199,11 +199,11 @@ typedef struct ventoy_virt_chunk
typedef struct ventoy_sector_flag typedef struct ventoy_sector_flag
{ {
UINT8 flag; // 0:init 1:mem 2:remap UINT8 flag; // 0:init 1:mem 2:remap
UINT64 remap_lba; UINT64 remap_lba;
}ventoy_sector_flag; }ventoy_sector_flag;
typedef struct vtoy_block_data typedef struct vtoy_block_data
{ {
EFI_HANDLE Handle; EFI_HANDLE Handle;
EFI_BLOCK_IO_MEDIA Media; /* Media descriptor */ EFI_BLOCK_IO_MEDIA Media; /* Media descriptor */
@@ -272,7 +272,7 @@ typedef struct ventoy_grub_param
grub_env_set_pf grub_env_set; grub_env_set_pf grub_env_set;
ventoy_grub_param_file_replace file_replace; ventoy_grub_param_file_replace file_replace;
ventoy_grub_param_file_replace img_replace[VTOY_MAX_CONF_REPLACE]; ventoy_grub_param_file_replace img_replace[VTOY_MAX_CONF_REPLACE];
grub_env_printf_pf grub_env_printf; grub_env_printf_pf grub_env_printf;
}ventoy_grub_param; }ventoy_grub_param;
typedef struct ventoy_ram_disk typedef struct ventoy_ram_disk
@@ -318,7 +318,7 @@ typedef struct MBR_HEAD
#pragma pack() #pragma pack()
typedef struct well_known_guid typedef struct well_known_guid
{ {
EFI_GUID *guid; EFI_GUID *guid;
const char *name; const char *name;
@@ -331,7 +331,7 @@ typedef struct ventoy_system_wrapper
EFI_HANDLE_PROTOCOL NewHandleProtocol; EFI_HANDLE_PROTOCOL NewHandleProtocol;
EFI_HANDLE_PROTOCOL OriHandleProtocol; EFI_HANDLE_PROTOCOL OriHandleProtocol;
EFI_OPEN_PROTOCOL NewOpenProtocol; EFI_OPEN_PROTOCOL NewOpenProtocol;
EFI_OPEN_PROTOCOL OriOpenProtocol; EFI_OPEN_PROTOCOL OriOpenProtocol;
@@ -382,7 +382,7 @@ typedef struct DriverBindWrapper
extern BOOLEAN gDebugPrint; extern BOOLEAN gDebugPrint;
VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...); VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...);
EFI_STATUS EFIAPI ventoy_wrapper_system(VOID); EFI_STATUS EFIAPI ventoy_wrapper_system(VOID);
EFI_STATUS EFIAPI ventoy_block_io_read EFI_STATUS EFIAPI ventoy_block_io_read
( (
IN EFI_BLOCK_IO_PROTOCOL *This, IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId, IN UINT32 MediaId,
@@ -428,6 +428,8 @@ EFI_STATUS ventoy_hook_1st_cdrom_start(VOID);
EFI_STATUS ventoy_hook_1st_cdrom_stop(VOID); EFI_STATUS ventoy_hook_1st_cdrom_stop(VOID);
EFI_STATUS ventoy_disable_ex_filesystem(VOID); EFI_STATUS ventoy_disable_ex_filesystem(VOID);
EFI_STATUS ventoy_enable_ex_filesystem(VOID); EFI_STATUS ventoy_enable_ex_filesystem(VOID);
EFI_STATUS ventoy_lock_max_res(VOID);
EFI_STATUS ventoy_unlock_max_res(VOID);
#endif #endif

View File

@@ -7,12 +7,12 @@
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the * published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>. * along with this program; if not, see <http://www.gnu.org/licenses/>.
* *
@@ -85,7 +85,7 @@ BOOLEAN ventoy_is_cdrom_dp_exist(VOID)
EFI_STATUS Status = EFI_SUCCESS; EFI_STATUS Status = EFI_SUCCESS;
EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL; EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiDevicePathProtocolGuid, Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiDevicePathProtocolGuid,
NULL, &Count, &Handles); NULL, &Count, &Handles);
if (EFI_ERROR(Status)) if (EFI_ERROR(Status))
{ {
@@ -107,24 +107,24 @@ BOOLEAN ventoy_is_cdrom_dp_exist(VOID)
FreePool(Handles); FreePool(Handles);
return TRUE; return TRUE;
} }
DevicePath = NextDevicePathNode(DevicePath); DevicePath = NextDevicePathNode(DevicePath);
} }
} }
FreePool(Handles); FreePool(Handles);
return FALSE; return FALSE;
} }
#if 0 #if 0
/* Block IO procotol */ /* Block IO procotol */
#endif #endif
EFI_STATUS EFIAPI ventoy_block_io_reset EFI_STATUS EFIAPI ventoy_block_io_reset
( (
IN EFI_BLOCK_IO_PROTOCOL *This, IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification IN BOOLEAN ExtendedVerification
) )
{ {
(VOID)This; (VOID)This;
(VOID)ExtendedVerification; (VOID)ExtendedVerification;
@@ -151,8 +151,8 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
ventoy_img_chunk *pchunk = g_chunk; ventoy_img_chunk *pchunk = g_chunk;
ventoy_override_chunk *pOverride = g_override_chunk; ventoy_override_chunk *pOverride = g_override_chunk;
EFI_BLOCK_IO_PROTOCOL *pRawBlockIo = gBlockData.pRawBlockIo; EFI_BLOCK_IO_PROTOCOL *pRawBlockIo = gBlockData.pRawBlockIo;
debug("read iso sector %lu count %u Buffer:%p Align:%u blk:%u", debug("read iso sector %lu count %u Buffer:%p Align:%u blk:%u",
Sector, Count, Buffer, pRawBlockIo->Media->IoAlign, pRawBlockIo->Media->BlockSize); Sector, Count, Buffer, pRawBlockIo->Media->IoAlign, pRawBlockIo->Media->BlockSize);
ReadStart = Sector * 2048; ReadStart = Sector * 2048;
@@ -207,7 +207,7 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
{ {
OverrideStart = pOverride->img_offset; OverrideStart = pOverride->img_offset;
OverrideEnd = pOverride->img_offset + pOverride->override_size; OverrideEnd = pOverride->img_offset + pOverride->override_size;
if (OverrideStart >= ReadEnd || ReadStart >= OverrideEnd) if (OverrideStart >= ReadEnd || ReadStart >= OverrideEnd)
{ {
continue; continue;
@@ -217,7 +217,7 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
{ {
if (ReadEnd <= OverrideEnd) if (ReadEnd <= OverrideEnd)
{ {
CopyMem(pCurBuf + OverrideStart - ReadStart, pOverride->override_data, ReadEnd - OverrideStart); CopyMem(pCurBuf + OverrideStart - ReadStart, pOverride->override_data, ReadEnd - OverrideStart);
} }
else else
{ {
@@ -228,7 +228,7 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
{ {
if (ReadEnd <= OverrideEnd) if (ReadEnd <= OverrideEnd)
{ {
CopyMem(pCurBuf, pOverride->override_data + ReadStart - OverrideStart, ReadEnd - ReadStart); CopyMem(pCurBuf, pOverride->override_data + ReadStart - OverrideStart, ReadEnd - ReadStart);
} }
else else
{ {
@@ -236,7 +236,7 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
} }
} }
if (g_fixup_iso9660_secover_enable && (!g_fixup_iso9660_secover_start) && if (g_fixup_iso9660_secover_enable && (!g_fixup_iso9660_secover_start) &&
pOverride->override_size == sizeof(ventoy_iso9660_override)) pOverride->override_size == sizeof(ventoy_iso9660_override))
{ {
ventoy_iso9660_override *dirent = (ventoy_iso9660_override *)pOverride->override_data; ventoy_iso9660_override *dirent = (ventoy_iso9660_override *)pOverride->override_data;
@@ -256,7 +256,7 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
STATIC EFI_STATUS EFIAPI ventoy_write_iso_sector STATIC EFI_STATUS EFIAPI ventoy_write_iso_sector
@@ -276,7 +276,7 @@ STATIC EFI_STATUS EFIAPI ventoy_write_iso_sector
UINT8 *pCurBuf = (UINT8 *)Buffer; UINT8 *pCurBuf = (UINT8 *)Buffer;
ventoy_img_chunk *pchunk = g_chunk; ventoy_img_chunk *pchunk = g_chunk;
EFI_BLOCK_IO_PROTOCOL *pRawBlockIo = gBlockData.pRawBlockIo; EFI_BLOCK_IO_PROTOCOL *pRawBlockIo = gBlockData.pRawBlockIo;
debug("write iso sector %lu count %u", Sector, Count); debug("write iso sector %lu count %u", Sector, Count);
ReadStart = Sector * 2048; ReadStart = Sector * 2048;
@@ -321,17 +321,17 @@ STATIC EFI_STATUS EFIAPI ventoy_write_iso_sector
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_STATUS EFIAPI ventoy_block_io_ramdisk_write EFI_STATUS EFIAPI ventoy_block_io_ramdisk_write
( (
IN EFI_BLOCK_IO_PROTOCOL *This, IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId, IN UINT32 MediaId,
IN EFI_LBA Lba, IN EFI_LBA Lba,
IN UINTN BufferSize, IN UINTN BufferSize,
IN VOID *Buffer IN VOID *Buffer
) )
{ {
(VOID)This; (VOID)This;
(VOID)MediaId; (VOID)MediaId;
@@ -349,14 +349,14 @@ EFI_STATUS EFIAPI ventoy_block_io_ramdisk_write
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_STATUS EFIAPI ventoy_block_io_ramdisk_read EFI_STATUS EFIAPI ventoy_block_io_ramdisk_read
( (
IN EFI_BLOCK_IO_PROTOCOL *This, IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId, IN UINT32 MediaId,
IN EFI_LBA Lba, IN EFI_LBA Lba,
IN UINTN BufferSize, IN UINTN BufferSize,
OUT VOID *Buffer OUT VOID *Buffer
) )
{ {
//debug("### ventoy_block_io_ramdisk_read sector:%u count:%u", (UINT32)Lba, (UINT32)BufferSize / 2048); //debug("### ventoy_block_io_ramdisk_read sector:%u count:%u", (UINT32)Lba, (UINT32)BufferSize / 2048);
@@ -364,12 +364,12 @@ EFI_STATUS EFIAPI ventoy_block_io_ramdisk_read
(VOID)MediaId; (VOID)MediaId;
CopyMem(Buffer, g_iso_data_buf + (Lba * 2048), BufferSize); CopyMem(Buffer, g_iso_data_buf + (Lba * 2048), BufferSize);
if (g_blockio_start_record_bcd && FALSE == g_blockio_bcd_read_done) if (g_blockio_start_record_bcd && FALSE == g_blockio_bcd_read_done)
{ {
if (*(UINT32 *)Buffer == 0x66676572) if (*(UINT32 *)Buffer == 0x66676572)
{ {
g_blockio_bcd_read_done = TRUE; g_blockio_bcd_read_done = TRUE;
} }
} }
@@ -429,14 +429,14 @@ end:
return Lba; return Lba;
} }
EFI_STATUS EFIAPI ventoy_block_io_read_real EFI_STATUS EFIAPI ventoy_block_io_read_real
( (
IN EFI_BLOCK_IO_PROTOCOL *This, IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId, IN UINT32 MediaId,
IN EFI_LBA Lba, IN EFI_LBA Lba,
IN UINTN BufferSize, IN UINTN BufferSize,
OUT VOID *Buffer OUT VOID *Buffer
) )
{ {
UINT32 i = 0; UINT32 i = 0;
UINT32 j = 0; UINT32 j = 0;
@@ -450,7 +450,7 @@ EFI_STATUS EFIAPI ventoy_block_io_read_real
UINT8 *lastbuffer; UINT8 *lastbuffer;
ventoy_sector_flag *cur_flag; ventoy_sector_flag *cur_flag;
ventoy_virt_chunk *node; ventoy_virt_chunk *node;
debug("### block_io_read_real sector:%u count:%u Buffer:%p", (UINT32)Lba, (UINT32)BufferSize / 2048, Buffer); debug("### block_io_read_real sector:%u count:%u Buffer:%p", (UINT32)Lba, (UINT32)BufferSize / 2048, Buffer);
secNum = BufferSize / 2048; secNum = BufferSize / 2048;
@@ -510,7 +510,7 @@ EFI_STATUS EFIAPI ventoy_block_io_read_real
{ {
if (curlba >= node->mem_sector_start && curlba < node->mem_sector_end) if (curlba >= node->mem_sector_start && curlba < node->mem_sector_end)
{ {
CopyMem((UINT8 *)Buffer + j * 2048, CopyMem((UINT8 *)Buffer + j * 2048,
(char *)g_virt_chunk + node->mem_sector_offset + (curlba - node->mem_sector_start) * 2048, (char *)g_virt_chunk + node->mem_sector_offset + (curlba - node->mem_sector_start) * 2048,
2048); 2048);
cur_flag->flag = 1; cur_flag->flag = 1;
@@ -564,7 +564,7 @@ EFI_STATUS EFIAPI ventoy_block_io_read
IN EFI_LBA Lba, IN EFI_LBA Lba,
IN UINTN BufferSize, IN UINTN BufferSize,
OUT VOID *Buffer OUT VOID *Buffer
) )
{ {
UINT32 IoAlign = 0; UINT32 IoAlign = 0;
VOID *NewBuf = NULL; VOID *NewBuf = NULL;
@@ -593,18 +593,18 @@ EFI_STATUS EFIAPI ventoy_block_io_read
return Status; return Status;
} }
EFI_STATUS EFIAPI ventoy_block_io_write EFI_STATUS EFIAPI ventoy_block_io_write
( (
IN EFI_BLOCK_IO_PROTOCOL *This, IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId, IN UINT32 MediaId,
IN EFI_LBA Lba, IN EFI_LBA Lba,
IN UINTN BufferSize, IN UINTN BufferSize,
IN VOID *Buffer IN VOID *Buffer
) )
{ {
UINT32 secNum = 0; UINT32 secNum = 0;
UINT64 offset = 0; UINT64 offset = 0;
(VOID)This; (VOID)This;
(VOID)MediaId; (VOID)MediaId;
@@ -636,8 +636,8 @@ STATIC UINTN ventoy_get_current_device_path_id(VOID)
EFI_STATUS Status = EFI_SUCCESS; EFI_STATUS Status = EFI_SUCCESS;
EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL; EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL;
VENDOR_DEVICE_PATH *venPath = NULL; VENDOR_DEVICE_PATH *venPath = NULL;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiDevicePathProtocolGuid, Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiDevicePathProtocolGuid,
NULL, &Count, &Handles); NULL, &Count, &Handles);
if (EFI_ERROR(Status)) if (EFI_ERROR(Status))
{ {
@@ -688,7 +688,7 @@ EFI_STATUS EFIAPI ventoy_fill_device_path(VOID)
venPath->Header.Length[1] = 0; venPath->Header.Length[1] = 0;
CopyMem(&venPath->Guid, &gVtoyBlockDevicePathGuid, sizeof(EFI_GUID)); CopyMem(&venPath->Guid, &gVtoyBlockDevicePathGuid, sizeof(EFI_GUID));
CopyMem(venPath + 1, VtoyDpName, NameLen); CopyMem(venPath + 1, VtoyDpName, NameLen);
gBlockData.Path = AppendDevicePathNode(NULL, (EFI_DEVICE_PATH_PROTOCOL *)TmpBuf); gBlockData.Path = AppendDevicePathNode(NULL, (EFI_DEVICE_PATH_PROTOCOL *)TmpBuf);
gBlockData.DevicePathCompareLen = sizeof(VENDOR_DEVICE_PATH) + NameLen; gBlockData.DevicePathCompareLen = sizeof(VENDOR_DEVICE_PATH) + NameLen;
@@ -710,7 +710,7 @@ EFI_STATUS EFIAPI ventoy_connect_driver(IN EFI_HANDLE ControllerHandle, IN CONST
debug("ventoy_connect_driver <%s>...", DrvName); debug("ventoy_connect_driver <%s>...", DrvName);
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentName2ProtocolGuid, Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentName2ProtocolGuid,
NULL, &Count, &Handles); NULL, &Count, &Handles);
if (EFI_ERROR(Status)) if (EFI_ERROR(Status))
{ {
@@ -748,7 +748,7 @@ EFI_STATUS EFIAPI ventoy_connect_driver(IN EFI_HANDLE ControllerHandle, IN CONST
FreePool(Handles); FreePool(Handles);
Handles = NULL; Handles = NULL;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentNameProtocolGuid, Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentNameProtocolGuid,
NULL, &Count, &Handles); NULL, &Count, &Handles);
if (EFI_ERROR(Status)) if (EFI_ERROR(Status))
{ {
@@ -781,10 +781,10 @@ EFI_STATUS EFIAPI ventoy_connect_driver(IN EFI_HANDLE ControllerHandle, IN CONST
} }
Status = EFI_NOT_FOUND; Status = EFI_NOT_FOUND;
end: end:
FreePool(Handles); FreePool(Handles);
return Status; return Status;
} }
@@ -805,11 +805,11 @@ STATIC BOOLEAN ventoy_filesystem_need_wrapper(IN CONST CHAR16 *DrvName)
} }
/* /*
* suppress some file system drivers * suppress some file system drivers
* 1. rEFInd File System Driver * 1. rEFInd File System Driver
* *
*/ */
if (StrStr(UpperDrvName, L"REFIND") && StrStr(UpperDrvName, L"FILE SYSTEM")) if (StrStr(UpperDrvName, L"REFIND") && StrStr(UpperDrvName, L"FILE SYSTEM"))
{ {
return TRUE; return TRUE;
@@ -820,7 +820,7 @@ STATIC BOOLEAN ventoy_filesystem_need_wrapper(IN CONST CHAR16 *DrvName)
STATIC VOID ventoy_add_filesystem_wrapper STATIC VOID ventoy_add_filesystem_wrapper
( (
IN EFI_DRIVER_BINDING_PROTOCOL *DriverBindProtocol, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBindProtocol,
IN CONST CHAR16 *DriverName IN CONST CHAR16 *DriverName
) )
{ {
@@ -865,10 +865,10 @@ STATIC EFI_STATUS ventoy_find_filesystem_driverbind(VOID)
EFI_COMPONENT_NAME_PROTOCOL *NameProtocol = NULL; EFI_COMPONENT_NAME_PROTOCOL *NameProtocol = NULL;
EFI_COMPONENT_NAME2_PROTOCOL *Name2Protocol = NULL; EFI_COMPONENT_NAME2_PROTOCOL *Name2Protocol = NULL;
EFI_DRIVER_BINDING_PROTOCOL *DriverBindProtocol = NULL; EFI_DRIVER_BINDING_PROTOCOL *DriverBindProtocol = NULL;
debug("ventoy_find_filesystem_driverbind..."); debug("ventoy_find_filesystem_driverbind...");
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentName2ProtocolGuid, Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentName2ProtocolGuid,
NULL, &Count, &Handles); NULL, &Count, &Handles);
if (EFI_ERROR(Status)) if (EFI_ERROR(Status))
{ {
@@ -899,7 +899,7 @@ STATIC EFI_STATUS ventoy_find_filesystem_driverbind(VOID)
FreePool(Handles); FreePool(Handles);
Handles = NULL; Handles = NULL;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentNameProtocolGuid, Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentNameProtocolGuid,
NULL, &Count, &Handles); NULL, &Count, &Handles);
if (EFI_ERROR(Status)) if (EFI_ERROR(Status))
{ {
@@ -927,7 +927,7 @@ STATIC EFI_STATUS ventoy_find_filesystem_driverbind(VOID)
} }
FreePool(Handles); FreePool(Handles);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@@ -988,7 +988,7 @@ EFI_STATUS ventoy_disable_ex_filesystem(VOID)
debug("Wrapper Ex Driver Binding %lu", g_DriverBindWrapperCnt); debug("Wrapper Ex Driver Binding %lu", g_DriverBindWrapperCnt);
ventoy_debug_pause(); ventoy_debug_pause();
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@@ -1046,10 +1046,10 @@ EFI_STATUS EFIAPI ventoy_block_io_read_512
if (BufferSize >= 2048) if (BufferSize >= 2048)
{ {
ReadSize = BufferSize / 2048 * 2048; ReadSize = BufferSize / 2048 * 2048;
Status |= g_sector_2048_read(This, MediaId, Lba / 4, ReadSize, CurBuf); Status |= g_sector_2048_read(This, MediaId, Lba / 4, ReadSize, CurBuf);
CurBuf += ReadSize; CurBuf += ReadSize;
Lba += ReadSize / 512; Lba += ReadSize / 512;
BufferSize -= ReadSize; BufferSize -= ReadSize;
} }
@@ -1096,7 +1096,7 @@ EFI_STATUS EFIAPI ventoy_block_io_write_512
ReadSize = (4 - Mod) * 512; ReadSize = (4 - Mod) * 512;
CopyMem(g_sector_buf + Mod * 512, CurBuf, ReadSize); CopyMem(g_sector_buf + Mod * 512, CurBuf, ReadSize);
g_sector_2048_write(This, MediaId, Lba / 4, 2048, g_sector_buf); g_sector_2048_write(This, MediaId, Lba / 4, 2048, g_sector_buf);
CurBuf += ReadSize; CurBuf += ReadSize;
Lba += (4 - Mod); Lba += (4 - Mod);
BufferSize -= ReadSize; BufferSize -= ReadSize;
@@ -1106,10 +1106,10 @@ EFI_STATUS EFIAPI ventoy_block_io_write_512
if (BufferSize >= 2048) if (BufferSize >= 2048)
{ {
ReadSize = BufferSize / 2048 * 2048; ReadSize = BufferSize / 2048 * 2048;
Status |= g_sector_2048_write(This, MediaId, Lba / 4, ReadSize, CurBuf); Status |= g_sector_2048_write(This, MediaId, Lba / 4, ReadSize, CurBuf);
CurBuf += ReadSize; CurBuf += ReadSize;
Lba += ReadSize / 512; Lba += ReadSize / 512;
BufferSize -= ReadSize; BufferSize -= ReadSize;
} }
@@ -1117,7 +1117,7 @@ EFI_STATUS EFIAPI ventoy_block_io_write_512
if (BufferSize > 0) if (BufferSize > 0)
{ {
Status |= g_sector_2048_read(This, MediaId, Lba / 4, 2048, g_sector_buf); Status |= g_sector_2048_read(This, MediaId, Lba / 4, 2048, g_sector_buf);
CopyMem(g_sector_buf, CurBuf, BufferSize); CopyMem(g_sector_buf, CurBuf, BufferSize);
g_sector_2048_write(This, MediaId, Lba / 4, 2048, g_sector_buf); g_sector_2048_write(This, MediaId, Lba / 4, 2048, g_sector_buf);
} }
@@ -1126,10 +1126,10 @@ EFI_STATUS EFIAPI ventoy_block_io_write_512
} }
EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 ImgSize) EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 ImgSize)
{ {
EFI_STATUS Status = EFI_SUCCESS; EFI_STATUS Status = EFI_SUCCESS;
EFI_BLOCK_IO_PROTOCOL *pBlockIo = &(gBlockData.BlockIo); EFI_BLOCK_IO_PROTOCOL *pBlockIo = &(gBlockData.BlockIo);
ventoy_fill_device_path(); ventoy_fill_device_path();
debug("install block io protocol %p", ImageHandle); debug("install block io protocol %p", ImageHandle);
@@ -1144,10 +1144,10 @@ EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 Im
else else
{ {
gBlockData.Media.BlockSize = 2048; gBlockData.Media.BlockSize = 2048;
gBlockData.Media.LastBlock = ImgSize / 2048 - 1; gBlockData.Media.LastBlock = ImgSize / 2048 - 1;
gBlockData.Media.ReadOnly = TRUE; gBlockData.Media.ReadOnly = TRUE;
} }
gBlockData.Media.MediaPresent = 1; gBlockData.Media.MediaPresent = 1;
gBlockData.Media.LogicalBlocksPerPhysicalBlock = 1; gBlockData.Media.LogicalBlocksPerPhysicalBlock = 1;
@@ -1164,10 +1164,10 @@ EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 Im
} }
else else
{ {
pBlockIo->ReadBlocks = gMemdiskMode ? ventoy_block_io_ramdisk_read : ventoy_block_io_read; pBlockIo->ReadBlocks = gMemdiskMode ? ventoy_block_io_ramdisk_read : ventoy_block_io_read;
pBlockIo->WriteBlocks = ventoy_block_io_write; pBlockIo->WriteBlocks = ventoy_block_io_write;
} }
pBlockIo->FlushBlocks = ventoy_block_io_flush; pBlockIo->FlushBlocks = ventoy_block_io_flush;
Status = gBS->InstallMultipleProtocolInterfaces(&gBlockData.Handle, Status = gBS->InstallMultipleProtocolInterfaces(&gBlockData.Handle,
@@ -1295,7 +1295,7 @@ DEF_WRAP_FUNC(7);
#error "VTOY_MAX_CONF_REPLACE overflow" #error "VTOY_MAX_CONF_REPLACE overflow"
#endif #endif
static EFI_FILE_FLUSH_EX g_img_flush_func[VTOY_MAX_CONF_REPLACE] = static EFI_FILE_FLUSH_EX g_img_flush_func[VTOY_MAX_CONF_REPLACE] =
{ {
ventoy_wrapper_file_flush_ex_img0, ventoy_wrapper_file_flush_ex_img0,
ventoy_wrapper_file_flush_ex_img1, ventoy_wrapper_file_flush_ex_img1,
@@ -1335,7 +1335,7 @@ STATIC ventoy_efi_file_replace *ventoy_wrapper_get_replace(EFI_FILE_HANDLE This)
return g_img_file_replace + i; return g_img_file_replace + i;
} }
} }
return NULL; return NULL;
} }
@@ -1369,7 +1369,7 @@ ventoy_wrapper_file_set_pos(EFI_FILE_HANDLE This, UINT64 Position)
ventoy_efi_file_replace *replace = NULL; ventoy_efi_file_replace *replace = NULL;
replace = ventoy_wrapper_get_replace(This); replace = ventoy_wrapper_get_replace(This);
if (Position <= replace->FileSizeBytes) if (Position <= replace->FileSizeBytes)
{ {
replace->CurPos = Position; replace->CurPos = Position;
@@ -1378,7 +1378,7 @@ ventoy_wrapper_file_set_pos(EFI_FILE_HANDLE This, UINT64 Position)
{ {
replace->CurPos = replace->FileSizeBytes; replace->CurPos = replace->FileSizeBytes;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@@ -1425,7 +1425,7 @@ ventoy_wrapper_file_get_info(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN *Len, V
//Info->FileName = EFI_FILE_READ_ONLY; //Info->FileName = EFI_FILE_READ_ONLY;
*Len = Info->Size; *Len = Info->Size;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@@ -1437,7 +1437,7 @@ ventoy_wrapper_file_read(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
ventoy_efi_file_replace *replace = NULL; ventoy_efi_file_replace *replace = NULL;
replace = ventoy_wrapper_get_replace(This); replace = ventoy_wrapper_get_replace(This);
debug("ventoy_wrapper_file_read ... %u", *Len); debug("ventoy_wrapper_file_read ... %u", *Len);
if (replace->CurPos + ReadLen > replace->FileSizeBytes) if (replace->CurPos + ReadLen > replace->FileSizeBytes)
@@ -1494,7 +1494,7 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File, B
STATIC BOOLEAN EFIAPI ventoy_replace_name_match(CHAR8 *pReplace, CHAR8 *pName) STATIC BOOLEAN EFIAPI ventoy_replace_name_match(CHAR8 *pReplace, CHAR8 *pName)
{ {
UINTN Len1, Len2; UINTN Len1, Len2;
Len1 = AsciiStrLen(pReplace); Len1 = AsciiStrLen(pReplace);
Len2 = AsciiStrLen(pName); Len2 = AsciiStrLen(pName);
@@ -1521,10 +1521,10 @@ STATIC BOOLEAN EFIAPI ventoy_replace_name_match(CHAR8 *pReplace, CHAR8 *pName)
STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
( (
EFI_FILE_HANDLE This, EFI_FILE_HANDLE This,
EFI_FILE_HANDLE *New, EFI_FILE_HANDLE *New,
CHAR16 *Name, CHAR16 *Name,
UINT64 Mode, UINT64 Mode,
UINT64 Attributes UINT64 Attributes
) )
{ {
@@ -1571,7 +1571,7 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
virt = g_virt_chunk + g_file_replace_list->new_file_virtual_id; virt = g_virt_chunk + g_file_replace_list->new_file_virtual_id;
Sectors = (virt->mem_sector_end - virt->mem_sector_start) + (virt->remap_sector_end - virt->remap_sector_start); Sectors = (virt->mem_sector_end - virt->mem_sector_start) + (virt->remap_sector_end - virt->remap_sector_start);
g_efi_file_replace.BlockIoSectorStart = virt->mem_sector_start; g_efi_file_replace.BlockIoSectorStart = virt->mem_sector_start;
g_efi_file_replace.FileSizeBytes = Sectors * 2048; g_efi_file_replace.FileSizeBytes = Sectors * 2048;
@@ -1581,7 +1581,7 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
g_efi_file_replace.BlockIoSectorStart, Sectors, Sectors * 2048); g_efi_file_replace.BlockIoSectorStart, Sectors, Sectors * 2048);
sleep(3); sleep(3);
} }
return Status; return Status;
} }
} }
@@ -1605,9 +1605,9 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
{ {
AsciiStrCpyS(OldName, sizeof(OldName), replace->old_file_name[j]); AsciiStrCpyS(OldName, sizeof(OldName), replace->old_file_name[j]);
if ((0 == AsciiStrCmp(OldName, TmpName)) || if ((0 == AsciiStrCmp(OldName, TmpName)) ||
(AsciiStrnCmp(OldName, "\\loader\\entries\\", 16) == 0 && (AsciiStrnCmp(OldName, "\\loader\\entries\\", 16) == 0 &&
AsciiStrCmp(OldName + 16, TmpName) == 0 AsciiStrCmp(OldName + 16, TmpName) == 0
) )
) )
{ {
g_original_fclose(*New); g_original_fclose(*New);
@@ -1617,7 +1617,7 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
virt = g_virt_chunk + replace->new_file_virtual_id; virt = g_virt_chunk + replace->new_file_virtual_id;
Sectors = (virt->mem_sector_end - virt->mem_sector_start) + (virt->remap_sector_end - virt->remap_sector_start); Sectors = (virt->mem_sector_end - virt->mem_sector_start) + (virt->remap_sector_end - virt->remap_sector_start);
g_img_file_replace[i].BlockIoSectorStart = virt->mem_sector_start; g_img_file_replace[i].BlockIoSectorStart = virt->mem_sector_start;
g_img_file_replace[i].FileSizeBytes = Sectors * 2048; g_img_file_replace[i].FileSizeBytes = Sectors * 2048;
@@ -1627,7 +1627,7 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
g_img_file_replace[i].BlockIoSectorStart, Sectors, Sectors * 2048); g_img_file_replace[i].BlockIoSectorStart, Sectors, Sectors * 2048);
sleep(3); sleep(3);
} }
return Status; return Status;
} }
} }
@@ -1648,7 +1648,7 @@ EFI_STATUS EFIAPI ventoy_wrapper_open_volume
) )
{ {
EFI_STATUS Status = EFI_SUCCESS; EFI_STATUS Status = EFI_SUCCESS;
Status = g_original_open_volume(This, Root); Status = g_original_open_volume(This, Root);
if (!EFI_ERROR(Status)) if (!EFI_ERROR(Status))
{ {
@@ -1685,10 +1685,10 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_read_key_ex
KeyData->Key.UnicodeChar = 0; KeyData->Key.UnicodeChar = 0;
KeyData->KeyState.KeyShiftState = 0; KeyData->KeyState.KeyShiftState = 0;
KeyData->KeyState.KeyToggleState = 0; KeyData->KeyState.KeyToggleState = 0;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
return g_org_read_key_ex(This, KeyData); return g_org_read_key_ex(This, KeyData);
} }
@@ -1725,7 +1725,7 @@ EFI_STATUS ventoy_hook_keyboard_start(VOID)
g_org_read_key = gST->ConIn->ReadKeyStroke; g_org_read_key = gST->ConIn->ReadKeyStroke;
gST->ConIn->ReadKeyStroke = ventoy_wrapper_read_key; gST->ConIn->ReadKeyStroke = ventoy_wrapper_read_key;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@@ -1763,7 +1763,7 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_locate_handle
EFI_STATUS Status = EFI_SUCCESS; EFI_STATUS Status = EFI_SUCCESS;
Status = g_org_locate_handle(SearchType, Protocol, SearchKey, BufferSize, Buffer); Status = g_org_locate_handle(SearchType, Protocol, SearchKey, BufferSize, Buffer);
if (EFI_SUCCESS == Status && Protocol && CompareGuid(&gEfiBlockIoProtocolGuid, Protocol)) if (EFI_SUCCESS == Status && Protocol && CompareGuid(&gEfiBlockIoProtocolGuid, Protocol))
{ {
for (i = 0; i < (*BufferSize) / sizeof(EFI_HANDLE); i++) for (i = 0; i < (*BufferSize) / sizeof(EFI_HANDLE); i++)
@@ -1785,7 +1785,7 @@ EFI_STATUS ventoy_hook_1st_cdrom_start(VOID)
{ {
g_org_locate_handle = gBS->LocateHandle; g_org_locate_handle = gBS->LocateHandle;
gBS->LocateHandle = ventoy_wrapper_locate_handle; gBS->LocateHandle = ventoy_wrapper_locate_handle;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@@ -1793,7 +1793,112 @@ EFI_STATUS ventoy_hook_1st_cdrom_stop(VOID)
{ {
gBS->LocateHandle = g_org_locate_handle; gBS->LocateHandle = g_org_locate_handle;
g_org_locate_handle = NULL; g_org_locate_handle = NULL;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
#if 0
/* For force highest resolution for Windows/WinPE */
#endif
STATIC UINT32 g_org_mode_num;
STATIC EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE g_org_set_mode = NULL;
STATIC EFI_STATUS EFIAPI ventoy_set_mode
(
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN UINT32 ModeNumber
)
{
(void)This;
(void)ModeNumber;
/* Force highest resolution */
return EFI_SUCCESS;
}
EFI_STATUS ventoy_lock_max_res(VOID)
{
UINT32 i = 0;
UINT32 x = 0;
UINT32 y = 0;
UINT32 CurMode = 0;
UINT32 Highest = 0;
UINTN Size;
EFI_STATUS rc;
EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info = NULL;
/* already hook */
if (g_org_set_mode)
{
return EFI_SUCCESS;
}
rc = gBS->LocateProtocol(&gEfiGraphicsOutputProtocolGuid, NULL, (void **)&gop);
if (rc != EFI_SUCCESS)
{
debug("Failed to locate GOP protocol");
return EFI_SUCCESS;
}
CurMode = gop->Mode->Mode;
for (i = 0 ; i < gop->Mode->MaxMode ; i++)
{
/* Get mode information */
if (gop->QueryMode(gop, i, &Size, &info) == EFI_SUCCESS)
{
if (x < info->HorizontalResolution ||
(x == info->HorizontalResolution && y < info->VerticalResolution))
{
Highest = i;
x = info->HorizontalResolution;
y = info->VerticalResolution;
}
}
}
if (Highest != CurMode)
{
gop->SetMode(gop, Highest);
}
debug("Lock resolution to Mode:%d %d x %d", Highest, x, y);
g_org_mode_num = CurMode;
g_org_set_mode = gop->SetMode;
gop->SetMode = ventoy_set_mode;
return EFI_SUCCESS;
}
EFI_STATUS ventoy_unlock_max_res(VOID)
{
EFI_STATUS rc;
EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
/* not hooked yet */
if (!g_org_set_mode)
{
return EFI_SUCCESS;
}
rc = gBS->LocateProtocol(&gEfiGraphicsOutputProtocolGuid, NULL, (void **)&gop);
if (rc != EFI_SUCCESS)
{
debug("Failed to locate GOP protocol");
return EFI_SUCCESS;
}
g_org_set_mode(gop, g_org_mode_num);
gop->SetMode = g_org_set_mode;
g_org_set_mode = NULL;
return EFI_SUCCESS;
}

View File

@@ -1,5 +1,5 @@
/****************************************************************************** /******************************************************************************
* ventoy.c * ventoy.c
* *
* Copyright (c) 2020, longpanda <admin@ventoy.net> * Copyright (c) 2020, longpanda <admin@ventoy.net>
* *
@@ -7,12 +7,12 @@
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the * published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>. * along with this program; if not, see <http://www.gnu.org/licenses/>.
* *
@@ -137,7 +137,7 @@ int ventoy_str_len_alnum(const char *str, int len)
{ {
int i; int i;
int slen; int slen;
if (NULL == str || 0 == *str) if (NULL == str || 0 == *str)
{ {
return 0; return 0;
@@ -168,7 +168,7 @@ int ventoy_str_len_alnum(const char *str, int len)
char * ventoy_str_basename(char *path) char * ventoy_str_basename(char *path)
{ {
char *pos = NULL; char *pos = NULL;
pos = grub_strrchr(path, '/'); pos = grub_strrchr(path, '/');
if (pos) if (pos)
{ {
@@ -185,17 +185,17 @@ char * ventoy_str_basename(char *path)
int ventoy_str_chrcnt(const char *str, char c) int ventoy_str_chrcnt(const char *str, char c)
{ {
int n = 0; int n = 0;
if (str) if (str)
{ {
while (*str) while (*str)
{ {
if (*str == c) if (*str == c)
{ {
n++; n++;
} }
str++; str++;
} }
} }
return n; return n;
@@ -235,7 +235,7 @@ int ventoy_strncmp (const char *pattern, const char *str, grub_size_t n)
grub_err_t ventoy_env_int_set(const char *name, int value) grub_err_t ventoy_env_int_set(const char *name, int value)
{ {
char buf[16]; char buf[16];
grub_snprintf(buf, sizeof(buf), "%d", value); grub_snprintf(buf, sizeof(buf), "%d", value);
return grub_env_set(name, buf); return grub_env_set(name, buf);
} }
@@ -248,13 +248,13 @@ void ventoy_debug_dump_guid(const char *prefix, grub_uint8_t *guid)
{ {
return; return;
} }
debug("%s", prefix); debug("%s", prefix);
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ {
grub_printf("%02x ", guid[i]); grub_printf("%02x ", guid[i]);
} }
grub_printf("\n"); grub_printf("\n");
} }
int ventoy_is_efi_os(void) int ventoy_is_efi_os(void)
@@ -290,7 +290,7 @@ void ventoy_memfile_env_set(const char *prefix, const void *buf, unsigned long l
grub_snprintf(name, sizeof(name), "%s_addr", prefix); grub_snprintf(name, sizeof(name), "%s_addr", prefix);
grub_snprintf(val, sizeof(val), "0x%llx", (ulonglong)(ulong)buf); grub_snprintf(val, sizeof(val), "0x%llx", (ulonglong)(ulong)buf);
grub_env_set(name, val); grub_env_set(name, val);
grub_snprintf(name, sizeof(name), "%s_size", prefix); grub_snprintf(name, sizeof(name), "%s_size", prefix);
grub_snprintf(val, sizeof(val), "%llu", len); grub_snprintf(val, sizeof(val), "%llu", len);
grub_env_set(name, val); grub_env_set(name, val);
@@ -374,7 +374,7 @@ static int ventoy_hwinfo_init(void)
return 0; return 0;
} }
static global_var_cfg g_global_vars[] = static global_var_cfg g_global_vars[] =
{ {
{ "gfxmode", "1024x768", NULL }, { "gfxmode", "1024x768", NULL },
{ ventoy_left_key, "5%", NULL }, { ventoy_left_key, "5%", NULL },
@@ -422,19 +422,20 @@ int ventoy_global_var_init(void)
for (i = 0; g_global_vars[i].name; i++) for (i = 0; g_global_vars[i].name; i++)
{ {
g_global_vars[i].value = grub_strdup(g_global_vars[i].defval); g_global_vars[i].value = grub_strdup(g_global_vars[i].defval);
ventoy_env_export(g_global_vars[i].name, g_global_vars[i].defval); ventoy_env_export(g_global_vars[i].name, g_global_vars[i].defval);
grub_register_variable_hook(g_global_vars[i].name, ventoy_global_var_read_hook, ventoy_global_var_write_hook); grub_register_variable_hook(g_global_vars[i].name, ventoy_global_var_read_hook, ventoy_global_var_write_hook);
} }
return 0; return 0;
} }
static ctrl_var_cfg g_ctrl_vars[] = static ctrl_var_cfg g_ctrl_vars[] =
{ {
{ "VTOY_WIN11_BYPASS_CHECK", 1 }, { "VTOY_WIN11_BYPASS_CHECK", 1 },
{ "VTOY_WIN11_BYPASS_NRO", 1 }, { "VTOY_WIN11_BYPASS_NRO", 1 },
{ "VTOY_LINUX_REMOUNT", 0 }, { "VTOY_LINUX_REMOUNT", 0 },
{ "VTOY_SECONDARY_BOOT_MENU", 1 }, { "VTOY_SECONDARY_BOOT_MENU", 1 },
{ "VTOY_WIN_UEFI_MAX_RES", 1 },
{ NULL, 0 } { NULL, 0 }
}; };

File diff suppressed because it is too large Load Diff

View File

@@ -7,12 +7,12 @@
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the * published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>. * along with this program; if not, see <http://www.gnu.org/licenses/>.
* *
@@ -82,7 +82,7 @@ typedef struct ventoy_image_location
/* /*
* disk region data (region_count) * disk region data (region_count)
* If the image file has more than one fragments in disk, * If the image file has more than one fragments in disk,
* there will be more than one region data here. * there will be more than one region data here.
* *
*/ */
@@ -104,7 +104,7 @@ typedef struct ventoy_os_param
char vtoy_img_path[384]; // It seems to be enough, utf-8 format char vtoy_img_path[384]; // It seems to be enough, utf-8 format
grub_uint64_t vtoy_img_size; // image file size in bytes grub_uint64_t vtoy_img_size; // image file size in bytes
/* /*
* Ventoy will write a copy of ventoy_image_location data into runtime memory * Ventoy will write a copy of ventoy_image_location data into runtime memory
* this is the physically address and length of that memory. * this is the physically address and length of that memory.
* Address 0 means no such data exist. * Address 0 means no such data exist.
@@ -114,7 +114,7 @@ typedef struct ventoy_os_param
grub_uint64_t vtoy_img_location_addr; grub_uint64_t vtoy_img_location_addr;
grub_uint32_t vtoy_img_location_len; grub_uint32_t vtoy_img_location_len;
/* /*
* These 32 bytes are reserved by ventoy. * These 32 bytes are reserved by ventoy.
* *
* vtoy_reserved[0]: vtoy_break_level * vtoy_reserved[0]: vtoy_break_level
@@ -125,6 +125,7 @@ typedef struct ventoy_os_param
* vtoy_reserved[5]: vtoy_linux_remount * vtoy_reserved[5]: vtoy_linux_remount
* vtoy_reserved[6]: vtoy_vlnk * vtoy_reserved[6]: vtoy_vlnk
* vtoy_reserved[7~10]: vtoy_disk_sig[4] used for vlnk * vtoy_reserved[7~10]: vtoy_disk_sig[4] used for vlnk
* vtoy_reserved[11]: vtoy_win_uefi_max_res
* *
*/ */
grub_uint8_t vtoy_reserved[32]; // Internal use by ventoy grub_uint8_t vtoy_reserved[32]; // Internal use by ventoy
@@ -155,8 +156,8 @@ typedef struct ventoy_windows_data
typedef struct ventoy_secure_data typedef struct ventoy_secure_data
{ {
grub_uint8_t magic1[16]; /* VENTOY_GUID */ grub_uint8_t magic1[16]; /* VENTOY_GUID */
grub_uint8_t diskuuid[16]; grub_uint8_t diskuuid[16];
grub_uint8_t Checksum[16]; grub_uint8_t Checksum[16];
grub_uint8_t adminSHA256[32]; grub_uint8_t adminSHA256[32];
grub_uint8_t reserved[4000]; grub_uint8_t reserved[4000];
grub_uint8_t magic2[16]; /* VENTOY_GUID */ grub_uint8_t magic2[16]; /* VENTOY_GUID */
@@ -200,7 +201,7 @@ typedef struct ventoy_chain_head
grub_uint64_t virt_img_size_in_bytes; grub_uint64_t virt_img_size_in_bytes;
grub_uint32_t boot_catalog; grub_uint32_t boot_catalog;
grub_uint8_t boot_catalog_sector[2048]; grub_uint8_t boot_catalog_sector[2048];
grub_uint32_t img_chunk_offset; grub_uint32_t img_chunk_offset;
grub_uint32_t img_chunk_num; grub_uint32_t img_chunk_num;
@@ -319,7 +320,7 @@ grub_uint64_t grub_udf_get_file_offset(grub_file_t file);
grub_uint64_t grub_udf_get_last_pd_size_offset(void); grub_uint64_t grub_udf_get_last_pd_size_offset(void);
grub_uint64_t grub_udf_get_last_file_attr_offset grub_uint64_t grub_udf_get_last_file_attr_offset
( (
grub_file_t file, grub_file_t file,
grub_uint32_t *startBlock, grub_uint32_t *startBlock,
grub_uint64_t *fe_entry_size_offset grub_uint64_t *fe_entry_size_offset
); );

View File

@@ -33,11 +33,13 @@ echo "_vtRet1=$_vtRet1 _vtRet2=$_vtRet2 ..." >> $VTLOG
if [ $_vtRet1 -ne 0 -a $_vtRet2 -eq 0 ]; then if [ $_vtRet1 -ne 0 -a $_vtRet2 -eq 0 ]; then
vtFindFlag=0 vtFindFlag=0
$GREP '`value from`' /usr/* -r | $AWK -F: '{print $1}' | while read vtline; do $GREP '`value from`' /usr/* -r | $AWK -F: '{print $1}' > $VTOY_PATH/.porteus
while read vtline; do
echo "hooking $vtline ..." >> $VTLOG echo "hooking $vtline ..." >> $VTLOG
$SED "s#\`value from\`#$vtPath#g" -i $vtline $SED "s#\`value from\`#$vtPath#g" -i $vtline
vtFindFlag=1 vtFindFlag=1
done done < $VTOY_PATH/.porteus
rm -f $VTOY_PATH/.porteus
if [ $vtFindFlag -eq 0 ]; then if [ $vtFindFlag -eq 0 ]; then
if $GREP -q '`value from`' /linuxrc; then if $GREP -q '`value from`' /linuxrc; then

View File

@@ -66,6 +66,16 @@ if [ -f mkexfatfs_static ]; then
if ldd --version 2>&1 | grep -qi musl; then if ldd --version 2>&1 | grep -qi musl; then
mv mkexfatfs mkexfatfs_shared mv mkexfatfs mkexfatfs_shared
mv mkexfatfs_static mkexfatfs mv mkexfatfs_static mkexfatfs
else
if ./mkexfatfs -V > /dev/null 2>&1; then
echo "mkexfatfs can not run, check static version" >> ./log.txt
else
if ./mkexfatfs_static -V > /dev/null 2>&1; then
echo "Use static version of mkexfatfs" >> ./log.txt
mv mkexfatfs mkexfatfs_shared
mv mkexfatfs_static mkexfatfs
fi
fi
fi fi
fi fi

View File

@@ -22,13 +22,22 @@ submenu "$VTLANG_CTRL_TEMP_SET" --class=debug_temp_set --class=F5tool {
} }
menuentry "[ $VTOY_SECONDARY_BOOT_MENU ] $VTLANG_SECONDARY_BOOT_MENU" --class=debug_temp_second_menu --class=debug_temp_set --class=F5tool \ menuentry "[ $VTOY_SECONDARY_BOOT_MENU ] $VTLANG_SECONDARY_BOOT_MENU" --class=debug_temp_second_menu --class=debug_temp_set --class=F5tool \
VTOY_RUN_SET3 { VTOY_RUN_SET2 {
if [ "$VTOY_SECONDARY_BOOT_MENU" = "0" ]; then if [ "$VTOY_SECONDARY_BOOT_MENU" = "0" ]; then
set VTOY_SECONDARY_BOOT_MENU=1 set VTOY_SECONDARY_BOOT_MENU=1
else else
set VTOY_SECONDARY_BOOT_MENU=0 set VTOY_SECONDARY_BOOT_MENU=0
fi fi
} }
menuentry "[ $VTOY_WIN_UEFI_MAX_RES ] $VTLANG_WIN_UEFI_MAX_RES" --class=debug_temp_win_uefi_res --class=debug_temp_set --class=F5tool \
VTOY_RUN_SET3 {
if [ "$VTOY_WIN_UEFI_MAX_RES" = "0" ]; then
set VTOY_WIN_UEFI_MAX_RES=1
else
set VTOY_WIN_UEFI_MAX_RES=0
fi
}
menuentry "$VTLANG_RETURN_PREVIOUS" --class=vtoyret VTOY_RET { menuentry "$VTLANG_RETURN_PREVIOUS" --class=vtoyret VTOY_RET {
echo "Return ..." echo "Return ..."

View File

@@ -2449,7 +2449,7 @@ function mimg_common_menuentry {
############################################################# #############################################################
############################################################# #############################################################
set VENTOY_VERSION="1.1.10" set VENTOY_VERSION="1.1.11"
#ACPI not compatible with Window7/8, so disable by default #ACPI not compatible with Window7/8, so disable by default
set VTOY_PARAM_NO_ACPI=1 set VTOY_PARAM_NO_ACPI=1

View File

@@ -60,7 +60,7 @@ check_tool_work_ok() {
return return
fi fi
if mkexfatfs -V > /dev/null; then if mkexfatfs -V > /dev/null; then
vtdebug "mkexfatfs test ok ..." vtdebug "mkexfatfs test ok ..."
else else
vtdebug "mkexfatfs test fail ..." vtdebug "mkexfatfs test fail ..."
@@ -341,6 +341,7 @@ EOF
udevadm trigger --name-match=$DISK >/dev/null 2>&1 udevadm trigger --name-match=$DISK >/dev/null 2>&1
partprobe >/dev/null 2>&1 partprobe >/dev/null 2>&1
partx -u $DISK >/dev/null 2>&1
sleep 3 sleep 3
echo "Done" echo "Done"
@@ -458,6 +459,7 @@ format_ventoy_disk_gpt() {
udevadm trigger --name-match=$DISK >/dev/null 2>&1 udevadm trigger --name-match=$DISK >/dev/null 2>&1
partprobe >/dev/null 2>&1 partprobe >/dev/null 2>&1
partx -u $DISK >/dev/null 2>&1
sleep 3 sleep 3
echo "Done" echo "Done"

View File

@@ -7,12 +7,12 @@
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the * published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>. * along with this program; if not, see <http://www.gnu.org/licenses/>.
* *
@@ -70,7 +70,7 @@ static void vlog(const char *fmt, ...)
n += vsnprintf(log, sizeof(log) - 1, fmt, arg); n += vsnprintf(log, sizeof(log) - 1, fmt, arg);
va_end(arg); va_end(arg);
fwrite(log, 1, n, fp); fwrite(log, 1, n, fp);
fclose(fp); fclose(fp);
} }
} }
@@ -90,7 +90,7 @@ static int copy_file(const char *file1, const char *file2)
vlog("Failed to read file <%s>\n", file1); vlog("Failed to read file <%s>\n", file1);
goto end; goto end;
} }
fp2 = fopen(file2, "wb+"); fp2 = fopen(file2, "wb+");
if (!fp2) if (!fp2)
{ {
@@ -115,7 +115,7 @@ static int copy_file(const char *file1, const char *file2)
vlog("Failed to read <%s> %d %d\n", file1, n, size); vlog("Failed to read <%s> %d %d\n", file1, n, size);
goto end; goto end;
} }
n = fwrite(buf, 1, size, fp2); n = fwrite(buf, 1, size, fp2);
if (n != size) if (n != size)
{ {
@@ -167,7 +167,7 @@ static int vtoy_is_possible_blkdev(const char *name)
{ {
return 0; return 0;
} }
return 1; return 1;
} }
@@ -184,7 +184,7 @@ static ulonglong vtoy_get_disk_size_in_byte(const char *disk)
if (access(diskpath, F_OK) >= 0) if (access(diskpath, F_OK) >= 0)
{ {
vlog("get disk size from sysfs for %s\n", disk); vlog("get disk size from sysfs for %s\n", disk);
fd = open(diskpath, O_RDONLY | O_BINARY); fd = open(diskpath, O_RDONLY | O_BINARY);
if (fd >= 0) if (fd >= 0)
{ {
@@ -233,7 +233,7 @@ static int get_disk_num(void)
{ {
return 0; return 0;
} }
while ((p = readdir(dir)) != NULL) while ((p = readdir(dir)) != NULL)
{ {
n++; n++;
@@ -248,7 +248,7 @@ static int is_usb_disk(const char *diskname)
int rc; int rc;
char dstpath[1024] = { 0 }; char dstpath[1024] = { 0 };
char syspath[1024] = { 0 }; char syspath[1024] = { 0 };
snprintf(syspath, sizeof(syspath), "/sys/block/%s", diskname); snprintf(syspath, sizeof(syspath), "/sys/block/%s", diskname);
rc = readlink(syspath, dstpath, sizeof(dstpath) - 1); rc = readlink(syspath, dstpath, sizeof(dstpath) - 1);
if (rc > 0 && strstr(dstpath, "/usb")) if (rc > 0 && strstr(dstpath, "/usb"))
@@ -296,13 +296,13 @@ static int get_all_disk(void)
vlog("disk %s is filted by name\n", p->d_name); vlog("disk %s is filted by name\n", p->d_name);
continue; continue;
} }
cursize = vtoy_get_disk_size_in_byte(p->d_name); cursize = vtoy_get_disk_size_in_byte(p->d_name);
node = g_disk_list + g_disk_num; node = g_disk_list + g_disk_num;
g_disk_num++; g_disk_num++;
snprintf(node->name, sizeof(node->name), p->d_name); snprintf(node->name, sizeof(node->name), p->d_name);
node->size = cursize; node->size = cursize;
node->isUSB = is_usb_disk(p->d_name); node->isUSB = is_usb_disk(p->d_name);
@@ -338,7 +338,7 @@ static int get_all_disk(void)
node->size / 1024 / 1024 / 1024, node->size, node->isUSB); node->size / 1024 / 1024 / 1024, node->size, node->isUSB);
} }
vlog("============ DISK DUMP END ===========\n"); vlog("============ DISK DUMP END ===========\n");
return 0; return 0;
} }
@@ -410,7 +410,7 @@ static int expand_var(const char *var, char *value, int len)
{ {
uiDst = strtoul(var + 22, NULL, 10); uiDst = strtoul(var + 22, NULL, 10);
uiDst = uiDst * (1024ULL * 1024ULL * 1024ULL); uiDst = uiDst * (1024ULL * 1024ULL * 1024ULL);
for (i = 0; i < g_disk_num; i++) for (i = 0; i < g_disk_num; i++)
{ {
node = g_disk_list + i; node = g_disk_list + i;
@@ -418,7 +418,7 @@ static int expand_var(const char *var, char *value, int len)
{ {
continue; continue;
} }
if (node->size > uiDst) if (node->size > uiDst)
{ {
delta = node->size - uiDst; delta = node->size - uiDst;
@@ -427,7 +427,52 @@ static int expand_var(const char *var, char *value, int len)
{ {
delta = uiDst - node->size; delta = uiDst - node->size;
} }
if (delta < maxdelta)
{
index = i;
maxdelta = delta;
}
}
if (index >= 0)
{
vlog("%s=<%s>\n", var, g_disk_list[index].name);
snprintf(value, len, "%s", g_disk_list[index].name);
return 0;
}
else
{
vlog("[Error] %s not found\n", var);
}
}
else if (strncmp(var, "VT_LINUX_DISK_NONVTOY_CLOSEST_", 30) == 0)
{
uiDst = strtoul(var + 30, NULL, 10);
uiDst = uiDst * (1024ULL * 1024ULL * 1024ULL);
for (i = 0; i < g_disk_num; i++)
{
node = g_disk_list + i;
if (node->size == 0)
{
continue;
}
if (strcmp(node->name, g_vtoy_disk_name) == 0)
{
continue;
}
if (node->size > uiDst)
{
delta = node->size - uiDst;
}
else
{
delta = uiDst - node->size;
}
if (delta < maxdelta) if (delta < maxdelta)
{ {
index = i; index = i;
@@ -481,10 +526,10 @@ int vtoyexpand_main(int argc, char **argv)
{ {
g_vtoy_disk_name += 5; g_vtoy_disk_name += 5;
} }
vlog("<%s> <%s> <%s>\n", argv[1], argv[2], g_vtoy_disk_name); vlog("<%s> <%s> <%s>\n", argv[1], argv[2], g_vtoy_disk_name);
get_all_disk(); get_all_disk();
fp = fopen(argv[1], "r"); fp = fopen(argv[1], "r");
if (!fp) if (!fp)
{ {
@@ -502,7 +547,7 @@ int vtoyexpand_main(int argc, char **argv)
memset(line, 0, sizeof(line)); memset(line, 0, sizeof(line));
memset(value, 0, sizeof(value)); memset(value, 0, sizeof(value));
while (fgets(line, sizeof(line), fp)) while (fgets(line, sizeof(line), fp))
{ {
start = strstr(line, "$$VT_"); start = strstr(line, "$$VT_");
@@ -519,7 +564,7 @@ int vtoyexpand_main(int argc, char **argv)
*end = 0; *end = 0;
expand_var(start + 2, value, sizeof(value)); expand_var(start + 2, value, sizeof(value));
fprintf(fout, "%s", value); fprintf(fout, "%s", value);
fprintf(fout, "%s", end + 2); fprintf(fout, "%s", end + 2);
memset(value, 0, sizeof(value)); memset(value, 0, sizeof(value));
@@ -531,7 +576,7 @@ int vtoyexpand_main(int argc, char **argv)
line[0] = line[4095] = 0; line[0] = line[4095] = 0;
} }
fclose(fp); fclose(fp);
fclose(fout); fclose(fout);
@@ -540,7 +585,7 @@ int vtoyexpand_main(int argc, char **argv)
vlog("Copy file <%s> --> <%s>\n", TMP_FILE, argv[1]); vlog("Copy file <%s> --> <%s>\n", TMP_FILE, argv[1]);
copy_file(TMP_FILE, argv[1]); copy_file(TMP_FILE, argv[1]);
return 0; return 0;
} }