From c3718d600154199f8d20f649226e20f3f663e048 Mon Sep 17 00:00:00 2001 From: longpanda Date: Tue, 22 Feb 2022 22:23:33 +0800 Subject: [PATCH] Auto use memdisk mode for Memtest86+ iso file. --- .../grub-2.04/grub-core/ventoy/ventoy_cmd.c | 85 +++++++++++++++++++ INSTALL/grub/grub.cfg | 20 ++++- 2 files changed, 103 insertions(+), 2 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 08187a81..1586a5db 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 @@ -137,6 +137,10 @@ static grub_uint64_t g_enumerate_start_time_ms; static grub_uint64_t g_enumerate_finish_time_ms; int g_vtoy_file_flt[VTOY_FILE_FLT_BUTT] = {0}; +static char g_iso_vd_id_publisher[130]; +static char g_iso_vd_id_prepare[130]; +static char g_iso_vd_id_application[130]; + static int g_pager_flag = 0; static char g_old_pager[32]; @@ -5469,6 +5473,84 @@ out: return ret; } +static grub_err_t ventoy_iso_vd_id_clear(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + g_iso_vd_id_publisher[0] = 0; + g_iso_vd_id_prepare[0] = 0; + g_iso_vd_id_application[0] = 0; + + return 0; +} + +static grub_err_t ventoy_cmd_iso_vd_id_parse(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int ret = 1; + int offset = 318; + grub_file_t file = NULL; + + (void)ctxt; + (void)argc; + + file = grub_file_open(args[0], VENTOY_FILE_TYPE); + if (!file) + { + grub_printf("Failed to open %s\n", args[0]); + goto out; + } + + grub_file_seek(file, 16 * 2048 + offset); + grub_file_read(file, g_iso_vd_id_publisher, 128); + + offset += 128; + grub_file_seek(file, 16 * 2048 + offset); + grub_file_read(file, g_iso_vd_id_prepare, 128); + + offset += 128; + grub_file_seek(file, 16 * 2048 + offset); + grub_file_read(file, g_iso_vd_id_application, 128); + +out: + + check_free(file, grub_file_close); + grub_errno = GRUB_ERR_NONE; + return ret; +} + +static grub_err_t ventoy_cmd_iso_vd_id_begin(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int ret = 1; + char *id = g_iso_vd_id_publisher; + + (void)ctxt; + (void)argc; + + if (args[0][0] == '1') + { + id = g_iso_vd_id_prepare; + } + else if (args[0][0] == '2') + { + id = g_iso_vd_id_application; + } + + if (args[1][0] == '0' && grub_strncasecmp(id, args[2], grub_strlen(args[2])) == 0) + { + ret = 0; + } + + if (args[1][0] == '1' && grub_strncmp(id, args[2], grub_strlen(args[2])) == 0) + { + ret = 0; + } + + grub_errno = GRUB_ERR_NONE; + return ret; +} + int ventoy_env_init(void) { char buf[64]; @@ -5664,6 +5746,9 @@ static cmd_para ventoy_cmds[] = { "vt_get_vlnk_dst", grub_cmd_get_vlnk_dst, 0, NULL, "", "", NULL }, { "vt_set_fake_vlnk", ventoy_cmd_set_fake_vlnk, 0, NULL, "", "", NULL }, { "vt_reset_fake_vlnk", ventoy_cmd_reset_fake_vlnk, 0, NULL, "", "", NULL }, + { "vt_iso_vd_id_parse", ventoy_cmd_iso_vd_id_parse, 0, NULL, "", "", NULL }, + { "vt_iso_vd_id_clear", ventoy_iso_vd_id_clear, 0, NULL, "", "", NULL }, + { "vt_iso_vd_id_begin", ventoy_cmd_iso_vd_id_begin, 0, NULL, "", "", NULL }, }; int ventoy_register_all_cmd(void) diff --git a/INSTALL/grub/grub.cfg b/INSTALL/grub/grub.cfg index a59b82d0..3cf47789 100644 --- a/INSTALL/grub/grub.cfg +++ b/INSTALL/grub/grub.cfg @@ -1303,14 +1303,30 @@ function iso_common_menuentry { set vtcompat=1 fi + + # 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 + set vtMemDiskBoot=1 + else + if [ "$grub_platform" = "pc" ]; then + if vt_iso_vd_id_begin 1 0 "Memtest86+"; then + set vtMemDiskBoot=1 + fi + fi + fi + vt_iso_vd_id_clear + + if [ "$grub_platform" = "pc" ]; then - if vt_check_mode 0; then + if [ -n "$vtMemDiskBoot" ]; then legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path" else legacy_iso_menu_func $vtoy_iso_part "$vt_chosen_path" fi else - if vt_check_mode 0; then + if [ -n "$vtMemDiskBoot" ]; then uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path" else uefi_iso_menu_func $vtoy_iso_part "$vt_chosen_path"