From 849d55d3d17cf7aa57a391e01c6efd89a586df24 Mon Sep 17 00:00:00 2001 From: jeroen Date: Wed, 16 May 2007 21:38:44 +0000 Subject: [PATCH] 2007-05-16 Jeroen Dekkers * 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 | 14 ++++++++++++++ include/grub/util/getroot.h | 3 ++- util/getroot.c | 36 +++++++++++++++++++++++++----------- util/grub-emu.c | 4 ++-- util/grub-probe.c | 18 +++++------------- util/i386/pc/grub-setup.c | 6 +++--- 6 files changed, 51 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 142f95469..6cdd1d579 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2007-05-16 Jeroen Dekkers + + * 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 * DISTLIST: Update for the latest changes. diff --git a/include/grub/util/getroot.h b/include/grub/util/getroot.h index 4fc1d6b3d..68fd6ec28 100644 --- a/include/grub/util/getroot.h +++ b/include/grub/util/getroot.h @@ -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 */ diff --git a/util/getroot.c b/util/getroot.c index 7b2a61da4..836b3880d 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -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); } diff --git a/util/grub-emu.c b/util/grub-emu.c index a0dba7f5b..67cb90508 100644 --- a/util/grub-emu.c +++ b/util/grub-emu.c @@ -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'", diff --git a/util/grub-probe.c b/util/grub-probe.c index b9085ea7e..29d0d0a4f 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -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) diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index 764d5d125..47d4b9f70 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -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);