diff --git a/DOC/BuildVentoyFromSource.txt b/DOC/BuildVentoyFromSource.txt index 8aae2823..be642b17 100644 --- a/DOC/BuildVentoyFromSource.txt +++ b/DOC/BuildVentoyFromSource.txt @@ -108,10 +108,10 @@ cd /home/Ventoy-master/VtoyTool sh build.sh -4.8 == Build vtoyfat == - cd /home/Ventoy-master/vtoyfat/fat_io_lib +4.8 == Build vtoycli == + cd /home/Ventoy-master/vtoycli/fat_io_lib sh buildlib.sh - cd /home/Ventoy-master/vtoyfat + cd /home/Ventoy-master/vtoycli sh build.sh 4.9 == Build exfat-util == 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 1586a5db..6e40f426 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 @@ -5713,6 +5713,7 @@ static cmd_para ventoy_cmds[] = { "vt_unix_parse_freebsd_ver_elf", ventoy_cmd_unix_freebsd_ver_elf, 0, NULL, "", "", NULL }, { "vt_unix_reset", ventoy_cmd_unix_reset, 0, NULL, "", "", NULL }, { "vt_unix_replace_conf", ventoy_cmd_unix_replace_conf, 0, NULL, "", "", NULL }, + { "vt_unix_replace_grub_conf", ventoy_cmd_unix_replace_grub_conf, 0, NULL, "", "", NULL }, { "vt_unix_replace_ko", ventoy_cmd_unix_replace_ko, 0, NULL, "", "", NULL }, { "vt_unix_ko_fillmap", ventoy_cmd_unix_ko_fillmap, 0, NULL, "", "", NULL }, { "vt_unix_fill_image_desc", ventoy_cmd_unix_fill_image_desc, 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 3e71fe39..763ed179 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 @@ -1094,6 +1094,7 @@ grub_err_t ventoy_cmd_unix_chain_data(grub_extcmd_context_t ctxt, int argc, char int ventoy_get_disk_guid(const char *filename, grub_uint8_t *guid, grub_uint8_t *signature); grub_err_t ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t ventoy_cmd_unix_replace_grub_conf(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_unix_ko_fillmap(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt, int argc, char **args); diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_unix.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_unix.c index fe581447..dbb30e17 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_unix.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_unix.c @@ -273,7 +273,7 @@ static void ventoy_unix_fill_virt_data( grub_uint64_t isosize, ventoy_chain_h return; } -static int ventoy_freebsd_append_conf(char *buf, const char *isopath) +static int ventoy_freebsd_append_conf(char *buf, const char *isopath, const char *alias) { int pos = 0; grub_uint32_t i; @@ -294,6 +294,10 @@ static int ventoy_freebsd_append_conf(char *buf, const char *isopath) vtoy_ssprintf(buf, pos, "ventoy_load=\"%s\"\n", "YES"); vtoy_ssprintf(buf, pos, "ventoy_name=\"%s\"\n", g_ko_mod_path); + if (alias) + { + vtoy_ssprintf(buf, pos, "hint.ventoy.0.alias=\"%s\"\n", alias); + } if (g_mod_search_magic) { @@ -647,6 +651,95 @@ out: VENTOY_CMD_RETURN(GRUB_ERR_NONE); } +grub_err_t ventoy_cmd_unix_replace_grub_conf(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int len; + grub_uint32_t i; + char *data; + char *pos; + grub_uint64_t offset; + grub_file_t file; + char extcfg[256]; + const char *confile = NULL; + const char * loader_conf[] = + { + "/boot/grub/grub.cfg", + }; + + (void)ctxt; + + if (argc != 1 && argc != 2) + { + debug("Replace conf invalid argc %d\n", argc); + return 1; + } + + for (i = 0; i < sizeof(loader_conf) / sizeof(loader_conf[0]); i++) + { + if (ventoy_get_file_override(loader_conf[i], &offset) == 0) + { + confile = loader_conf[i]; + g_conf_override_offset = offset; + break; + } + } + + if (confile == NULL) + { + debug("Can't find grub.cfg file from %u locations\n", i); + return 1; + } + + file = ventoy_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "(loop)/%s", confile); + if (!file) + { + debug("Failed to open %s \n", confile); + return 1; + } + + debug("old grub2 conf file size:%d\n", (int)file->size); + + data = grub_malloc(VTOY_MAX_SCRIPT_BUF); + if (!data) + { + grub_file_close(file); + return 1; + } + + grub_file_read(file, data, file->size); + grub_file_close(file); + + g_conf_new_data = data; + g_conf_new_len = (int)file->size; + + pos = grub_strstr(data, "kfreebsd /boot/kernel/kernel"); + if (pos) + { + pos += grub_strlen("kfreebsd /boot/kernel/kernel"); + + if (argc == 2) + { + len = grub_snprintf(extcfg, sizeof(extcfg), + ";kfreebsd_module_elf %s; set kFreeBSD.hint.ventoy.0.alias=\"%s\"", + args[0], args[1]); + } + else + { + len = grub_snprintf(extcfg, sizeof(extcfg), ";kfreebsd_module_elf %s", args[0]); + } + + grub_memmove(pos + len, pos, (int)(file->size - (pos - data))); + grub_memcpy(pos, extcfg, len); + g_conf_new_len += len; + } + else + { + debug("no kfreebsd found\n"); + } + + VENTOY_CMD_RETURN(GRUB_ERR_NONE); +} + grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, char **args) { grub_uint32_t i; @@ -662,7 +755,7 @@ grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, ch (void)ctxt; - if (argc != 2) + if (argc != 2 && argc != 3) { debug("Replace conf invalid argc %d\n", argc); return 1; @@ -708,7 +801,7 @@ grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, ch if (grub_strcmp(args[0], "FreeBSD") == 0) { - g_conf_new_len += ventoy_freebsd_append_conf(data + file->size, args[1]); + g_conf_new_len += ventoy_freebsd_append_conf(data + file->size, args[1], (argc > 2) ? args[2] : NULL); } else if (grub_strcmp(args[0], "DragonFly") == 0) { diff --git a/INSTALL/grub/grub.cfg b/INSTALL/grub/grub.cfg index feb8b2ac..e2998ceb 100644 --- a/INSTALL/grub/grub.cfg +++ b/INSTALL/grub/grub.cfg @@ -519,8 +519,17 @@ function ventoy_freebsd_proc { fi done - vt_unix_replace_ko $vt_unix_mod_path (vtunix)/ventoy_unix/$vtFreeBsdDistro/geom_ventoy_ko/$vt_freebsd_ver/$vt_freebsd_bit/geom_ventoy.ko.xz - vt_unix_replace_conf FreeBSD "${1}${chosen_path}" + if [ -n "$vt_unix_mod_path" ]; then + vt_unix_replace_ko $vt_unix_mod_path (vtunix)/ventoy_unix/$vtFreeBsdDistro/geom_ventoy_ko/$vt_freebsd_ver/$vt_freebsd_bit/geom_ventoy.ko.xz + vt_unix_replace_conf FreeBSD "${1}${chosen_path}" + elif [ -e (loop)/easyre.ufs.uzip ]; then + vt_unix_replace_ko "/boot/grub/i386-pc/linux.mod" (vtunix)/ventoy_unix/$vtFreeBsdDistro/geom_ventoy_ko/$vt_freebsd_ver/$vt_freebsd_bit/geom_ventoy.ko.xz + if [ "$grub_platform" = "pc" ]; then + vt_unix_replace_grub_conf "/boot/grub/i386-pc/linux.mod" "cd9" + else + vt_unix_replace_conf FreeBSD "${1}${chosen_path}" "cd9" + fi + fi } function ventoy_dragonfly_proc { diff --git a/INSTALL/ventoy/ventoy_unix.cpio b/INSTALL/ventoy/ventoy_unix.cpio index 9cf11c36..22d6af4d 100644 Binary files a/INSTALL/ventoy/ventoy_unix.cpio and b/INSTALL/ventoy/ventoy_unix.cpio differ diff --git a/Unix/ventoy_unix/FreeBSD/geom_ventoy_ko/13.x/64/geom_ventoy.ko.xz b/Unix/ventoy_unix/FreeBSD/geom_ventoy_ko/13.x/64/geom_ventoy.ko.xz index 537592eb..7bbca670 100644 Binary files a/Unix/ventoy_unix/FreeBSD/geom_ventoy_ko/13.x/64/geom_ventoy.ko.xz and b/Unix/ventoy_unix/FreeBSD/geom_ventoy_ko/13.x/64/geom_ventoy.ko.xz differ diff --git a/Unix/ventoy_unix_src/FreeBSD/geom_ventoy_src/13.x/sys/geom/ventoy/g_ventoy.c b/Unix/ventoy_unix_src/FreeBSD/geom_ventoy_src/13.x/sys/geom/ventoy/g_ventoy.c index 1924a06e..95c2842b 100644 --- a/Unix/ventoy_unix_src/FreeBSD/geom_ventoy_src/13.x/sys/geom/ventoy/g_ventoy.c +++ b/Unix/ventoy_unix_src/FreeBSD/geom_ventoy_src/13.x/sys/geom/ventoy/g_ventoy.c @@ -200,12 +200,17 @@ g_ventoy_access(struct g_provider *pp, int dr, int dw, int de) g_topology_assert(); gp = pp->geom; +#if 1 /* On first open, grab an extra "exclusive" bit */ if (pp->acr == 0 && pp->acw == 0 && pp->ace == 0) de++; /* ... and let go of it on last close */ if ((pp->acr + dr) == 0 && (pp->acw + dw) == 0 && (pp->ace + de) == 0) de--; +#else + G_DEBUG("g_ventoy_access fake de (%d)-->(0)\n", de); + de = 0; +#endif LIST_FOREACH_SAFE(cp1, &gp->consumer, consumer, tmp) { error = g_access(cp1, dr, dw, de); @@ -835,6 +840,7 @@ g_ventoy_taste(struct g_class *mp, struct g_provider *pp, int flags __unused) int disknum; char *endpos; const char *value; + const char *alias = NULL; struct g_geom *gp; struct g_ventoy_metadata md; struct g_ventoy_softc *sc; @@ -858,7 +864,17 @@ g_ventoy_taste(struct g_class *mp, struct g_provider *pp, int flags __unused) g_ventoy_tasted = true; - G_DEBUG("######### ventoy disk <%s> #############\n", pp->name); + G_DEBUG("###### ventoy disk <%s> ######\n", pp->name); + + /* hint.ventoy.0.alias=xxx */ + if (resource_string_value("ventoy", 0, "alias", &alias) == 0) + { + G_DEBUG("###### ventoy alias <%s> ######\n", alias); + } + else + { + alias = NULL; + } if (VENTOY_MAP_VALID(g_ventoy_map_data.magic2)) { @@ -929,7 +945,12 @@ g_ventoy_taste(struct g_class *mp, struct g_provider *pp, int flags __unused) g_disk_map_end = 0; } - return (gp); + if (alias && sc && sc->sc_provider) + { + g_provider_add_alias(sc->sc_provider, "%s", alias); + } + + return (gp); } static void