From b1d52370413fe35672ba7aa6f8390de0d7eb1c50 Mon Sep 17 00:00:00 2001 From: longpanda Date: Wed, 3 Feb 2021 21:07:17 +0800 Subject: [PATCH] 1.0.34 release --- .../grub-2.04/grub-core/ventoy/ventoy.c | 71 +++++- .../grub-2.04/grub-core/ventoy/ventoy_def.h | 16 ++ .../grub-core/ventoy/ventoy_plugin.c | 210 ++++++++++++++++++ GRUB2/MOD_SRC/grub-2.04/install.sh | 4 +- INSTALL/grub/grub.cfg | 44 +++- 5 files changed, 339 insertions(+), 6 deletions(-) diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c index 75ec17d1..ee5922a1 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c @@ -1160,7 +1160,7 @@ static int ventoy_check_ignore_flag(const char *filename, const struct grub_dirh return 0; } -static int ventoy_colect_img_files(const char *filename, const struct grub_dirhook_info *info, void *data) +static int ventoy_collect_img_files(const char *filename, const struct grub_dirhook_info *info, void *data) { //int i = 0; int type = 0; @@ -1281,6 +1281,15 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho { type = img_type_vtoy; } + else if (len >= 9 && 0 == grub_strcasecmp(filename + len - 5, ".vcfg")) + { + if (filename[len - 9] == '.' || (len >= 10 && filename[len - 10] == '.')) + { + grub_snprintf(g_img_swap_tmp_buf, sizeof(g_img_swap_tmp_buf), "%s%s", node->dir, filename); + ventoy_plugin_add_custom_boot(g_img_swap_tmp_buf); + } + return 0; + } else { return 0; @@ -2027,7 +2036,7 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char for (node = &g_img_iterator_head; node; node = node->next) { - fs->fs_dir(dev, node->dir, ventoy_colect_img_files, node); + fs->fs_dir(dev, node->dir, ventoy_collect_img_files, node); } strdata = ventoy_get_env("VTOY_TREE_VIEW_MENU_STYLE"); @@ -3637,6 +3646,31 @@ static grub_err_t ventoy_cmd_load_part_table(grub_extcmd_context_t ctxt, int arg return 0; } +static grub_err_t ventoy_cmd_check_custom_boot(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int ret = 1; + const char *vcfg = NULL; + + (void)argc; + (void)ctxt; + + vcfg = ventoy_plugin_get_custom_boot(args[0]); + if (vcfg) + { + debug("custom boot <%s>:<%s>\n", args[0], vcfg); + grub_env_set(args[1], vcfg); + ret = 0; + } + else + { + debug("custom boot <%s>:\n", args[0]); + } + + grub_errno = 0; + return ret; +} + + static grub_err_t ventoy_cmd_part_exist(grub_extcmd_context_t ctxt, int argc, char **args) { int id; @@ -3829,6 +3863,36 @@ static grub_err_t ventoy_cmd_basename(grub_extcmd_context_t ctxt, int argc, char return 0; } +static grub_err_t ventoy_cmd_basefile(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + int len; + const char *buf; + + (void)ctxt; + + if (argc != 2) + { + debug("ventoy_cmd_basefile, invalid param num %d\n", argc); + return 1; + } + + buf = args[0]; + len = (int)grub_strlen(buf); + for (i = len; i > 0; i--) + { + if (buf[i - 1] == '/') + { + grub_env_set(args[1], buf + i); + return 0; + } + } + + grub_env_set(args[1], buf); + + return 0; +} + static grub_err_t ventoy_cmd_enum_video_mode(grub_extcmd_context_t ctxt, int argc, char **args) { struct grub_video_mode_info info; @@ -4096,6 +4160,8 @@ static cmd_para ventoy_cmds[] = { "vt_patch_vhdboot", ventoy_cmd_patch_vhdboot, 0, NULL, "", "", NULL }, { "vt_raw_chain_data", ventoy_cmd_raw_chain_data, 0, NULL, "", "", NULL }, { "vt_get_vtoy_type", ventoy_cmd_get_vtoy_type, 0, NULL, "", "", NULL }, + { "vt_check_custom_boot", ventoy_cmd_check_custom_boot, 0, NULL, "", "", NULL }, + { "vt_dump_custom_boot", ventoy_cmd_dump_custom_boot, 0, NULL, "", "", NULL }, { "vt_skip_svd", ventoy_cmd_skip_svd, 0, NULL, "", "", NULL }, { "vt_cpio_busybox64", ventoy_cmd_cpio_busybox_64, 0, NULL, "", "", NULL }, @@ -4110,6 +4176,7 @@ static cmd_para ventoy_cmds[] = { "vt_get_fs_label", ventoy_cmd_get_fs_label, 0, NULL, "", "", NULL }, { "vt_fs_enum_1st_file", ventoy_cmd_fs_enum_1st_file, 0, NULL, "", "", NULL }, { "vt_file_basename", ventoy_cmd_basename, 0, NULL, "", "", NULL }, + { "vt_file_basefile", ventoy_cmd_basefile, 0, NULL, "", "", NULL }, { "vt_enum_video_mode", ventoy_cmd_enum_video_mode, 0, NULL, "", "", NULL }, { "vt_get_video_mode", ventoy_cmd_get_video_mode, 0, NULL, "", "", NULL }, { "vt_update_cur_video_mode", vt_cmd_update_cur_video_mode, 0, NULL, "", "", NULL }, 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 e228574d..980dc2ee 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 @@ -801,6 +801,19 @@ typedef struct menu_class struct menu_class *next; }menu_class; +#define vtoy_custom_boot_image_file 0 +#define vtoy_custom_boot_directory 1 + +typedef struct custom_boot +{ + int type; + int pathlen; + char path[256]; + char cfg[256]; + + struct custom_boot *next; +}custom_boot; + #define vtoy_max_replace_file_size (2 * 1024 * 1024) typedef struct conf_replace { @@ -945,6 +958,9 @@ grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char * int ventoy_check_password(const vtoy_password *pwd, int retry); int ventoy_gzip_compress(void *mem_in, int mem_in_len, void *mem_out, int mem_out_len); grub_uint64_t ventoy_get_part1_size(ventoy_gpt_info *gpt); +int ventoy_plugin_add_custom_boot(const char *vcfgpath); +const char * ventoy_plugin_get_custom_boot(const char *isopath); +grub_err_t ventoy_cmd_dump_custom_boot(grub_extcmd_context_t ctxt, int argc, char **args); #endif /* __VENTOY_DEF_H__ */ diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c index 1843399b..c50b1cad 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c @@ -49,6 +49,7 @@ static menu_password *g_pwd_head = NULL; static persistence_config *g_persistence_head = NULL; static menu_alias *g_menu_alias_head = NULL; static menu_class *g_menu_class_head = NULL; +static custom_boot *g_custom_boot_head = NULL; static injection_config *g_injection_head = NULL; static auto_memdisk *g_auto_memdisk_head = NULL; static image_list *g_image_list_head = NULL; @@ -1382,6 +1383,124 @@ static int ventoy_plugin_menuclass_check(VTOY_JSON *json, const char *isodisk) return 0; } +static int ventoy_plugin_custom_boot_entry(VTOY_JSON *json, const char *isodisk) +{ + int type; + int len; + const char *key = NULL; + const char *cfg = NULL; + VTOY_JSON *pNode = NULL; + custom_boot *tail = NULL; + custom_boot *node = NULL; + custom_boot *next = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + debug("Not array %d\n", json->enDataType); + return 0; + } + + if (g_custom_boot_head) + { + for (node = g_custom_boot_head; node; node = next) + { + next = node->next; + grub_free(node); + } + + g_custom_boot_head = NULL; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + type = vtoy_custom_boot_image_file; + key = vtoy_json_get_string_ex(pNode->pstChild, "file"); + if (!key) + { + key = vtoy_json_get_string_ex(pNode->pstChild, "dir"); + type = vtoy_custom_boot_directory; + } + + cfg = vtoy_json_get_string_ex(pNode->pstChild, "vcfg"); + if (key && cfg) + { + node = grub_zalloc(sizeof(custom_boot)); + if (node) + { + node->type = type; + node->pathlen = grub_snprintf(node->path, sizeof(node->path), "%s", key); + len = (int)grub_snprintf(node->cfg, sizeof(node->cfg), "%s", cfg); + + if (len >= 5 && grub_strncmp(node->cfg + len - 5, ".vcfg", 5) == 0) + { + if (g_custom_boot_head) + { + tail->next = node; + } + else + { + g_custom_boot_head = node; + } + tail = node; + } + else + { + grub_free(node); + } + } + } + } + + return 0; +} + +static int ventoy_plugin_custom_boot_check(VTOY_JSON *json, const char *isodisk) +{ + int type; + int len; + const char *key = NULL; + const char *cfg = NULL; + VTOY_JSON *pNode = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + grub_printf("Not array %d\n", json->enDataType); + return 1; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + type = vtoy_custom_boot_image_file; + key = vtoy_json_get_string_ex(pNode->pstChild, "file"); + if (!key) + { + key = vtoy_json_get_string_ex(pNode->pstChild, "dir"); + type = vtoy_custom_boot_directory; + } + + cfg = vtoy_json_get_string_ex(pNode->pstChild, "vcfg"); + len = (int)grub_strlen(cfg); + if (key && cfg) + { + if (len < 5 || grub_strncmp(cfg + len - 5, ".vcfg", 5)) + { + grub_printf("<%s> does not have \".vcfg\" suffix\n\n", cfg); + } + else + { + grub_printf("%s: <%s>\n", (type == vtoy_custom_boot_directory) ? "dir" : "file", key); + grub_printf("vcfg: <%s>\n\n", cfg); + } + } + } + + return 0; +} + static int ventoy_plugin_conf_replace_entry(VTOY_JSON *json, const char *isodisk) { const char *isof = NULL; @@ -1704,6 +1823,7 @@ static plugin_entry g_plugin_entries[] = { "conf_replace", ventoy_plugin_conf_replace_entry, ventoy_plugin_conf_replace_check }, { "dud", ventoy_plugin_dud_entry, ventoy_plugin_dud_check }, { "password", ventoy_plugin_pwd_entry, ventoy_plugin_pwd_check }, + { "custom_boot", ventoy_plugin_custom_boot_entry, ventoy_plugin_custom_boot_check }, }; static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk) @@ -2065,6 +2185,96 @@ const char * ventoy_plugin_get_menu_class(int type, const char *name) return NULL; } +int ventoy_plugin_add_custom_boot(const char *vcfgpath) +{ + int len; + custom_boot *node = NULL; + + node = grub_zalloc(sizeof(custom_boot)); + if (node) + { + node->type = vtoy_custom_boot_image_file; + node->pathlen = grub_snprintf(node->path, sizeof(node->path), "%s", vcfgpath); + grub_snprintf(node->cfg, sizeof(node->cfg), "%s", vcfgpath); + + /* .vcfg */ + len = node->pathlen - 5; + node->path[len] = 0; + node->pathlen = len; + + if (g_custom_boot_head) + { + node->next = g_custom_boot_head; + } + g_custom_boot_head = node; + } + + return 0; +} + +const char * ventoy_plugin_get_custom_boot(const char *isopath) +{ + int i; + int len; + custom_boot *node = NULL; + + if (!g_custom_boot_head) + { + return NULL; + } + + len = (int)grub_strlen(isopath); + + for (node = g_custom_boot_head; node; node = node->next) + { + if (node->type == vtoy_custom_boot_image_file) + { + if (node->pathlen == len && grub_strncmp(isopath, node->path, len) == 0) + { + return node->cfg; + } + } + else + { + if (node->pathlen < len && isopath[node->pathlen] == '/' && + grub_strncmp(isopath, node->path, node->pathlen) == 0) + { + for (i = node->pathlen + 1; i < len; i++) + { + if (isopath[i] == '/') + { + break; + } + } + + if (i >= len) + { + return node->cfg; + } + } + } + } + + return NULL; +} + +grub_err_t ventoy_cmd_dump_custom_boot(grub_extcmd_context_t ctxt, int argc, char **args) +{ + custom_boot *node = NULL; + + (void)argc; + (void)ctxt; + (void)args; + + for (node = g_custom_boot_head; node; node = node->next) + { + grub_printf("[%s] <%s>:<%s>\n", (node->type == vtoy_custom_boot_directory) ? "dir" : "file", + node->path, node->cfg); + } + + return 0; +} + int ventoy_plugin_check_memdisk(const char *isopath) { int len; diff --git a/GRUB2/MOD_SRC/grub-2.04/install.sh b/GRUB2/MOD_SRC/grub-2.04/install.sh index 253d1cbd..886a90f7 100644 --- a/GRUB2/MOD_SRC/grub-2.04/install.sh +++ b/GRUB2/MOD_SRC/grub-2.04/install.sh @@ -15,9 +15,9 @@ net_modules_legacy="net tftp http" all_modules_legacy="setkey date drivemap blocklist regexp newc vga_text ntldr search at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio lspci pci ext2 xfs ventoy chain read halt iso9660 linux16 test true sleep reboot echo videotest videoinfo videotest_checksum video_colors video_cirrus video_bochs vga vbe video_fb font video gettext extcmd terminal linux minicmd help configfile tr trig boot biosdisk disk ls tar squash4 password_pbkdf2 all_video png jpeg part_gpt part_msdos fat exfat ntfs loopback gzio normal udf gfxmenu gfxterm gfxterm_background gfxterm_menu" net_modules_uefi="efinet net tftp http" -all_modules_uefi="setkey blocklist ventoy test regexp newc search at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux relocator jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop efi_uga video_bochs video_cirrus video video_fb gfxterm_background gfxterm_menu" +all_modules_uefi="setkey blocklist ventoy test true regexp newc search at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux relocator jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop efi_uga video_bochs video_cirrus video video_fb gfxterm_background gfxterm_menu" -all_modules_arm64_uefi="setkey blocklist ventoy test regexp newc search gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop video video_fb gfxterm_background gfxterm_menu" +all_modules_arm64_uefi="setkey blocklist ventoy test true regexp newc search gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop video video_fb gfxterm_background gfxterm_menu" if [ "$1" = "uefi" ]; then diff --git a/INSTALL/grub/grub.cfg b/INSTALL/grub/grub.cfg index 2a61314f..71c7a189 100644 --- a/INSTALL/grub/grub.cfg +++ b/INSTALL/grub/grub.cfg @@ -50,6 +50,21 @@ function ventoy_acpi_param { fi } +function ventoy_vcfg_proc { + if vt_check_custom_boot "${1}" vt_vcfg; then + set vtoy_chosen_path="${1}" + vt_file_basefile "${vtoy_chosen_path}" vtoy_chosen_file + + export vtoy_chosen_path + export vtoy_chosen_file + ventoy_debug_pause + configfile "${vtoy_iso_part}${vt_vcfg}" + true + else + false + fi +} + function ventoy_power { configfile $prefix/power.cfg } @@ -959,6 +974,7 @@ function ventoy_iso_busybox_ver { fi } + function iso_common_menuentry { unset vt_system_id unset vt_volume_id @@ -981,7 +997,11 @@ function iso_common_menuentry { if vt_check_password "${vt_chosen_path}"; then return fi - + + if ventoy_vcfg_proc "${vt_chosen_path}"; then + return + fi + if vt_str_begin "$vt_volume_id" "Avira"; then vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}" fi @@ -1051,6 +1071,10 @@ function wim_common_menuentry { return fi + if ventoy_vcfg_proc "${vt_chosen_path}"; then + return + fi + if vt_wim_check_bootable "${vtoy_iso_part}${vt_chosen_path}"; then vt_wim_chain_data "${vtoy_iso_part}${vt_chosen_path}" else @@ -1086,6 +1110,10 @@ function efi_common_menuentry { return fi + if ventoy_vcfg_proc "${vt_chosen_path}"; then + return + fi + vt_concat_efi_iso "${vtoy_iso_part}${vt_chosen_path}" vtoy_iso_buf ventoy_debug_pause @@ -1127,6 +1155,10 @@ function vhd_common_menuentry { return fi + if ventoy_vcfg_proc "${vt_chosen_path}"; then + return + fi + vt_patch_vhdboot "$vt_chosen_path" ventoy_debug_pause @@ -1215,6 +1247,10 @@ function vtoy_common_menuentry { return fi + if ventoy_vcfg_proc "${vt_chosen_path}"; then + return + fi + vtoyboot_common_func "${vtoy_iso_part}${vt_chosen_path}" } @@ -1418,6 +1454,10 @@ function img_common_menuentry { return fi + if ventoy_vcfg_proc "${vt_chosen_path}"; then + return + fi + if [ -d (vtimghd)/ ]; then loopback -d vtimghd fi @@ -1496,7 +1536,7 @@ function img_unsupport_menuentry { ############################################################# ############################################################# -set VENTOY_VERSION="1.0.33" +set VENTOY_VERSION="1.0.34" #ACPI not compatible with Window7/8, so disable by default set VTOY_PARAM_NO_ACPI=1