]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Show a warning message if the path of /ventoy/ventoy.json case mismatch.
authorlongpanda <admin@ventoy.net>
Thu, 19 Aug 2021 03:40:23 +0000 (11:40 +0800)
committerlongpanda <admin@ventoy.net>
Thu, 19 Aug 2021 03:40:23 +0000 (11:40 +0800)
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
INSTALL/grub/grub.cfg

index 04582359b542654cf106d3ed2e5dc5634b48d9f0..cdf5333aec2c34a34ff380e5e16ffc60d0c7c35b 100644 (file)
@@ -145,6 +145,8 @@ const char *g_menu_prefix[img_type_max] =
 static int g_vtoy_load_prompt = 0;
 static char g_vtoy_prompt_msg[64];
 
 static int g_vtoy_load_prompt = 0;
 static char g_vtoy_prompt_msg[64];
 
+static char g_json_case_mis_path[32];
+
 static int ventoy_get_fs_type(const char *fs)
 {
     if (NULL == fs)
 static int ventoy_get_fs_type(const char *fs)
 {
     if (NULL == fs)
@@ -4695,6 +4697,101 @@ static grub_err_t ventoy_cmd_pop_pager(grub_extcmd_context_t ctxt, int argc, cha
     VENTOY_CMD_RETURN(GRUB_ERR_NONE);
 }
 
     VENTOY_CMD_RETURN(GRUB_ERR_NONE);
 }
 
+static int ventoy_chk_case_file(const char *filename, const struct grub_dirhook_info *info, void *data)
+{
+    if (g_json_case_mis_path[0])
+    {
+        return 1;
+    }
+
+    if (0 == info->dir && grub_strncasecmp(filename, "ventoy.json", 11) == 0)
+    {
+        grub_snprintf(g_json_case_mis_path, 32, "%s/%s", (char *)data, filename);
+        return 1;
+    }
+    return 0;
+}
+
+static int ventoy_chk_case_dir(const char *filename, const struct grub_dirhook_info *info, void *data)
+{
+    char path[16];
+    chk_case_fs_dir *fs_dir = (chk_case_fs_dir *)data;
+
+    if (g_json_case_mis_path[0])
+    {
+        return 1;
+    }
+
+    if (info->dir && (filename[0] == 'v' || filename[0] == 'V'))
+    {
+        if (grub_strncasecmp(filename, "ventoy", 6) == 0)
+        {
+            grub_snprintf(path, sizeof(path), "/%s", filename);
+            fs_dir->fs->fs_dir(fs_dir->dev, path, ventoy_chk_case_file, path);
+            if (g_json_case_mis_path[0])
+            {
+                return 1;
+            }
+        }
+    }
+    
+    return 0;
+}
+
+static grub_err_t ventoy_cmd_chk_json_pathcase(grub_extcmd_context_t ctxt, int argc, char **args)
+{
+    int fstype = 0;
+    char *device_name = NULL;
+    grub_device_t dev = NULL;
+    grub_fs_t fs = NULL;
+    chk_case_fs_dir fs_dir;
+    
+    (void)ctxt;
+    (void)argc;
+    (void)args;
+
+    device_name = grub_file_get_device_name(args[0]);
+    if (!device_name)
+    {
+        goto out;
+    }
+
+    dev = grub_device_open(device_name);
+    if (!dev)
+    {
+        goto out;
+    }
+
+    fs = grub_fs_probe(dev);
+    if (!fs)
+    {
+        goto out;
+    }
+
+    fstype = ventoy_get_fs_type(fs->name);
+    if (fstype == ventoy_fs_fat || fstype == ventoy_fs_exfat || fstype >= ventoy_fs_max)
+    {
+        goto out;
+    }
+
+    g_json_case_mis_path[0] = 0;
+    fs_dir.dev = dev;
+    fs_dir.fs = fs;
+    fs->fs_dir(dev, "/", ventoy_chk_case_dir, &fs_dir);
+
+    if (g_json_case_mis_path[0])
+    {
+        grub_env_set("VTOY_PLUGIN_PATH_CASE_MISMATCH", g_json_case_mis_path);
+    }
+
+out:
+
+    grub_check_free(device_name);
+    check_free(dev, grub_device_close);
+
+    VENTOY_CMD_RETURN(GRUB_ERR_NONE);
+}
+
 int ventoy_env_init(void)
 {
     char buf[64];
 int ventoy_env_init(void)
 {
     char buf[64];
@@ -4872,6 +4969,7 @@ static cmd_para ventoy_cmds[] =
     { "vt_search_replace_initrd", ventoy_cmd_search_replace_initrd, 0, NULL, "", "", NULL },
     { "vt_push_pager", ventoy_cmd_push_pager, 0, NULL, "", "", NULL },
     { "vt_pop_pager", ventoy_cmd_pop_pager, 0, NULL, "", "", NULL },
     { "vt_search_replace_initrd", ventoy_cmd_search_replace_initrd, 0, NULL, "", "", NULL },
     { "vt_push_pager", ventoy_cmd_push_pager, 0, NULL, "", "", NULL },
     { "vt_pop_pager", ventoy_cmd_pop_pager, 0, NULL, "", "", NULL },
+    { "vt_check_json_path_case", ventoy_cmd_chk_json_pathcase, 0, NULL, "", "", NULL },
 };
 
 int ventoy_register_all_cmd(void)
 };
 
 int ventoy_register_all_cmd(void)
index f841aba6644c5d21acf579cd49ffca6efd624e66..3185a7a5273287f04c35236ec328f2c80aad645a 100644 (file)
@@ -547,6 +547,12 @@ typedef struct replace_fs_dir
     int filecnt;
 }replace_fs_dir;
 
     int filecnt;
 }replace_fs_dir;
 
