]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Auto use memdisk mode for Memtest86+ iso file.
authorlongpanda <admin@ventoy.net>
Tue, 22 Feb 2022 14:23:33 +0000 (22:23 +0800)
committerlongpanda <admin@ventoy.net>
Tue, 22 Feb 2022 14:23:33 +0000 (22:23 +0800)
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c
INSTALL/grub/grub.cfg

index 08187a81b1f7834e02a39e57f4c2d7b1288022d1..1586a5dbdba75c2dc9ceaa4efef6800048d545c5 100644 (file)
@@ -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)
index a59b82d02b47ec739a1e7f85c11f7ce30de9a11b..3cf4778987663bc055f57524c39bca1c7e6e276b 100644 (file)
@@ -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"