X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/Ventoy.git/blobdiff_plain/05a1b863a66bf72b26e5d87570c4e0e61b9736cd..fe0dda690426b8e1b73c79b0dff46e1459ea40ec:/GRUB2/grub-2.04/grub-core/ventoy/ventoy_linux.c diff --git a/GRUB2/grub-2.04/grub-core/ventoy/ventoy_linux.c b/GRUB2/grub-2.04/grub-core/ventoy/ventoy_linux.c index cc35a84..06cd046 100644 --- a/GRUB2/grub-2.04/grub-core/ventoy/ventoy_linux.c +++ b/GRUB2/grub-2.04/grub-core/ventoy/ventoy_linux.c @@ -543,6 +543,7 @@ grub_err_t ventoy_cmd_specify_initrd_file(grub_extcmd_context_t ctxt, int argc, grub_strncpy(img->name, args[0], sizeof(img->name)); if (ventoy_find_initrd_by_name(g_initrd_img_list, img->name)) { + debug("%s is already exist\n", args[0]); grub_free(img); } else @@ -587,7 +588,7 @@ static void ventoy_cpio_newc_fill_int(grub_uint32_t value, char *buf, int buflen } } -int ventoy_cpio_newc_fill_head(void *buf, int filesize, void *filedata, const char *name) +int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name) { int namelen = 0; int headlen = 0; @@ -738,6 +739,23 @@ grub_err_t ventoy_cmd_initrd_count(grub_extcmd_context_t ctxt, int argc, char ** (void)argc; (void)args; + if (argc == 1) + { + grub_snprintf(buf, sizeof(buf), "%d", g_initrd_img_count); + grub_env_set(args[0], buf); + } + + VENTOY_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t ventoy_cmd_valid_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args) +{ + char buf[32] = {0}; + + (void)ctxt; + (void)argc; + (void)args; + if (argc == 1) { grub_snprintf(buf, sizeof(buf), "%d", g_valid_initrd_count); @@ -750,6 +768,7 @@ grub_err_t ventoy_cmd_initrd_count(grub_extcmd_context_t ctxt, int argc, char ** static grub_err_t ventoy_linux_locate_initrd(int filt, int *filtcnt) { int data; + int filtbysize = 1; int sizefilt = 0; grub_file_t file; initrd_info *node; @@ -757,6 +776,11 @@ static grub_err_t ventoy_linux_locate_initrd(int filt, int *filtcnt) debug("ventoy_linux_locate_initrd %d\n", filt); g_valid_initrd_count = 0; + + if (grub_env_get("INITRD_NO_SIZE_FILT")) + { + filtbysize = 0; + } for (node = g_initrd_img_list; node; node = node->next) { @@ -769,12 +793,18 @@ static grub_err_t ventoy_linux_locate_initrd(int filt, int *filtcnt) debug("file <%s> size:%d\n", node->name, (int)file->size); /* initrd file too small */ - if (filt > 0 && file->size <= g_ventoy_cpio_size + 2048) + if (filtbysize + && (NULL == grub_strstr(node->name, "minirt.gz")) + && (NULL == grub_strstr(node->name, "initrd.xz")) + ) { - debug("file size too small %d\n", (int)g_ventoy_cpio_size); - grub_file_close(file); - sizefilt++; - continue; + if (filt > 0 && file->size <= g_ventoy_cpio_size + 2048) + { + debug("file size too small %d\n", (int)g_ventoy_cpio_size); + grub_file_close(file); + sizefilt++; + continue; + } } if (grub_strcmp(file->fs->name, "iso9660") == 0) @@ -822,18 +852,22 @@ grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc, grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args) { - grub_uint8_t *buf; + char *template_file = NULL; + char *template_buf = NULL; + grub_uint8_t *buf = NULL; grub_uint32_t mod; grub_uint32_t headlen; grub_uint32_t initrd_head_len; grub_uint32_t padlen; grub_uint32_t img_chunk_size; + grub_uint32_t template_size = 0; grub_file_t file; + grub_file_t scriptfile; (void)ctxt; (void)argc; - if (argc != 1) + if (argc != 3) { return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s cpiofile\n", cmd_raw_name); } @@ -858,7 +892,30 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg g_ventoy_cpio_size = 0; } - g_ventoy_cpio_buf = grub_malloc(file->size + 4096 + img_chunk_size); + template_file = ventoy_plugin_get_install_template(args[1]); + if (template_file) + { + debug("auto install template: <%s>\n", template_file); + scriptfile = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", args[2], template_file); + if (scriptfile) + { + debug("auto install script size %d\n", (int)scriptfile->size); + template_size = scriptfile->size; + template_buf = grub_malloc(template_size); + if (template_buf) + { + grub_file_read(scriptfile, template_buf, template_size); + } + + grub_file_close(scriptfile); + } + else + { + debug("Failed to open install script %s%s\n", args[2], template_file); + } + } + + g_ventoy_cpio_buf = grub_malloc(file->size + 4096 + template_size + img_chunk_size); if (NULL == g_ventoy_cpio_buf) { grub_file_close(file); @@ -880,6 +937,12 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg headlen = ventoy_cpio_newc_fill_head(buf, img_chunk_size, g_img_chunk_list.chunk, "ventoy/ventoy_image_map"); buf += headlen + ventoy_align(img_chunk_size, 4); + if (template_buf) + { + headlen = ventoy_cpio_newc_fill_head(buf, template_size, template_buf, "ventoy/autoinstall"); + buf += headlen + ventoy_align(template_size, 4); + } + /* step2: insert os param to cpio */ headlen = ventoy_cpio_newc_fill_head(buf, 0, NULL, "ventoy/ventoy_os_param"); padlen = sizeof(ventoy_os_param);