From 96fdd594f098200c5bb3561bb446047f7bc51240 Mon Sep 17 00:00:00 2001 From: longpanda Date: Tue, 15 Feb 2022 14:42:46 +0800 Subject: [PATCH] Support to F2 browse Ventoy partition self. --- .../grub-core/ventoy/ventoy_browser.c | 48 ++++++++++++++++++- .../grub-2.04/grub-core/ventoy/ventoy_cmd.c | 7 ++- .../grub-2.04/grub-core/ventoy/ventoy_def.h | 3 ++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_browser.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_browser.c index 1395541e..01c7248e 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_browser.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_browser.c @@ -149,7 +149,7 @@ static int ventoy_browser_iterate_partition(struct grub_disk *disk, const grub_p (void)data; - if (partition->number < 2 && g_vtoy_dev && grub_strcmp(disk->name, g_vtoy_dev) == 0) + if (partition->number == 1 && g_vtoy_dev && grub_strcmp(disk->name, g_vtoy_dev) == 0) { return 0; } @@ -423,6 +423,43 @@ static int ventoy_browser_iterate_dir(const char *filename, const struct grub_di return 0; } +static grub_err_t ventoy_browser_iso_part(void) +{ + char cfgfile[64]; + char *buffer = NULL; + int pos = 0; + int buflen = 0; + int cfglen = 0; + + cfglen = g_tree_script_pos - g_tree_script_pre; + buflen = cfglen + 512; + buffer = grub_malloc(buflen); + if (!buffer) + { + return 1; + } + + if (g_tree_view_menu_style == 0) + { + pos = grub_snprintf(buffer, buflen, "menuentry \"%-10s [../]\" --class=\"vtoyret\" VTOY_RET {\n " + " echo 'return ...' \n}\n", "<--"); + } + else + { + pos = grub_snprintf(buffer, buflen, "menuentry \"[../]\" --class=\"vtoyret\" VTOY_RET {\n " + " echo 'return ...' \n}\n"); + } + + grub_memcpy(buffer + pos, g_tree_script_buf + g_tree_script_pre, cfglen); + pos += cfglen; + + grub_snprintf(cfgfile, sizeof(cfgfile), "configfile mem:0x%lx:size:%d", (ulong)buffer, pos); + grub_script_execute_sourcecode(cfgfile); + + grub_free(buffer); + VENTOY_CMD_RETURN(GRUB_ERR_NONE); +} + grub_err_t ventoy_cmd_browser_dir(grub_extcmd_context_t ctxt, int argc, char **args) { int i; @@ -435,6 +472,15 @@ grub_err_t ventoy_cmd_browser_dir(grub_extcmd_context_t ctxt, int argc, char **a (void)ctxt; (void)argc; + if (args[2][0] == '/' && args[2][1] == 0) + { + grub_snprintf(cfgfile, sizeof(cfgfile), "(%s)", args[0]); + if (grub_strcmp(cfgfile, g_iso_path) == 0) + { + return ventoy_browser_iso_part(); + } + } + if (!ventoy_browser_mbuf_alloc(&mbuf)) { return 1; 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 f00cfc62..08187a81 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 @@ -117,8 +117,9 @@ ventoy_gpt_info *g_ventoy_part_info = NULL; grub_uint64_t g_ventoy_disk_size = 0; grub_uint64_t g_ventoy_disk_part_size[2]; -static char *g_tree_script_buf = NULL; -static int g_tree_script_pos = 0; +char *g_tree_script_buf = NULL; +int g_tree_script_pos = 0; +int g_tree_script_pre = 0; static char *g_list_script_buf = NULL; static int g_list_script_pos = 0; @@ -2294,6 +2295,8 @@ static int ventoy_dynamic_tree_menu(img_iterator_node *node) "}\n", "return"); } } + + g_tree_script_pre = g_tree_script_pos; } else { diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h index 5dde8ddf..3e71fe39 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h @@ -1187,6 +1187,9 @@ typedef struct browser_node struct browser_node *next; }browser_node; +extern char *g_tree_script_buf; +extern int g_tree_script_pos; +extern int g_tree_script_pre; extern int g_tree_view_menu_style; extern int g_sort_case_sensitive; extern int g_wimboot_enable;