zbyszek / rpms / grub2

Forked from rpms/grub2 5 years ago
Clone
31004e6
From 25ec194a39ae32af2000600ee2e6e1d28230fa98 Mon Sep 17 00:00:00 2001
31004e6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
31004e6
Date: Mon, 29 Apr 2013 12:14:57 +0200
f74b50e
Subject: [PATCH 388/482] 	* grub-core/commands/nativedisk.c: Customize
31004e6
 the list of modules on 	platform. Don't try to search for disks
31004e6
 already using native drivers.
31004e6
31004e6
---
31004e6
 ChangeLog                       |   5 ++
31004e6
 grub-core/Makefile.core.def     |   4 ++
31004e6
 grub-core/commands/nativedisk.c | 101 +++++++++++++++++++++++++++++++---------
31004e6
 3 files changed, 89 insertions(+), 21 deletions(-)
31004e6
31004e6
diff --git a/ChangeLog b/ChangeLog
31004e6
index 99a049a..1ba588d 100644
31004e6
--- a/ChangeLog
31004e6
+++ b/ChangeLog
31004e6
@@ -1,5 +1,10 @@
31004e6
 2013-04-29  Vladimir Serbinenko  <phcoder@gmail.com>
31004e6
 
31004e6
+	* grub-core/commands/nativedisk.c: Customize the list of modules on
31004e6
+	platform. Don't try to search for disks already using native drivers.
31004e6
+
31004e6
+2013-04-29  Vladimir Serbinenko  <phcoder@gmail.com>
31004e6
+
31004e6
 	* grub-core/bus/usb/uhci.c: Fix DMA handling and enable on all PCI
31004e6
 	platforms.
31004e6
 