+typedef struct chk_case_fs_dir
+{
+    grub_device_t dev;
+    grub_fs_t fs;
+}chk_case_fs_dir;
+
 int ventoy_strcmp(const char *pattern, const char *str);
 int ventoy_strncmp (const char *pattern, const char *str, grub_size_t n);
 void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param);
 int ventoy_strcmp(const char *pattern, const char *str);
 int ventoy_strncmp (const char *pattern, const char *str, grub_size_t n);
 void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param);
index 66537063f2a84930537dccc0c894c00c52eb6815..2b3be9551795ce104723bac0efae08a8b09c60e6 100644 (file)
@@ -1940,9 +1940,11 @@ vt_load_part_table $vtoydev
 
 #Load Plugin
 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
 
 #Load Plugin
 if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
-   clear
-   vt_load_plugin $vtoy_iso_part
-   clear
+    clear
+    vt_load_plugin $vtoy_iso_part
+    clear
+else
+    vt_check_json_path_case $vtoy_iso_part
 fi
 
 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
 fi
 
 if [ -n "$VTOY_MENU_TIMEOUT" ]; then
@@ -2009,6 +2011,15 @@ if [ -n "$VTOY_DEFAULT_KBD_LAYOUT" ]; then
     set_keyboard_layout "$VTOY_DEFAULT_KBD_LAYOUT"
 fi
 
     set_keyboard_layout "$VTOY_DEFAULT_KBD_LAYOUT"
 fi
 
+if [ -n "$VTOY_PLUGIN_PATH_CASE_MISMATCH" ]; then
+    clear
+    echo "$VTOY_PLUGIN_PATH_CASE_MISMATCH"
+    echo -e "\n\nPath case does not match! ventoy directory and ventoy.json MUST be all lowercase!"
+    echo -e "\n路径大小写不匹配!ventoy 目录和 ventoy.json 文件的名字必须是全部小写,请修正!"
+    echo -e "\n\npress ENTER to continue (请按回车键继续) ..."
+    read vtInputKey
+fi
+
 if [ -n "$VTOY_PLUGIN_SYNTAX_ERROR" ]; then
     clear
     echo -e "\n Syntax error detected in ventoy.json, please check! \n"
 if [ -n "$VTOY_PLUGIN_SYNTAX_ERROR" ]; then
     clear
     echo -e "\n Syntax error detected in ventoy.json, please check! \n"