From 1c0b4ee90324bb38369d4d4ad59d793bbeff8fc7 Mon Sep 17 00:00:00 2001 From: longpanda Date: Wed, 8 Jun 2022 10:15:56 +0800 Subject: [PATCH] Auto use memdisk/grub2/wimboot mode if the ISO file name has _VTMEMDISK/_VTGRUB2/_VTWIMBOOT suffix. (e.g. ubuntu-22.04-desktop-amd64_VTGRUB2.iso) --- .../grub-2.04/grub-core/ventoy/ventoy_cmd.c | 78 ++++++++++++++++++- INSTALL/grub/grub.cfg | 30 +++---- 2 files changed, 89 insertions(+), 19 deletions(-) diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c index 51d11c99..facd0ede 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c @@ -3715,20 +3715,70 @@ static grub_err_t ventoy_cmd_dump_persistence(grub_extcmd_context_t ctxt, int ar return 0; } +static int ventoy_check_mode_by_name(char *filename, const char *suffix) +{ + int i; + int len1; + int len2; + + len1 = (int)grub_strlen(filename); + len2 = (int)grub_strlen(suffix); + + if (len1 <= len2) + { + return 0; + } + + for (i = len1 - 1; i >= 0; i--) + { + if (filename[i] == '.') + { + break; + } + } + + if (i < len2 + 1) + { + return 0; + } + + if (filename[i - len2 - 1] != '_') + { + return 0; + } + + if (grub_strncasecmp(filename + (i - len2), suffix, len2) == 0) + { + return 1; + } + + return 0; +} + static grub_err_t ventoy_cmd_check_mode(grub_extcmd_context_t ctxt, int argc, char **args) { (void)ctxt; (void)argc; (void)args; - if (argc != 1) + if (argc != 1 && argc != 2) { return 1; } if (args[0][0] == '0') { - return g_ventoy_memdisk_mode ? 0 : 1; + if (g_ventoy_memdisk_mode) + { + return 0; + } + + if (argc == 2 && ventoy_check_mode_by_name(args[1], "vtmemdisk")) + { + return 0; + } + + return 1; } else if (args[0][0] == '1') { @@ -3740,11 +3790,31 @@ static grub_err_t ventoy_cmd_check_mode(grub_extcmd_context_t ctxt, int argc, ch } else if (args[0][0] == '3') { - return g_ventoy_grub2_mode ? 0 : 1; + if (g_ventoy_grub2_mode) + { + return 0; + } + + if (argc == 2 && ventoy_check_mode_by_name(args[1], "vtgrub2")) + { + return 0; + } + + return 1; } else if (args[0][0] == '4') { - return g_ventoy_wimboot_mode ? 0 : 1; + if (g_ventoy_wimboot_mode) + { + return 0; + } + + if (argc == 2 && ventoy_check_mode_by_name(args[1], "vtwimboot")) + { + return 0; + } + + return 1; } return 1; diff --git a/INSTALL/grub/grub.cfg b/INSTALL/grub/grub.cfg index 2d2498b0..3e7d5b78 100644 --- a/INSTALL/grub/grub.cfg +++ b/INSTALL/grub/grub.cfg @@ -621,7 +621,7 @@ function uefi_windows_menu_func { vt_windows_chain_data "${1}${chosen_path}" ventoy_debug_pause - if vt_check_mode 4; then + if vt_check_mode 4 "$vt_chosen_name"; then vtoy_windows_wimboot_func fi @@ -779,7 +779,7 @@ function uefi_linux_menu_func { ventoy_cli_console unset vtGrub2Mode - if vt_check_mode 3; then + if vt_check_mode 3 "$vt_chosen_name"; then set vtGrub2Mode=1 elif vt_str_begin "$vt_volume_id" "KRD"; then if [ -f (loop)/boot/grub/grub.cfg.sig ]; then @@ -867,7 +867,7 @@ function uefi_iso_menu_func { if [ -n "$vtisouefi" ]; then set LoadIsoEfiDriver=on unset vtisouefi - elif vt_check_mode 2; then + elif vt_check_mode 2 "$vt_chosen_name"; then set LoadIsoEfiDriver=on else unset LoadIsoEfiDriver @@ -904,7 +904,7 @@ function uefi_iso_menu_func { if [ -n "$vtcompat" ]; then set ventoy_compatible=YES unset vtcompat - elif vt_check_mode 1; then + elif vt_check_mode 1 "$vt_chosen_name"; then set ventoy_compatible=YES else vt_check_compatible (loop) @@ -1050,7 +1050,7 @@ function legacy_windows_menu_func { vt_windows_chain_data "${1}${chosen_path}" ventoy_debug_pause - if vt_check_mode 4; then + if vt_check_mode 4 "$vt_chosen_name"; then vtoy_windows_wimboot_func fi @@ -1133,7 +1133,7 @@ function legacy_linux_menu_func { ventoy_debug_pause if [ -n "$vtoy_chain_mem_addr" ]; then - if vt_check_mode 3; then + if vt_check_mode 3 "$vt_chosen_name"; then ventoy_acpi_param ${vtoy_chain_mem_addr} 2048 ventoy_cli_console @@ -1212,7 +1212,7 @@ function legacy_iso_menu_func { if [ -n "$vtcompat" ]; then set ventoy_compatible=YES unset vtcompat - elif vt_check_mode 1; then + elif vt_check_mode 1 "$vt_chosen_name"; then set ventoy_compatible=YES else vt_check_compatible (loop) @@ -1343,7 +1343,7 @@ function iso_common_menuentry { # auto memdisk mode for some special ISO files vt_iso_vd_id_parse "${vtoy_iso_part}${vt_chosen_path}" unset vtMemDiskBoot - if vt_check_mode 0; then + if vt_check_mode 0 "$vt_chosen_name"; then set vtMemDiskBoot=1 else if [ "$grub_platform" = "pc" ]; then @@ -1380,7 +1380,7 @@ function iso_common_menuentry { } function miso_common_menuentry { - vt_chosen_img_path vt_chosen_path vt_chosen_size + vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name if vt_check_password "${vt_chosen_path}"; then return @@ -1414,7 +1414,7 @@ function iso_unsupport_menuentry { } function wim_common_menuentry { - vt_chosen_img_path vt_chosen_path vt_chosen_size + vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name if vt_check_password "${vt_chosen_path}"; then return @@ -1453,7 +1453,7 @@ function wim_unsupport_menuentry { } function efi_common_menuentry { - vt_chosen_img_path vt_chosen_path vt_chosen_size + vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name if vt_check_password "${vt_chosen_path}"; then return @@ -1523,7 +1523,7 @@ function vhdboot_common_func { } function vhd_common_menuentry { - vt_chosen_img_path vt_chosen_path vt_chosen_size + vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name if vt_check_password "${vt_chosen_path}"; then return @@ -1620,7 +1620,7 @@ function vtoyboot_common_func { } function vtoy_common_menuentry { - vt_chosen_img_path vt_chosen_path vt_chosen_size + vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name if vt_check_password "${vt_chosen_path}"; then return @@ -2030,7 +2030,7 @@ function img_common_menuentry { set ventoy_busybox_ver=32 unset LoadIsoEfiDriver - vt_chosen_img_path vt_chosen_path vt_chosen_size + vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name if vt_check_password "${vt_chosen_path}"; then return @@ -2041,7 +2041,7 @@ function img_common_menuentry { fi if [ "$grub_platform" = "pc" ]; then - if vt_check_mode 0; then + if vt_check_mode 0 "$vt_chosen_name"; then legacy_img_memdisk $vtoy_iso_part "$vt_chosen_path" return fi