]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2007-05-16 Jeroen Dekkers <jeroen@dekkers.cx>
authorjeroen <jeroen@localhost>
Wed, 16 May 2007 21:38:44 +0000 (21:38 +0000)
committerjeroen <jeroen@localhost>
Wed, 16 May 2007 21:38:44 +0000 (21:38 +0000)
* util/getroot.c (grub_guess_root_device): Remove RAID and LVM
code, first search for device in /dev/mapper, then in /dev.
(grub_util_get_grub_dev): New function.
* include/grub/util/getroot.h (grub_util_get_grub_dev): Add
prototype.
* util/grub-probe.c (probe): Remove check for RAID, call
grub_util_get_grub_dev() instead of
grub_util_biosdisk_get_grub_dev().
* util/grub-emu.c (main): Call grub_util_get_grub_dev() instead of
grub_util_biosdisk_get_grub_dev().
* util/i386/pc/grub-setup.c (main): Likewise.

ChangeLog
include/grub/util/getroot.h
util/getroot.c
util/grub-emu.c
util/grub-probe.c
util/i386/pc/grub-setup.c

index 142f95469dc50f459a16c6ca164926ce48933103..6cdd1d5793581b0387862c7c737683619dc95147 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-05-16  Jeroen Dekkers  <jeroen@dekkers.cx>
+
+       * util/getroot.c (grub_guess_root_device): Remove RAID and LVM
+       code, first search for device in /dev/mapper, then in /dev.
+       (grub_util_get_grub_dev): New function.
+       * include/grub/util/getroot.h (grub_util_get_grub_dev): Add
+       prototype.
+       * util/grub-probe.c (probe): Remove check for RAID, call
+       grub_util_get_grub_dev() instead of
+       grub_util_biosdisk_get_grub_dev().
+       * util/grub-emu.c (main): Call grub_util_get_grub_dev() instead of
+       grub_util_biosdisk_get_grub_dev().
+       * util/i386/pc/grub-setup.c (main): Likewise.
+
 2007-05-16  Robert Millan  <rmh@aybabtu.com>
 
        * DISTLIST: Update for the latest changes.
index 4fc1d6b3de9696d1a1825c1b65f3a266fd34af70..68fd6ec287be358da6b5750bb8d0dd3cc42c68d0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2003  Free Software Foundation, Inc.
+ *  Copyright (C) 2003, 2007  Free Software Foundation, Inc.
  *
  *  GRUB is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -22,5 +22,6 @@
 
 char *grub_guess_root_device (const char *dir);
 char *grub_get_prefix (const char *dir);
+char *grub_util_get_grub_dev (const char *os_dev);
 
 #endif /* ! GRUB_UTIL_GETROOT_HEADER */
index 7b2a61da4b4982b88e11943d8e5ff8b21f65ed65..836b3880d4c4d252a77e3ba325b86fda7653c8c1 100644 (file)
@@ -1,7 +1,7 @@
 /* getroot.c - Get root device */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 1999,2000,2001,2002,2003,2006  Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2006,2007  Free Software Foundation, Inc.
  *
  *  GRUB is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -225,32 +225,46 @@ grub_guess_root_device (const char *dir)
   if (stat (dir, &st) < 0)
     grub_util_error ("Cannot stat `%s'", dir);
 
-  /* This might be truly slow, but is there any better way?  */
-  os_dev = find_root_device ("/dev", st.st_dev);
-  if (! os_dev)
-    return 0;
-
 #ifdef __linux__
+  /* We first try to find the device in the /dev/mapper directory.  If
+     we don't do this, we get useless device names like /dev/dm-0 for
+     LVM. */
+  os_dev = find_root_device ("/dev/mapper", st.st_dev);
+  if (!os_dev)
+#endif __linux_
+    {
+      /* This might be truly slow, but is there any better way?  */
+      os_dev = find_root_device ("/dev", st.st_dev);
+    }
+
+  return os_dev;
+}
+
+char *
+grub_util_get_grub_dev (const char *os_dev)
+{
   /* Check for LVM.  */
   if (!strncmp (os_dev, "/dev/mapper/", 12))
     {
-      char *grub_dev = xmalloc (strlen (os_dev) - 12);
+      char *grub_dev = xmalloc (strlen (os_dev) - 12 + 1);
 
       strcpy (grub_dev, os_dev+12);
 
       return grub_dev;
     }
 
+  /* Check for RAID.  */
   if (!strncmp (os_dev, "/dev/md", 7))
     {
       char *p, *grub_dev = xmalloc (8);
 
       p = strchr (os_dev, 'm');
-      strncpy (grub_dev, p, 8);
+      memcpy (grub_dev, p, 7);
+      grub_dev[7] = '\0';
 
       return grub_dev;
     }
-#endif
-    
-  return os_dev;
+
+  /* If it's not RAID or LVM, it should be a biosdisk.  */
+  return grub_util_biosdisk_get_grub_dev (os_dev);
 }
