Auto use memdisk mode for Memtest86+ iso file.

This commit is contained in:
longpanda 2022-02-22 22:23:33 +08:00
parent d0744513a6
commit c3718d6001
2 changed files with 103 additions and 2 deletions

View File

@ -137,6 +137,10 @@ static grub_uint64_t g_enumerate_start_time_ms;
static grub_uint64_t g_enumerate_finish_time_ms; static grub_uint64_t g_enumerate_finish_time_ms;
int g_vtoy_file_flt[VTOY_FILE_FLT_BUTT] = {0}; 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 int g_pager_flag = 0;
static char g_old_pager[32]; static char g_old_pager[32];
@ -5469,6 +5473,84 @@ out:
return ret; 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) int ventoy_env_init(void)
{ {
char buf[64]; 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_get_vlnk_dst", grub_cmd_get_vlnk_dst, 0, NULL, "", "", NULL },
{ "vt_set_fake_vlnk", ventoy_cmd_set_fake_vlnk, 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_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) int ventoy_register_all_cmd(void)

View File

@ -1303,14 +1303,30 @@ function iso_common_menuentry {
set vtcompat=1 set vtcompat=1
fi 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 [ "$grub_platform" = "pc" ]; then
if vt_check_mode 0; then if [ -n "$vtMemDiskBoot" ]; then
legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path" legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
else else
legacy_iso_menu_func $vtoy_iso_part "$vt_chosen_path" legacy_iso_menu_func $vtoy_iso_part "$vt_chosen_path"
fi fi
else else
if vt_check_mode 0; then if [ -n "$vtMemDiskBoot" ]; then
uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path" uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
else else
uefi_iso_menu_func $vtoy_iso_part "$vt_chosen_path" uefi_iso_menu_func $vtoy_iso_part "$vt_chosen_path"