]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - GRUB2/MOD_SRC/grub-2.04/grub-core/kern/main.c
1.0.13 release
[Ventoy.git] / GRUB2 / MOD_SRC / grub-2.04 / grub-core / kern / main.c
index 43b2de984051ca8c296d3fb505e3ded6395074e4..2f22ecb56a53e1192beede96130cbb8b8af4572b 100644 (file)
@@ -260,6 +260,45 @@ reclaim_module_space (void)
 #endif
 }
 
+#ifndef GRUB_MACHINE_EFI
+static int ventoy_legacy_limit_workaround(void)
+{
+    grub_file_t file;
+    char *pos, *root;
+    char buf[128];
+
+    root = grub_strdup(grub_env_get("root"));
+    if (!root)
+    {
+        return 1;
+    }
+
+    pos = grub_strchr(root, ',');
+    if (pos) *pos = 0;
+
+    grub_snprintf(buf, sizeof(buf), "(%s,1)/ventoy/ventoy.disk.img.xz", root);
+    file = grub_file_open(buf, GRUB_FILE_TYPE_NONE);
+    if (file)
+    {
+        pos = grub_malloc(file->size);
+        if (pos)
+        {
+            grub_file_read(file, pos, file->size);
+            grub_snprintf(buf, sizeof(buf), "loopback ventoydisk mem:0x%lx:size:%lu", 
+                          (unsigned long)pos, (unsigned long)file->size);
+            
+            grub_parser_execute(buf);
+            grub_env_set("prefix", "(ventoydisk)/grub");
+        }
+
+        grub_file_close(file);
+    }
+
+    grub_free(root);      
+    return 0;
+}
+#endif
+
 /* The main routine.  */
 void __attribute__ ((noreturn))
 grub_main (void)
@@ -293,6 +332,12 @@ grub_main (void)
   grub_env_export ("root");
   grub_env_export ("prefix");
 
+#ifndef GRUB_MACHINE_EFI
+  if (0 == ventoy_check_file_exist("%s/grub.cfg", grub_env_get("prefix"))) {
+      ventoy_legacy_limit_workaround();
+  }
+#endif
+
   /* Reclaim space used for modules.  */
   reclaim_module_space ();