index a0dba7f5be419e0234275b3d5bc24066f42d9aab..67cb905084b0beb2fb9282b5ff402341641593ed 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2003,2004,2005,2006  Free Software Foundation, Inc.
+ *  Copyright (C) 2003,2004,2005,2006,2007  Free Software Foundation, Inc.
  *
  *  GRUB is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -190,7 +190,7 @@ main (int argc, char *argv[])
   /* Make sure that there is a root device.  */
   if (! args.root_dev)
     {
-      args.root_dev = grub_util_biosdisk_get_grub_dev (grub_guess_root_device (args.dir ? : DEFAULT_DIRECTORY));
+      args.root_dev = grub_util_get_grub_dev (grub_guess_root_device (args.dir ? : DEFAULT_DIRECTORY));
       if (! args.root_dev)
        {
          grub_util_info ("guessing the root device failed, because of `%s'",
index b9085ea7e57784da2decfa8b16a8c7f191bccf85..29d0d0a4f6368f38dfdfaa137c0e473f9c8be7a0 100644 (file)
@@ -1,7 +1,7 @@
 /* grub-probe.c - probe device information for a given path */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2005,2006 Free Software Foundation, Inc.
+ *  Copyright (C) 2005,2006,2007 Free Software Foundation, Inc.
  *
  *  GRUB is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -98,19 +98,11 @@ probe (const char *path)
       goto end;
     }
 
-  if (device_name[0] == 'm' && device_name[1] == 'd'
-      && device_name[2] >= '0' && device_name[2] <= '9')
+  drive_name = grub_util_get_grub_dev (device_name);
+  if (! drive_name)
     {
-      drive_name = xstrdup (device_name);
-    }
-  else
-    {
-      drive_name = grub_util_biosdisk_get_grub_dev (device_name);
-      if (! drive_name)
-       {
-         fprintf (stderr, "cannot find a GRUB drive for %s.\n", device_name);
-         goto end;
-       }
+      fprintf (stderr, "cannot find a GRUB drive for %s.\n", device_name);
+      goto end;
     }
   
   if (print == PRINT_DRIVE)
index 764d5d1252958d995f3081a86050c4bdd6de93b0..47d4b9f7015e60c6c74ff3753e1de24c66504a28 100644 (file)
@@ -669,7 +669,7 @@ main (int argc, char *argv[])
   if (! dest_dev)
     {
       /* Possibly, the user specified an OS device file.  */
-      dest_dev = grub_util_biosdisk_get_grub_dev (argv[optind]);
+      dest_dev = grub_util_get_grub_dev (argv[optind]);
       if (! dest_dev)
        {
          fprintf (stderr, "Invalid device `%s'.\n", argv[optind]);
@@ -703,7 +703,7 @@ main (int argc, char *argv[])
     }
   else
     {
-      root_dev = grub_util_biosdisk_get_grub_dev (grub_guess_root_device (dir ? : DEFAULT_DIRECTORY));
+      root_dev = grub_util_get_grub_dev (grub_guess_root_device (dir ? : DEFAULT_DIRECTORY));
       if (! root_dev)
        {
          grub_util_info ("guessing the root device failed, because of `%s'",
@@ -743,7 +743,7 @@ main (int argc, char *argv[])
                 dir ? : DEFAULT_DIRECTORY,
                 boot_file ? : DEFAULT_BOOT_FILE,
                 core_file ? : DEFAULT_CORE_FILE,
-                root_dev, grub_util_biosdisk_get_grub_dev (devicelist[i]), 1);
+                root_dev, grub_util_get_grub_dev (devicelist[i]), 1);
        }
 
       free (raid_prefix);