#endif
#include <grub/time.h>
#include <grub/relocator.h>
+#include <grub/charset.h>
#include <grub/ventoy.h>
#include "ventoy_def.h"
ventoy_img_chunk_list g_wimiso_chunk_list;
char *g_wimiso_path = NULL;
+int g_vhdboot_enable = 0;
+
static char *g_tree_script_buf = NULL;
static int g_tree_script_pos = 0;
static const char *g_menu_class[] =
{
- "vtoyiso", "vtoywim", "vtoyefi", "vtoyimg"
+ "vtoyiso", "vtoywim", "vtoyefi", "vtoyimg", "vtoyvhd"
};
static const char *g_menu_prefix[] =
{
- "iso", "wim", "efi", "img"
+ "iso", "wim", "efi", "img", "vhd"
};
void ventoy_debug(const char *fmt, ...)
va_end (args);
}
+void ventoy_debug_dump_guid(const char *prefix, grub_uint8_t *guid)
+{
+ int i;
+
+ if (!g_ventoy_debug)
+ {
+ return;
+ }
+
+ debug("%s", prefix);
+ for (i = 0; i < 16; i++)
+ {
+ grub_printf("%02x ", guid[i]);
+ }
+ grub_printf("\n");
+}
+
int ventoy_is_efi_os(void)
{
if (g_efi_os > 1)
{
type = img_type_wim;
}
+ else if (g_vhdboot_enable && (0 == grub_strcasecmp(filename + len - 4, ".vhd") ||
+ 0 == grub_strcasecmp(filename + len - 5, ".vhdx")))
+ {
+ type = img_type_vhd;
+ }
#ifdef GRUB_MACHINE_EFI
else if (0 == grub_strcasecmp(filename + len - 4, ".efi"))
{
#endif
else if (0 == grub_strcasecmp(filename + len - 4, ".img"))
{
- if (len == 18 && grub_strncmp(filename, "ventoy_wimboot", 14) == 0)
+ if (len == 18 && grub_strncmp(filename, "ventoy_", 7) == 0)
{
- return 0;
+ if (grub_strncmp(filename + 7, "wimboot", 7) == 0 ||
+ grub_strncmp(filename + 7, "vhdboot", 7) == 0)
+ {
+ return 0;
+ }
}
type = img_type_img;
}
}
img->menu_prefix = g_menu_prefix[type];
+ if (img_type_iso == type)
+ {
+ if (ventoy_plugin_check_memdisk(img->path))
+ {
+ img->menu_prefix = "miso";
+ }
+ }
+
debug("Add %s%s to list %d\n", node->dir, filename, g_ventoy_img_count);
}
}
return 0;
}
+int ventoy_check_device_result(int ret)
+{
+ char buf[32];
+
+ grub_snprintf(buf, sizeof(buf), "%d", ret);
+ ventoy_set_env("VTOY_CHKDEV_RESULT_STRING", buf);
+
+ if (ret)
+ {
+ grub_printf(VTOY_WARNING"\n");
+ grub_printf(VTOY_WARNING"\n");
+ grub_printf(VTOY_WARNING"\n\n\n");
+
+ grub_printf("This is NOT a standard Ventoy device and is NOT officially supported.\n\n");
+ grub_printf("Recommend to follow the instructions in https://www.ventoy.net to use Ventoy.\n");
+
+ grub_printf("\n\nWill continue to boot after 10 seconds ...... ");
+ grub_refresh();
+ grub_sleep(10);
+ }
+
+ return ret;
+}
+
+int ventoy_check_device(grub_device_t dev)
+{
+ grub_file_t file;
+ grub_uint64_t offset;
+ char devname[64];
+ grub_fs_t fs;
+ grub_device_t dev2;
+ char *label = NULL;
+ struct grub_partition *partition;
+
+ if (dev->disk == NULL || dev->disk->partition == NULL)
+ {
+ return ventoy_check_device_result(1);
+ }
+
+ partition = dev->disk->partition;
+ if (partition->number != 0 || partition->start != 2048)
+ {
+ return ventoy_check_device_result(2);
+ }
+
+ offset = partition->start + partition->len;
+
+ /* We must have partition 2 */
+ file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "(%s,2)/ventoy/ventoy.cpio", dev->disk->name);
+ if (!file)
+ {
+ return ventoy_check_device_result(3);
+ }
+
+ partition = file->device->disk->partition;
+ if ((partition->number != 1) || (partition->len != 65536) || (offset != partition->start))
+ {
+ grub_file_close(file);
+ return ventoy_check_device_result(4);
+ }
+ grub_file_close(file);
+
+ grub_snprintf(devname, sizeof(devname), "%s,2", dev->disk->name);
+ dev2 = grub_device_open(devname);
+ if (!dev2)
+ {
+ return ventoy_check_device_result(5);
+ }
+
+ fs = grub_fs_probe(dev2);
+ if (!fs)
+ {
+ grub_device_close(dev2);
+ return ventoy_check_device_result(6);
+ }
+
+ fs->fs_label(dev2, &label);
+ if ((!label) || grub_strncmp("VTOYEFI", label, 7))
+ {
+ grub_device_close(dev2);
+ return ventoy_check_device_result(7);
+ }
+
+ grub_device_close(dev2);
+ return ventoy_check_device_result(0);
+}
+
static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char **args)
{
int len;
goto fail;
}
+ /* make sure that we are running in a correct Ventoy device */
+ ventoy_check_device(dev);
+
g_enum_fs = fs = grub_fs_probe(dev);
if (!fs)
{
goto fail;
}
+ ventoy_set_env("vtoy_iso_fs", fs->name);
+
strdata = ventoy_get_env("VTOY_DEFAULT_MENU_MODE");
if (strdata && strdata[0] == '1')
{
{ "vt_img_sector", ventoy_cmd_img_sector, 0, NULL, "{imageName}", "", NULL },
{ "vt_dump_img_sector", ventoy_cmd_dump_img_sector, 0, NULL, "", "", NULL },
{ "vt_load_wimboot", ventoy_cmd_load_wimboot, 0, NULL, "", "", NULL },
+ { "vt_load_vhdboot", ventoy_cmd_load_vhdboot, 0, NULL, "", "", NULL },
+ { "vt_patch_vhdboot", ventoy_cmd_patch_vhdboot, 0, NULL, "", "", NULL },
{ "vt_cpio_busybox64", ventoy_cmd_cpio_busybox_64, 0, NULL, "", "", NULL },
{ "vt_load_cpio", ventoy_cmd_load_cpio, 0, NULL, "", "", NULL },