Hi Vladimir,

here an another try. I hope it's better now ;-) Open for you feedback.
If it's ok it would be nice if one of you could commit this patch to
bazaar for me.

Greetings,
Raphael
# HG changeset patch
# Parent 1019176187e9f766af7b3940c307964ffdb09e80

diff -r 1019176187e9 include/grub/emu/misc.h
--- a/include/grub/emu/misc.h	Tue Jul 27 09:59:43 2010 +0200
+++ b/include/grub/emu/misc.h	Tue Jul 27 11:51:36 2010 +0200
@@ -51,5 +51,6 @@
 #ifdef HAVE_DEVICE_MAPPER
 int grub_device_mapper_supported (void);
 #endif
+int device_is_mapped (const char *dev);
 
 #endif /* GRUB_EMU_MISC_H */
diff -r 1019176187e9 kern/emu/getroot.c
--- a/kern/emu/getroot.c	Tue Jul 27 09:59:43 2010 +0200
+++ b/kern/emu/getroot.c	Tue Jul 27 11:51:36 2010 +0200
@@ -139,9 +139,6 @@
       free (ret);
       ret = NULL;
 
-      if (major != 0)
-	continue; /* not a virtual device */
-
       sep = strstr (buf + count, " - ");
       if (!sep)
 	continue;
@@ -156,6 +153,9 @@
       if (!S_ISBLK (st.st_mode))
 	continue; /* not a block device */
 
+      if (major != 0 && ! device_is_mapped (device))
+	continue; /* not a virtual device */
+
       ret = strdup (device);
     }
 
diff -r 1019176187e9 kern/emu/hostdisk.c
--- a/kern/emu/hostdisk.c	Tue Jul 27 09:59:43 2010 +0200
+++ b/kern/emu/hostdisk.c	Tue Jul 27 11:51:36 2010 +0200
@@ -316,19 +316,6 @@
   return GRUB_ERR_NONE;
 }
 
-#ifdef HAVE_DEVICE_MAPPER
-static int
-device_is_mapped (const char *dev)
-{
-  struct stat st;
-
-  if (stat (dev, &st) < 0)
-    return 0;
-
-  return dm_is_dm_major (major (st.st_rdev));
-}
-#endif /* HAVE_DEVICE_MAPPER */
-
 #if defined(__linux__) || defined(__CYGWIN__) || defined(__NetBSD__)
 static grub_disk_addr_t
 find_partition_start (const char *dev)
@@ -342,7 +329,7 @@
 # endif /* !defined(__NetBSD__) */
 
 # ifdef HAVE_DEVICE_MAPPER
-  if (grub_device_mapper_supported () && device_is_mapped (dev)) {
+  if (device_is_mapped (dev)) {
     struct dm_task *task = NULL;
     grub_uint64_t start, length;
     char *target_type, *params, *space;
@@ -1145,7 +1132,7 @@
 
 #ifdef HAVE_DEVICE_MAPPER
       /* If this is a DM-RAID device.  */
-      if ((strncmp ("mapper/", p, 7) == 0))
+      if (device_is_mapped (path))
 	{
 	  static struct dm_tree *tree = NULL;
 	  uint32_t maj, min;
diff -r 1019176187e9 kern/emu/misc.c
--- a/kern/emu/misc.c	Tue Jul 27 09:59:43 2010 +0200
+++ b/kern/emu/misc.c	Tue Jul 27 11:51:36 2010 +0200
@@ -350,3 +350,21 @@
   return supported;
 }
 #endif /* HAVE_DEVICE_MAPPER */
+
+int
+device_is_mapped (const char *dev)
+{
+#ifdef HAVE_DEVICE_MAPPER
+  struct stat st;
+
+  if (! grub_device_mapper_supported ())
+    return 0;
+
+  if (stat (dev, &st) < 0)
+    return 0;
+
+  return dm_is_dm_major (major (st.st_rdev));
+#else
+  return 0;
+#endif /* HAVE_DEVICE_MAPPER */
+}
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to