+static grub_err_t ventoy_cmd_file_size(grub_extcmd_context_t ctxt, int argc, char **args)
+{
+ int rc = 1;
+ char buf[32];
+ grub_file_t file;
+
+ (void)ctxt;
+ (void)argc;
+ (void)args;
+
+ if (argc != 2)
+ {
+ return rc;
+ }
+
+ file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
+ if (file == NULL)
+ {
+ debug("failed to open file <%s> for udf check\n", args[0]);
+ return 1;
+ }
+
+ grub_snprintf(buf, sizeof(buf), "%llu", (unsigned long long)file->size);
+
+ grub_env_set(args[1], buf);
+
+ grub_file_close(file);
+ rc = 0;
+
+ return rc;
+}
+
+static grub_err_t ventoy_cmd_load_iso_to_mem(grub_extcmd_context_t ctxt, int argc, char **args)
+{
+ int rc = 1;
+ char name[32];
+ char value[32];
+ char *buf = NULL;
+ grub_file_t file;
+
+ (void)ctxt;
+ (void)argc;
+ (void)args;
+
+ if (argc != 2)
+ {
+ return rc;
+ }
+
+ file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
+ if (file == NULL)
+ {
+ debug("failed to open file <%s> for udf check\n", args[0]);
+ return 1;
+ }
+
+#ifdef GRUB_MACHINE_EFI
+ buf = (char *)grub_efi_allocate_iso_buf(file->size);
+#else
+ buf = (char *)grub_malloc(file->size);
+#endif
+
+ grub_file_read(file, buf, file->size);
+
+ grub_snprintf(name, sizeof(name), "%s_addr", args[1]);
+ grub_snprintf(value, sizeof(value), "0x%llx", (unsigned long long)(unsigned long)buf);
+ grub_env_set(name, value);
+
+ grub_snprintf(name, sizeof(name), "%s_size", args[1]);
+ grub_snprintf(value, sizeof(value), "%llu", (unsigned long long)file->size);
+ grub_env_set(name, value);
+
+ grub_file_close(file);
+ rc = 0;
+
+ return rc;
+}
+