31004e6
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
31004e6
index dcb92ef..ebcd01d 100644
31004e6
--- a/grub-core/Makefile.core.def
31004e6
+++ b/grub-core/Makefile.core.def
31004e6
@@ -510,6 +510,10 @@ module = {
31004e6
 module = {
31004e6
   name = nativedisk;
31004e6
   common = commands/nativedisk.c;
31004e6
+
31004e6
+  enable = x86;
31004e6
+  enable = mips_loongson;
31004e6
+  enable = mips_qemu_mips;
31004e6
 };
31004e6
 
31004e6
 module = {
31004e6
diff --git a/grub-core/commands/nativedisk.c b/grub-core/commands/nativedisk.c
31004e6
index 333fc82..453faad 100644
31004e6
--- a/grub-core/commands/nativedisk.c
31004e6
+++ b/grub-core/commands/nativedisk.c
31004e6
@@ -31,17 +31,67 @@
31004e6
 
31004e6
 GRUB_MOD_LICENSE ("GPLv3+");
31004e6
 
31004e6
-static const char *modnames_def[] = { "pata", "ahci", "usbms", "ohci", "uhci", "ehci" };
31004e6
+static const char *modnames_def[] = { 
31004e6
+  /* FIXME: autogenerate this.  */
31004e6
+#if defined (__i386__) || defined (__x86_64__) || defined (GRUB_MACHINE_MIPS_LOONGSON)
31004e6
+  "pata", "ahci", "usbms", "ohci", "uhci", "ehci"
31004e6
+#elif defined (GRUB_MACHINE_MIPS_QEMU_MIPS)
31004e6
+  "pata"
31004e6
+#else
31004e6
+#error "Fill this"
31004e6
+#endif
31004e6
+ };
31004e6
 
31004e6
 static grub_err_t
31004e6
-get_uuid (const char *name, char **uuid)
31004e6
+get_uuid (const char *name, char **uuid, int getnative)
31004e6
 {
31004e6
   grub_device_t dev;
31004e6
   grub_fs_t fs = 0;
31004e6
 
31004e6
+  *uuid = 0;
31004e6
+
31004e6
   dev = grub_device_open (name);
31004e6
   if (!dev)
31004e6
     return grub_errno;
31004e6
+
31004e6
+  if (!dev->disk)
31004e6
+    {
31004e6
+      grub_dprintf ("nativedisk", "Skipping non-disk\n");
31004e6
+      return 0;
31004e6
+    }
31004e6
+
31004e6
+  switch (dev->disk->dev->id)
31004e6
+    {
31004e6
+      /* Firmware disks.  */
31004e6
+    case GRUB_DISK_DEVICE_BIOSDISK_ID:
31004e6
+    case GRUB_DISK_DEVICE_OFDISK_ID:
31004e6
+    case GRUB_DISK_DEVICE_EFIDISK_ID:
31004e6
+    case GRUB_DISK_DEVICE_NAND_ID:
31004e6
+    case GRUB_DISK_DEVICE_ARCDISK_ID:
31004e6
+    case GRUB_DISK_DEVICE_HOSTDISK_ID:
31004e6
+      break;
31004e6
+
31004e6
+      /* Native disks.  */
31004e6
+    case GRUB_DISK_DEVICE_ATA_ID:
31004e6
+    case GRUB_DISK_DEVICE_SCSI_ID:
31004e6
+      if (getnative)
31004e6
+	break;
31004e6
+
31004e6
+      /* Virtual disks.  */
31004e6
+    case GRUB_DISK_DEVICE_PROCFS_ID:
31004e6
+    case GRUB_DISK_DEVICE_HOST_ID:
31004e6
+      /* GRUB-only memdisk. Can't match any of firmware devices.  */
31004e6
+    case GRUB_DISK_DEVICE_MEMDISK_ID:
31004e6
+      grub_dprintf ("nativedisk", "Skipping native disk %s\n",
31004e6
+		    dev->disk->name);
31004e6
+      return 0;
31004e6
+
31004e6
+      /* FIXME: those probably need special handling.  */
31004e6
+    case GRUB_DISK_DEVICE_LOOPBACK_ID:
31004e6
+    case GRUB_DISK_DEVICE_DISKFILTER_ID:
31004e6
+    case GRUB_DISK_DEVICE_CRYPTODISK_ID:
31004e6
+      break;
31004e6
+    }
31004e6
   if (dev)
31004e6
     fs = grub_fs_probe (dev);
31004e6
   if (!fs)
31004e6
@@ -49,7 +99,7 @@ get_uuid (const char *name, char **uuid)
31004e6
       grub_device_close (dev);
31004e6
       return grub_errno;
31004e6
     }
31004e6
-  if (!fs->uuid || fs->uuid (dev, uuid))
31004e6
+  if (!fs->uuid || fs->uuid (dev, uuid) || !*uuid)
31004e6
     {
31004e6
       grub_device_close (dev);
31004e6
 
31004e6
@@ -77,14 +127,17 @@ iterate_device (const char *name, void *data)
31004e6
   struct search_ctx *ctx = data;
31004e6
   char *cur_uuid;
31004e6
 
31004e6
-  if (get_uuid (name, &cur_uuid))
31004e6
+  if (get_uuid (name, &cur_uuid, 1))
31004e6
     {
31004e6
       if (grub_errno == GRUB_ERR_UNKNOWN_FS)
31004e6
 	grub_errno = 0;
31004e6
       grub_print_error ();
31004e6
       return 0;
31004e6
     }
31004e6
-  if (grub_strcasecmp (cur_uuid, ctx->prefix_uuid) == 0)
31004e6
+
31004e6
+  grub_dprintf ("nativedisk", "checking %s: %s\n", name,
31004e6
+		cur_uuid);
31004e6
+  if (ctx->prefix_uuid && grub_strcasecmp (cur_uuid, ctx->prefix_uuid) == 0)
31004e6
     {
31004e6
       char *prefix;
31004e6
       prefix = grub_xasprintf ("(%s)/%s", name, ctx->prefix_path);
31004e6
@@ -92,7 +145,7 @@ iterate_device (const char *name, void *data)
31004e6
       grub_free (prefix);
31004e6
       ctx->prefix_found = 1;
31004e6
     }
31004e6
-  if (grub_strcasecmp (cur_uuid, ctx->root_uuid) == 0)
31004e6
+  if (ctx->root_uuid && grub_strcasecmp (cur_uuid, ctx->root_uuid) == 0)
31004e6
     {
31004e6
       grub_env_set ("root", name);
31004e6
       ctx->root_found = 1;
31004e6
@@ -109,9 +162,7 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
31004e6
   const char *path_prefix = 0;
31004e6
   int mods_loaded = 0;
31004e6
   grub_dl_t *mods;
31004e6
-  struct search_ctx ctx;
31004e6
   const char **args;
31004e6
-  grub_fs_autoload_hook_t saved_autoload;
31004e6
   int i;
31004e6
 
31004e6
   if (argc == 0)
31004e6
@@ -138,7 +189,7 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
31004e6
   if (!mods)
31004e6
     return grub_errno;
31004e6
 
31004e6
-  if (get_uuid (NULL, &uuid_root))
31004e6
+  if (get_uuid (NULL, &uuid_root, 0))
31004e6
     return grub_errno;
31004e6
 
31004e6
   prefdev = grub_file_get_device_name (prefix);
31004e6
@@ -148,12 +199,15 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
31004e6
       prefdev = 0;
31004e6
     }
31004e6
 
31004e6
-  if (get_uuid (prefdev, &uuid_prefix))
31004e6
+  if (get_uuid (prefdev, &uuid_prefix, 0))
31004e6
     {
31004e6
       grub_free (uuid_root);
31004e6
       return grub_errno;
31004e6
     }
31004e6
 
31004e6
+  grub_dprintf ("nativedisk", "uuid_prefix = %s, uuid_root = %s\n",
31004e6
+		uuid_prefix, uuid_root);
31004e6
+
31004e6
   for (mods_loaded = 0; mods_loaded < argc; mods_loaded++)
31004e6
     {
31004e6
       char *filename;
31004e6
@@ -205,21 +259,26 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
31004e6
     if (mods[i])
31004e6
       grub_dl_init (mods[i]);
31004e6
 
31004e6
-  /* No need to autoload FS since obviously we already have the necessary fs modules.  */
31004e6
-  saved_autoload = grub_fs_autoload_hook;
31004e6
-  grub_fs_autoload_hook = 0;
31004e6
+  if (uuid_prefix || uuid_root)
31004e6
+    {
31004e6
+      struct search_ctx ctx;
31004e6
+      grub_fs_autoload_hook_t saved_autoload;
31004e6
 
31004e6
-  ctx.root_uuid = uuid_root;
31004e6
-  ctx.prefix_uuid = uuid_prefix;
31004e6
-  ctx.prefix_path = path_prefix;
31004e6
-  ctx.prefix_found = 0;
31004e6
-  ctx.root_found = 0;
31004e6
+      /* No need to autoload FS since obviously we already have the necessary fs modules.  */
31004e6
+      saved_autoload = grub_fs_autoload_hook;
31004e6
+      grub_fs_autoload_hook = 0;
31004e6
 
31004e6
-  /* FIXME: try to guess the correct values.  */
31004e6
-  grub_device_iterate (iterate_device, &ctx;;
31004e6
+      ctx.root_uuid = uuid_root;
31004e6
+      ctx.prefix_uuid = uuid_prefix;
31004e6
+      ctx.prefix_path = path_prefix;
31004e6
+      ctx.prefix_found = !uuid_prefix;
31004e6
+      ctx.root_found = !uuid_root;
31004e6
 
31004e6
-  grub_fs_autoload_hook = saved_autoload;
31004e6
+      /* FIXME: try to guess the correct values.  */
31004e6
+      grub_device_iterate (iterate_device, &ctx;;
31004e6
 
31004e6
+      grub_fs_autoload_hook = saved_autoload;
31004e6
+    }
31004e6
   grub_free (uuid_root);
31004e6
   grub_free (uuid_prefix);
31004e6
 
31004e6
-- 
31004e6
1.8.2.1
31004e6