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.
This commit is contained in:
jeroen 2007-05-16 21:38:44 +00:00
parent 8fff7c2f2a
commit 849d55d3d1
6 changed files with 51 additions and 30 deletions

View file

@ -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> 2007-05-16 Robert Millan <rmh@aybabtu.com>
* DISTLIST: Update for the latest changes. * DISTLIST: Update for the latest changes.

View file

@ -1,6 +1,6 @@
/* /*
* GRUB -- GRand Unified Bootloader * 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 * GRUB is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * 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_guess_root_device (const char *dir);
char *grub_get_prefix (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 */ #endif /* ! GRUB_UTIL_GETROOT_HEADER */

View file

@ -1,7 +1,7 @@
/* getroot.c - Get root device */ /* getroot.c - Get root device */
/* /*
* GRUB -- GRand Unified Bootloader * 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 * GRUB is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * 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) if (stat (dir, &st) < 0)
grub_util_error ("Cannot stat `%s'", dir); 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__ #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. */ /* Check for LVM. */
if (!strncmp (os_dev, "/dev/mapper/", 12)) 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); strcpy (grub_dev, os_dev+12);
return grub_dev; return grub_dev;
} }
/* Check for RAID. */
if (!strncmp (os_dev, "/dev/md", 7)) if (!strncmp (os_dev, "/dev/md", 7))
{ {
char *p, *grub_dev = xmalloc (8); char *p, *grub_dev = xmalloc (8);
p = strchr (os_dev, 'm'); p = strchr (os_dev, 'm');
strncpy (grub_dev, p, 8); memcpy (grub_dev, p, 7);
grub_dev[7] = '\0';
return grub_dev; 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);
} }

View file

@ -1,6 +1,6 @@
/* /*
* GRUB -- GRand Unified Bootloader * 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 * GRUB is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * 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. */ /* Make sure that there is a root device. */
if (! args.root_dev) 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) if (! args.root_dev)
{ {
grub_util_info ("guessing the root device failed, because of `%s'", grub_util_info ("guessing the root device failed, because of `%s'",

View file

@ -1,7 +1,7 @@
/* grub-probe.c - probe device information for a given path */ /* grub-probe.c - probe device information for a given path */
/* /*
* GRUB -- GRand Unified Bootloader * 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 * GRUB is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -98,19 +98,11 @@ probe (const char *path)
goto end; goto end;
} }
if (device_name[0] == 'm' && device_name[1] == 'd' drive_name = grub_util_get_grub_dev (device_name);
&& device_name[2] >= '0' && device_name[2] <= '9') if (! drive_name)
{ {
drive_name = xstrdup (device_name); fprintf (stderr, "cannot find a GRUB drive for %s.\n", device_name);
} goto end;
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;
}
} }
if (print == PRINT_DRIVE) if (print == PRINT_DRIVE)

View file

@ -669,7 +669,7 @@ main (int argc, char *argv[])
if (! dest_dev) if (! dest_dev)
{ {
/* Possibly, the user specified an OS device file. */ /* 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) if (! dest_dev)
{ {
fprintf (stderr, "Invalid device `%s'.\n", argv[optind]); fprintf (stderr, "Invalid device `%s'.\n", argv[optind]);
@ -703,7 +703,7 @@ main (int argc, char *argv[])
} }
else 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) if (! root_dev)
{ {
grub_util_info ("guessing the root device failed, because of `%s'", grub_util_info ("guessing the root device failed, because of `%s'",
@ -743,7 +743,7 @@ main (int argc, char *argv[])
dir ? : DEFAULT_DIRECTORY, dir ? : DEFAULT_DIRECTORY,
boot_file ? : DEFAULT_BOOT_FILE, boot_file ? : DEFAULT_BOOT_FILE,
core_file ? : DEFAULT_CORE_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); free (raid_prefix);