From 6babad5e597ca4241acefd8911aea8ddca1ff58d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 23 Dec 2011 18:19:16 +0100 Subject: [PATCH 1/7] Initial integration of hints --- Makefile.util.def | 6 +- grub-core/commands/search_wrap.c | 114 +++++++++-- grub-core/disk/ieee1275/ofdisk.c | 15 +- grub-core/kern/emu/hostdisk.c | 23 ++- grub-core/normal/main.c | 2 +- include/grub/emu/hostdisk.h | 2 + util/grub-install.in | 47 ++--- util/grub-mkconfig.in | 13 -- util/grub-mkconfig_lib.in | 9 +- util/grub-probe.c | 315 +++++++++++++++++++++++++++++++ util/ieee1275/devicemap.c | 49 ----- 11 files changed, 489 insertions(+), 106 deletions(-) delete mode 100644 util/ieee1275/devicemap.c diff --git a/Makefile.util.def b/Makefile.util.def index 829b16fac..8812a783c 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -242,10 +242,7 @@ program = { common = util/grub-mkdevicemap.c; common = util/deviceiter.c; - nosparc64 = util/devicemap.c; - - sparc64_ieee1275 = util/ieee1275/ofpath.c; - sparc64_ieee1275 = util/ieee1275/devicemap.c; + common = util/devicemap.c; ldadd = libgrubmods.a; ldadd = libgrubkern.a; @@ -258,6 +255,7 @@ program = { installdir = sbin; mansection = 8; common = util/grub-probe.c; + common = util/ieee1275/ofpath.c; ldadd = libgrubmods.a; ldadd = libgrubkern.a; diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c index 7b0a99565..35c5ee319 100644 --- a/grub-core/commands/search_wrap.c +++ b/grub-core/commands/search_wrap.c @@ -42,6 +42,21 @@ static const struct grub_arg_option options[] = {"hint", 'h', GRUB_ARG_OPTION_REPEATABLE, N_("First try the device HINT. If HINT ends in comma, " "also try subpartitions"), N_("HINT"), ARG_TYPE_STRING}, + {"hint-ieee1275", 0, GRUB_ARG_OPTION_REPEATABLE, + N_("First try the device HINT if on IEEE1275. If HINT ends in comma, " + "also try subpartitions"), N_("HINT"), ARG_TYPE_STRING}, + {"hint-bios", 0, GRUB_ARG_OPTION_REPEATABLE, + N_("First try the device HINT if on BIOS. If HINT ends in comma, " + "also try subpartitions"), N_("HINT"), ARG_TYPE_STRING}, + {"hint-baremetal", 0, GRUB_ARG_OPTION_REPEATABLE, + N_("First try the device HINT. If HINT ends in comma, " + "also try subpartitions"), N_("HINT"), ARG_TYPE_STRING}, + {"hint-efi", 0, GRUB_ARG_OPTION_REPEATABLE, + N_("First try the device HINT if on EFI. If HINT ends in comma, " + "also try subpartitions"), N_("HINT"), ARG_TYPE_STRING}, + {"hint-arc", 0, GRUB_ARG_OPTION_REPEATABLE, + N_("First try the device HINT if on ARC. If HINT ends in comma, " + "also try subpartitions"), N_("HINT"), ARG_TYPE_STRING}, {0, 0, 0, 0, 0, 0} }; @@ -52,7 +67,12 @@ enum options SEARCH_FS_UUID, SEARCH_SET, SEARCH_NO_FLOPPY, - SEARCH_HINT + SEARCH_HINT, + SEARCH_HINT_IEEE1275, + SEARCH_HINT_BIOS, + SEARCH_HINT_BAREMETAL, + SEARCH_HINT_EFI, + SEARCH_HINT_ARC, }; static grub_err_t @@ -60,27 +80,98 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) { struct grub_arg_list *state = ctxt->state; const char *var = 0; - int nhints = 0; + int i = 0, j = 0, nhints = 0; + char **hints = NULL; if (state[SEARCH_HINT].set) - while (state[SEARCH_HINT].args[nhints]) + for (i = 0; state[SEARCH_HINT].args[i]; i++) nhints++; - if (argc == 0) +#ifdef GRUB_MACHINE_IEEE1275 + if (state[SEARCH_HINT_IEEE1275].set) + for (i = 0; state[SEARCH_HINT_IEEE1275].args[i]; i++) + nhints++; +#endif + +#ifdef GRUB_MACHINE_EFI + if (state[SEARCH_HINT_EFI].set) + for (i = 0; state[SEARCH_HINT_EFI].args[i]; i++) + nhints++; +#endif + +#ifdef GRUB_MACHINE_PCBIOS + if (state[SEARCH_HINT_BIOS].set) + for (i = 0; state[SEARCH_HINT_BIOS].args[i]; i++) + nhints++; +#endif + +#ifdef GRUB_MACHINE_ARC + if (state[SEARCH_HINT_ARC].set) + for (i = 0; state[SEARCH_HINT_ARC].args[i]; i++) + nhints++; +#endif + + if (state[SEARCH_HINT_BAREMETAL].set) + for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++) + nhints++; + + hints = grub_malloc (sizeof (hints[0]) * nhints); + if (!hints) + return grub_errno; + j = 0; + + if (state[SEARCH_HINT].set) + for (i = 0; state[SEARCH_HINT].args[i]; i++) + hints[j++] = state[SEARCH_HINT].args[i]; + +#ifdef GRUB_MACHINE_IEEE1275 + if (state[SEARCH_HINT_IEEE1275].set) + for (i = 0; state[SEARCH_HINT_IEEE1275].args[i]; i++) + hints[j++] = state[SEARCH_HINT_IEEE1275].args[i]; +#endif + +#ifdef GRUB_MACHINE_EFI + if (state[SEARCH_HINT_EFI].set) + for (i = 0; state[SEARCH_HINT_EFI].args[i]; i++) + hints[j++] = state[SEARCH_HINT_EFI].args[i]; +#endif + +#ifdef GRUB_MACHINE_ARC + if (state[SEARCH_HINT_ARC].set) + for (i = 0; state[SEARCH_HINT_ARC].args[i]; i++) + hints[j++] = state[SEARCH_HINT_ARC].args[i]; +#endif + +#ifdef GRUB_MACHINE_PCBIOS + if (state[SEARCH_HINT_BIOS].set) + for (i = 0; state[SEARCH_HINT_BIOS].args[i]; i++) + hints[j++] = state[SEARCH_HINT_BIOS].args[i]; +#endif + + if (state[SEARCH_HINT_BAREMETAL].set) + for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++) + hints[j++] = state[SEARCH_HINT_BAREMETAL].args[i]; + + /* Skip hints for future platforms. */ + for (j = 0; j < argc; j++) + if (grub_memcmp (args[j], "--hint-", sizeof ("--hint-") - 1) != 0) + break; + + if (argc == j) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no argument specified"); if (state[SEARCH_SET].set) var = state[SEARCH_SET].arg ? state[SEARCH_SET].arg : "root"; if (state[SEARCH_LABEL].set) - grub_search_label (args[0], var, state[SEARCH_NO_FLOPPY].set, - state[SEARCH_HINT].args, nhints); + grub_search_label (args[j], var, state[SEARCH_NO_FLOPPY].set, + hints, nhints); else if (state[SEARCH_FS_UUID].set) - grub_search_fs_uuid (args[0], var, state[SEARCH_NO_FLOPPY].set, - state[SEARCH_HINT].args, nhints); + grub_search_fs_uuid (args[j], var, state[SEARCH_NO_FLOPPY].set, + hints, nhints); else if (state[SEARCH_FILE].set) - grub_search_fs_file (args[0], var, state[SEARCH_NO_FLOPPY].set, - state[SEARCH_HINT].args, nhints); + grub_search_fs_file (args[j], var, state[SEARCH_NO_FLOPPY].set, + hints, nhints); else return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type"); @@ -92,7 +183,8 @@ static grub_extcmd_t cmd; GRUB_MOD_INIT(search) { cmd = - grub_register_extcmd ("search", grub_cmd_search, GRUB_COMMAND_FLAG_EXTRACTOR, + grub_register_extcmd ("search", grub_cmd_search, + GRUB_COMMAND_FLAG_EXTRACTOR | GRUB_COMMAND_ACCEPT_DASH, N_("[-f|-l|-u|-s|-n] [--hint HINT [--hint HINT] ...]" " NAME"), N_("Search devices by file, filesystem label" diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c index 0a935d5c2..7d1e81b30 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -193,8 +193,14 @@ grub_ofdisk_iterate (int (*hook) (const char *name)) if (grub_strncmp (ent->shortest, "cdrom", 5) == 0) continue; - if (hook (ent->shortest)) - return 1; + { + char buffer[sizeof ("ieee1275/") + grub_strlen (env->shortest)]; + char *ptr; + ptr = grub_stpcpy (buffer, "ieee1275/"); + grub_strcpy (ptr, env->shortest); + if (hook (buffer)) + return 1; + } } } return 0; @@ -236,7 +242,10 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) char prop[64]; grub_ssize_t actual; - devpath = compute_dev_path (name); + if (grub_strncmp (devpath, "ieee1275/", sizeof ("ieee1275/") - 1) != 0) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "not IEEE1275 device"); + devpath = compute_dev_path (name + sizeof ("ieee1275/") - 1); if (! devpath) return grub_errno; diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index d3db7e6be..8f30c8a09 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -132,6 +132,7 @@ struct { char *drive; char *device; + int device_map; } map[256]; struct grub_util_biosdisk_data @@ -140,6 +141,7 @@ struct grub_util_biosdisk_data int access_mode; int fd; int is_disk; + int device_map; }; #ifdef __linux__ @@ -242,6 +244,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) data->access_mode = 0; data->fd = -1; data->is_disk = 0; + data->device_map = map[drive].device_map; /* Get the size. */ #if defined(__MINGW32__) @@ -1015,6 +1018,12 @@ read_device_map (const char *dev_map) grub_util_error ("%s:%d: %s", dev_map, lineno, msg); } + if (dev_map[0] == '\0') + { + grub_util_info (_("no device.map")); + return; + } + fp = fopen (dev_map, "r"); if (! fp) { @@ -1055,6 +1064,7 @@ read_device_map (const char *dev_map) map[drive].drive = xmalloc (p - e + sizeof ('\0')); strncpy (map[drive].drive, e, p - e + sizeof ('\0')); map[drive].drive[p - e] = '\0'; + map[drive].device_map = 1; p++; /* Skip leading spaces. */ @@ -1623,7 +1633,10 @@ find_system_device (const char *os_dev, struct stat *st, int convert, int add) grub_util_error (_("device count exceeds limit")); map[i].device = os_disk; - map[i].drive = xstrdup (os_disk); + map[i].drive = xmalloc (sizeof ("hostdisk/") + strlen (os_disk)); + strcpy (map[i].drive, "hostdisk/"); + strcpy (map[i].drive + sizeof ("hostdisk/") - 1, os_disk); + map[i].device_map = 0; return i; } @@ -1818,6 +1831,14 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev) #endif } +const char * +grub_util_biosdisk_get_compatibility_hint (grub_disk_t disk) +{ + if (disk->dev != &grub_util_biosdisk_dev || map[disk->id].device_map) + return disk->name; + return 0; +} + const char * grub_util_biosdisk_get_osdev (grub_disk_t disk) { diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c index f372b6798..2527d8fe9 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -474,7 +474,7 @@ static grub_command_t cmd_clear; static void (*grub_xputs_saved) (const char *str); static const char *features[] = { - "feature_chainloader_bpb", "feature_ntldr" + "feature_chainloader_bpb", "feature_ntldr", "feature_platform_search_hint" }; GRUB_MOD_INIT(normal) diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index 842dff496..b44a573e1 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -28,6 +28,8 @@ char *grub_util_biosdisk_get_grub_dev (const char *os_dev); const char *grub_util_biosdisk_get_osdev (grub_disk_t disk); int grub_util_biosdisk_is_present (const char *name); int grub_util_biosdisk_is_floppy (grub_disk_t disk); +const char * +grub_util_biosdisk_get_compatibility_hint (grub_disk_t disk); grub_err_t grub_util_biosdisk_flush (struct grub_disk *disk); #endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */ diff --git a/util/grub-install.in b/util/grub-install.in index db3a4db98..bf654f741 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -50,7 +50,6 @@ modules= install_device= no_floppy= force_lba= -recheck=no debug=no debug_image= @@ -106,7 +105,6 @@ Install GRUB on your drive. --no-floppy do not probe any floppy drive --allow-floppy Make the drive also bootable as floppy (default for fdX devices). May break on some BIOSes. - --recheck probe a device map even if it already exists --force install even if problems are detected EOF if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then @@ -218,7 +216,7 @@ do --no-floppy) no_floppy="--no-floppy" ;; --recheck) - recheck=yes ;; + ;; --removable) removable=yes ;; @@ -408,27 +406,17 @@ fi # Create the GRUB directory if it is not present. mkdir -p "$grubdir" || exit 1 -# If --recheck is specified, remove the device map, if present. -if test $recheck = yes; then - rm -f "$device_map" -fi - # Create the device map file if it is not present. if test -f "$device_map"; then - : + # Make sure that there is no duplicated entry. + tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' "$device_map" \ + | sort | uniq -d | sed -n 1p` + if test -n "$tmp"; then + echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2 + exit 1 + fi else - # Create a safe temporary file. - test -n "$mklog" && log_file=`$mklog` - - "$grub_mkdevicemap" "--device-map=$device_map" $no_floppy || exit 1 -fi - -# Make sure that there is no duplicated entry. -tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' "$device_map" \ - | sort | uniq -d | sed -n 1p` -if test -n "$tmp"; then - echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2 - exit 1 + device_map= fi # Copy the GRUB images to the GRUB directory. @@ -536,7 +524,22 @@ if [ "x${devabstraction_module}" = "x" ] ; then exit 1 fi - echo "search.fs_uuid ${uuid} root " >> "${grubdir}/load.cfg" + + if [ x"$disk_module" != x ] && [ x"$disk_module" != xbiosdisk ]; then + hints="`"$grub_probe" --device-map="${device_map}" --target=baremetal_hints --device "${grub_device}"`" + elif [ x"$platform" = xpc ]; then + hints="`"$grub_probe" --device-map="${device_map}" --target=bios_hints --device "${grub_device}"`" + elif [ x"$platform" = xefi ]; then + hints="`"$grub_probe" --device-map="${device_map}" --target=efi_hints --device "${grub_device}"`" + elif [ x"$platform" = xieee1275 ]; then + hints="`"$grub_probe" --device-map="${device_map}" --target=ieee1275_hints --device "${grub_device}"`" + elif [ x"$platform" = xloongson ] || [ x"$platform" = xqemu ] || [ x"$platform" = xcoreboot ] || [ x"$platform" = xmultiboot ] || [ x"$platform" = xqemu-mips ]; then + hints="`"$grub_probe" --device-map="${device_map}" --target=baremetal_hints --device "${grub_device}"`" + else + echo "No hints available for your platform. Expect reduced performance" + hints= + fi + echo "search.fs_uuid ${uuid} root $hints " >> "${grubdir}/load.cfg" echo 'set prefix=($root)'"${relative_grubdir}" >> "${grubdir}/load.cfg" config_opt="-c ${grubdir}/load.cfg " modules="$modules search_fs_uuid" diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index afc66f886..1917da7a1 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -36,7 +36,6 @@ grub_mkconfig_dir=${sysconfdir}/grub.d self=`basename $0` -grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed "${transform}"` grub_probe=${sbindir}/`echo grub-probe | sed "${transform}"` grub_script_check="${bindir}/`echo grub-script-check | sed "${transform}"`" @@ -118,14 +117,6 @@ if [ "$EUID" != 0 ] ; then fi fi -set $grub_mkdevicemap dummy -if test -f "$1"; then - : -else - echo "$1: Not found." 1>&2 - exit 1 -fi - set $grub_probe dummy if test -f "$1"; then : @@ -136,10 +127,6 @@ fi mkdir -p ${GRUB_PREFIX} -if test -e ${GRUB_PREFIX}/device.map ; then : ; else - ${grub_mkdevicemap} -fi - # Device containing our userland. Typically used for root= parameter. GRUB_DEVICE="`${grub_probe} --target=device /`" GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 2c5fd8c6f..8303edd86 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -128,9 +128,14 @@ prepare_grub_to_access_device () # If there's a filesystem UUID that GRUB is capable of identifying, use it; # otherwise set root as per value in device.map. - echo "set root='`"${grub_probe}" --device "${device}" --target=drive`'" + echo "set root='`"${grub_probe}" --device "${device}" --target=compatibility_hint`'" if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then - echo "search --no-floppy --fs-uuid --set=root ${fs_uuid}" + hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" + echo "if [ x$feature_platform_search_hint = xy ]; then" + echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}" + echo "else" + echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}" + echo "fi" fi } diff --git a/util/grub-probe.c b/util/grub-probe.c index 0d5dac902..b486a82e5 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include @@ -54,6 +56,13 @@ enum { PRINT_DEVICE, PRINT_PARTMAP, PRINT_ABSTRACTION, + PRINT_HINT_STR, + PRINT_BIOS_HINT, + PRINT_IEEE1275_HINT, + PRINT_BAREMETAL_HINT, + PRINT_EFI_HINT, + PRINT_ARC_HINT, + PRINT_COMPATIBILITY_HINT }; int print = PRINT_FS; @@ -88,6 +97,131 @@ probe_raid_level (grub_disk_t disk) return ((struct grub_raid_array *) disk->data)->level; } +/* Since OF path names can have "," characters in them, and GRUB + internally uses "," to indicate partitions (unlike OF which uses + ":" for this purpose) we escape such commas. */ +static char * +escape_of_path (const char *orig_path) +{ + char *new_path, *d, c; + const char *p; + + if (!strchr (orig_path, ',')) + return (char *) orig_path; + + new_path = xmalloc (strlen (orig_path) * 2 + sizeof ("ieee1275/")); + + p = orig_path; + grub_strcpy (new_path, "ieee1275/"); + d = new_path + sizeof ("ieee1275/") - 1; + while ((c = *p++) != '\0') + { + if (c == ',') + *d++ = '\\'; + *d++ = c; + } + + free ((char *) orig_path); + + return new_path; +} + +static char * +guess_bios_drive (const char *orig_path) +{ + char *canon; + char *ptr; + canon = canonicalize_file_name (orig_path); + if (!canon) + return NULL; + ptr = strrchr (orig_path, '/'); + if (ptr) + ptr++; + else + ptr = canon; + if ((ptr[0] == 's' || ptr[0] == 'h') && ptr[1] == 'd') + { + int num = ptr[2] - 'a'; + free (canon); + return xasprintf ("hd%d", num); + } + if (ptr[0] == 'f' && ptr[1] == 'd') + { + int num = atoi (ptr + 2); + free (canon); + return xasprintf ("fd%d", num); + } + free (canon); + return NULL; +} + +static char * +guess_efi_drive (const char *orig_path) +{ + char *canon; + char *ptr; + canon = canonicalize_file_name (orig_path); + if (!canon) + return NULL; + ptr = strrchr (orig_path, '/'); + if (ptr) + ptr++; + else + ptr = canon; + if ((ptr[0] == 's' || ptr[0] == 'h') && ptr[1] == 'd') + { + int num = ptr[2] - 'a'; + free (canon); + return xasprintf ("hd%d", num); + } + if (ptr[0] == 'f' && ptr[1] == 'd') + { + int num = atoi (ptr + 2); + free (canon); + return xasprintf ("fd%d", num); + } + free (canon); + return NULL; +} + +static char * +guess_baremetal_drive (const char *orig_path) +{ + char *canon; + char *ptr; + canon = canonicalize_file_name (orig_path); + if (!canon) + return NULL; + ptr = strrchr (orig_path, '/'); + if (ptr) + ptr++; + else + ptr = canon; + if (ptr[0] == 'h' && ptr[1] == 'd') + { + int num = ptr[2] - 'a'; + free (canon); + return xasprintf ("ata%d", num); + } + if (ptr[0] == 's' && ptr[1] == 'd') + { + int num = ptr[2] - 'a'; + free (canon); + return xasprintf ("ahci%d", num); + } + free (canon); + return NULL; +} + +static void +print_full_name (const char *drive, grub_device_t dev) +{ + if (dev->disk->partition) + printf ("%s,%s", drive, grub_partition_get_name (dev->disk->partition)); + else + printf ("%s", drive); +} + static void probe (const char *path, char *device_name) { @@ -134,6 +268,173 @@ probe (const char *path, char *device_name) if (! dev) grub_util_error ("%s", grub_errmsg); + if (print == PRINT_HINT_STR) + { + const char *orig_path = grub_util_devname_to_ofpath (device_name); + char *ofpath = escape_of_path (orig_path); + char *biosname, *bare, *efi; + const char *map; + + printf ("--hint-ieee1275="); + print_full_name (ofpath, dev); + printf (" "); + free (ofpath); + + biosname = guess_bios_drive (device_name); + if (biosname) + { + printf ("--hint-bios="); + print_full_name (biosname, dev); + printf (" "); + } + free (biosname); + + efi = guess_efi_drive (device_name); + if (efi) + { + printf ("--hint-efi="); + print_full_name (efi, dev); + printf (" "); + } + free (efi); + + bare = guess_baremetal_drive (device_name); + if (bare) + { + printf ("--hint-baremetal="); + print_full_name (bare, dev); + printf (" "); + } + free (biosname); + + /* FIXME: Add ARC hint. */ + + map = grub_util_biosdisk_get_compatibility_hint (dev->disk); + if (map) + { + printf ("--hint="); + print_full_name (map, dev); + printf (" "); + } + printf ("\n"); + + goto end; + } + + if (print == PRINT_COMPATIBILITY_HINT) + { + const char *map; + char *biosname; + map = grub_util_biosdisk_get_compatibility_hint (dev->disk); + if (map) + { + printf ("%s\n", map); + goto end; + } + biosname = guess_bios_drive (device_name); + if (biosname) + print_full_name (biosname, dev); + printf ("\n"); + free (biosname); + goto end; + } + + if (print == PRINT_BIOS_HINT) + { + char *biosname; + biosname = guess_bios_drive (device_name); + if (biosname) + print_full_name (biosname, dev); + printf ("\n"); + free (biosname); + goto end; + } + if (print == PRINT_IEEE1275_HINT) + { + const char *orig_path = grub_util_devname_to_ofpath (device_name); + char *ofpath = escape_of_path (orig_path); + const char *map; + + map = grub_util_biosdisk_get_compatibility_hint (dev->disk); + if (map) + { + printf (" "); + print_full_name (map, dev); + } + + printf (" "); + print_full_name (ofpath, dev); + + printf ("\n"); + free (ofpath); + goto end; + } + if (print == PRINT_EFI_HINT) + { + char *biosname; + char *name; + const char *map; + biosname = guess_efi_drive (device_name); + + map = grub_util_biosdisk_get_compatibility_hint (dev->disk); + if (map) + { + printf (" "); + print_full_name (map, dev); + } + if (biosname) + { + printf (" "); + print_full_name (biosname, dev); + } + + printf ("\n"); + free (biosname); + goto end; + } + + if (print == PRINT_BAREMETAL_HINT) + { + char *biosname; + char *name; + const char *map; + + biosname = guess_baremetal_drive (device_name); + + map = grub_util_biosdisk_get_compatibility_hint (dev->disk); + if (map) + { + printf (" "); + print_full_name (map, dev); + } + if (biosname) + { + printf (" "); + print_full_name (biosname, dev); + } + + printf ("\n"); + free (biosname); + goto end; + } + + if (print == PRINT_ARC_HINT) + { + const char *map; + + map = grub_util_biosdisk_get_compatibility_hint (dev->disk); + if (map) + { + printf (" "); + print_full_name (map, dev); + } + printf ("\n"); + + /* FIXME */ + + goto end; + } + if (print == PRINT_ABSTRACTION) { grub_disk_memberlist_t list = NULL, tmp; @@ -348,6 +649,20 @@ main (int argc, char *argv[]) print = PRINT_PARTMAP; else if (!strcmp (optarg, "abstraction")) print = PRINT_ABSTRACTION; + else if (!strcmp (optarg, "hints_string")) + print = PRINT_HINT_STR; + else if (!strcmp (optarg, "bios_hints")) + print = PRINT_BIOS_HINT; + else if (!strcmp (optarg, "ieee1275_hints")) + print = PRINT_IEEE1275_HINT; + else if (!strcmp (optarg, "baremetal_hints")) + print = PRINT_BAREMETAL_HINT; + else if (!strcmp (optarg, "efi_hints")) + print = PRINT_EFI_HINT; + else if (!strcmp (optarg, "arc_hints")) + print = PRINT_ARC_HINT; + else if (!strcmp (optarg, "compatibility_hint")) + print = PRINT_COMPATIBILITY_HINT; else usage (1); break; diff --git a/util/ieee1275/devicemap.c b/util/ieee1275/devicemap.c deleted file mode 100644 index 19ab746ef..000000000 --- a/util/ieee1275/devicemap.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -#include -#include -#include -#include - -/* Since OF path names can have "," characters in them, and GRUB - internally uses "," to indicate partitions (unlike OF which uses - ":" for this purpose) we escape such commas. */ - -static char * -escape_of_path (const char *orig_path) -{ - char *new_path, *d, c; - const char *p; - - if (!strchr (orig_path, ',')) - return (char *) orig_path; - - new_path = xmalloc (strlen (orig_path) * 2); - - p = orig_path; - d = new_path; - while ((c = *p++) != '\0') - { - if (c == ',') - *d++ = '\\'; - *d++ = c; - } - - free ((char *) orig_path); - - return new_path; -} - -void -grub_util_emit_devicemap_entry (FILE *fp, char *name, - int is_floppy __attribute__((unused)), - int *num_fd __attribute__((unused)), - int *num_hd __attribute__((unused))) -{ - const char *orig_path = grub_util_devname_to_ofpath (name); - char *ofpath = escape_of_path (orig_path); - - fprintf(fp, "(%s)\t%s\n", ofpath, name); - - free (ofpath); -} From 298050285086407f07e0c0821c3bba2131792768 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 23 Dec 2011 19:25:24 +0100 Subject: [PATCH 2/7] Fix few bugs and memory leaks --- grub-core/kern/emu/hostdisk.c | 1 + util/getroot.c | 2 +- util/grub-mkconfig_lib.in | 2 +- util/grub-probe.c | 26 ++++++++---- util/ieee1275/ofpath.c | 77 +++++++++++++++++++++++++---------- 5 files changed, 75 insertions(+), 33 deletions(-) diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index d9cf07cf4..b3d35dd43 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -1940,6 +1940,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev) name = grub_xasprintf ("%s,%s", disk->name, partname); free (partname); + grub_disk_close (disk); return name; } diff --git a/util/getroot.c b/util/getroot.c index a4bc9f0af..967e4b62b 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -1159,7 +1159,7 @@ grub_util_pull_device (const char *os_dev) return; default: /* GRUB_DEV_ABSTRACTION_NONE */ - grub_util_biosdisk_get_grub_dev (os_dev); + free (grub_util_biosdisk_get_grub_dev (os_dev)); return; } } diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 13897986b..d7549c540 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -149,7 +149,7 @@ prepare_grub_to_access_device () echo "set root='`"${grub_probe}" --device "${device}" --target=compatibility_hint`'" if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" - echo "if [ x$feature_platform_search_hint = xy ]; then" + echo "if [ x\$feature_platform_search_hint = xy ]; then" echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}" echo "else" echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}" diff --git a/util/grub-probe.c b/util/grub-probe.c index e33a2ad10..250044637 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -67,7 +67,7 @@ enum { PRINT_COMPATIBILITY_HINT }; -int print = PRINT_FS; +static int print = PRINT_FS; static unsigned int argument_is_device = 0; static void @@ -253,7 +253,11 @@ static void print_full_name (const char *drive, grub_device_t dev) { if (dev->disk->partition) - printf ("%s,%s", drive, grub_partition_get_name (dev->disk->partition)); + { + char *pname = grub_partition_get_name (dev->disk->partition); + printf ("%s,%s", drive, pname); + free (pname); + } else printf ("%s", drive); } @@ -347,14 +351,17 @@ probe (const char *path, char *device_name) if (print == PRINT_HINT_STR) { const char *orig_path = grub_util_devname_to_ofpath (device_name); - char *ofpath = escape_of_path (orig_path); char *biosname, *bare, *efi; const char *map; - printf ("--hint-ieee1275="); - print_full_name (ofpath, dev); - printf (" "); - free (ofpath); + if (orig_path) + { + char *ofpath = escape_of_path (orig_path); + printf ("--hint-ieee1275="); + print_full_name (ofpath, dev); + printf (" "); + free (ofpath); + } biosname = guess_bios_drive (device_name); if (biosname) @@ -381,7 +388,7 @@ probe (const char *path, char *device_name) print_full_name (bare, dev); printf (" "); } - free (biosname); + free (bare); /* FIXME: Add ARC hint. */ @@ -404,7 +411,8 @@ probe (const char *path, char *device_name) map = grub_util_biosdisk_get_compatibility_hint (dev->disk); if (map) { - printf ("%s\n", map); + print_full_name (map, dev); + printf ("\n"); goto end; } biosname = guess_bios_drive (device_name); diff --git a/util/ieee1275/ofpath.c b/util/ieee1275/ofpath.c index 20a571191..69319d58a 100644 --- a/util/ieee1275/ofpath.c +++ b/util/ieee1275/ofpath.c @@ -85,8 +85,8 @@ trim_newline (char *path) #define OF_PATH_MAX 256 -static void -find_obppath(char *of_path, const char *sysfs_path_orig) +static int +find_obppath (char *of_path, const char *sysfs_path_orig) { char *sysfs_path, *path; @@ -108,8 +108,14 @@ find_obppath(char *of_path, const char *sysfs_path_orig) { kill_trailing_dir(sysfs_path); if (!strcmp(sysfs_path, "/sys")) - grub_util_error(_("'obppath' not found in parent dirs of %s"), - sysfs_path_orig); + { + grub_util_info (_("'obppath' not found in parent dirs of %s," + " no IEEE1275 name discovery"), + sysfs_path_orig); + free (path); + free (sysfs_path); + return 1; + } continue; } memset(of_path, 0, OF_PATH_MAX); @@ -122,6 +128,7 @@ find_obppath(char *of_path, const char *sysfs_path_orig) free (path); free (sysfs_path); + return 0; } static void @@ -159,14 +166,15 @@ trailing_digits (const char *p) return end + 1; } -static void +static int __of_path_common(char *of_path, char *sysfs_path, const char *device, int devno) { const char *digit_string; char disk[64]; - find_obppath(of_path, sysfs_path); + if (find_obppath(of_path, sysfs_path)) + return 1; digit_string = trailing_digits (device); if (*digit_string == '\0') @@ -181,6 +189,7 @@ __of_path_common(char *of_path, char *sysfs_path, sprintf(disk, "/disk@%d:%c", devno, 'a' + (part - 1)); } strcat(of_path, disk); + return 0; } static char * @@ -198,7 +207,7 @@ get_basename(char *p) return ret; } -static void +static int of_path_of_vdisk(char *of_path, const char *devname __attribute__((unused)), const char *device, @@ -207,18 +216,20 @@ of_path_of_vdisk(char *of_path, { char *sysfs_path, *p; int devno, junk; + int ret; sysfs_path = xmalloc (PATH_MAX); block_device_get_sysfs_path_and_link(devicenode, sysfs_path, PATH_MAX); p = get_basename (sysfs_path); sscanf(p, "vdc-port-%d-%d", &devno, &junk); - __of_path_common(of_path, sysfs_path, device, devno); + ret = __of_path_common(of_path, sysfs_path, device, devno); free (sysfs_path); + return ret; } -static void +static int of_path_of_ide(char *of_path, const char *devname __attribute__((unused)), const char *device, const char *devnode __attribute__((unused)), @@ -226,6 +237,7 @@ of_path_of_ide(char *of_path, { char *sysfs_path, *p; int chan, devno; + int ret; sysfs_path = xmalloc (PATH_MAX); block_device_get_sysfs_path_and_link(devicenode, @@ -233,9 +245,10 @@ of_path_of_ide(char *of_path, p = get_basename (sysfs_path); sscanf(p, "%d.%d", &chan, &devno); - __of_path_common(of_path, sysfs_path, device, devno); + ret = __of_path_common(of_path, sysfs_path, device, devno); free (sysfs_path); + return ret; } static int @@ -258,10 +271,13 @@ vendor_is_ATA(const char *path) close(fd); - free (buf); - if (!strncmp(buf, "ATA", 3)) - return 1; + { + free (buf); + return 1; + } + + free (buf); return 0; } @@ -302,7 +318,7 @@ check_sas (char *sysfs_path, int *tgt) close (fd); } -static void +static int of_path_of_scsi(char *of_path, const char *devname __attribute__((unused)), const char *device, const char *devnode __attribute__((unused)), @@ -311,6 +327,7 @@ of_path_of_scsi(char *of_path, const char *p, *digit_string, *disk_name; int host, bus, tgt, lun; char *sysfs_path, disk[64]; + int ret; sysfs_path = xmalloc (PATH_MAX); @@ -322,13 +339,15 @@ of_path_of_scsi(char *of_path, if (vendor_is_ATA(sysfs_path)) { - __of_path_common(of_path, sysfs_path, device, tgt); + ret = __of_path_common(of_path, sysfs_path, device, tgt); free (sysfs_path); - return; + return ret; } - find_obppath(of_path, sysfs_path); + ret = find_obppath(of_path, sysfs_path); free (sysfs_path); + if (ret) + return 1; if (strstr (of_path, "qlc")) strcat (of_path, "/fp@0,0"); @@ -351,6 +370,7 @@ of_path_of_scsi(char *of_path, sprintf(disk, "/%s@%x,%d:%c", disk_name, tgt, lun, 'a' + (part - 1)); } strcat(of_path, disk); + return 0; } static char * @@ -374,6 +394,7 @@ char * grub_util_devname_to_ofpath (const char *devname) { char *name_buf, *device, *devnode, *devicenode, *ofpath; + int ret; name_buf = xmalloc (PATH_MAX); name_buf = realpath (devname, name_buf); @@ -387,25 +408,37 @@ grub_util_devname_to_ofpath (const char *devname) ofpath = xmalloc (OF_PATH_MAX); if (device[0] == 'h' && device[1] == 'd') - of_path_of_ide(ofpath, name_buf, device, devnode, devicenode); + ret = of_path_of_ide(ofpath, name_buf, device, devnode, devicenode); else if (device[0] == 's' && (device[1] == 'd' || device[1] == 'r')) - of_path_of_scsi(ofpath, name_buf, device, devnode, devicenode); + ret = of_path_of_scsi(ofpath, name_buf, device, devnode, devicenode); else if (device[0] == 'v' && device[1] == 'd' && device[2] == 'i' && device[3] == 's' && device[4] == 'k') - of_path_of_vdisk(ofpath, name_buf, device, devnode, devicenode); + ret = of_path_of_vdisk(ofpath, name_buf, device, devnode, devicenode); else if (device[0] == 'f' && device[1] == 'd' && device[2] == '0' && device[3] == '\0') /* All the models I've seen have a devalias "floppy". New models have no floppy at all. */ - strcpy (ofpath, "floppy"); + { + strcpy (ofpath, "floppy"); + ret = 0; + } else - grub_util_error (_("unknown device type %s\n"), device); + { + grub_util_warn (_("unknown device type %s\n"), device); + return NULL; + } free (devnode); free (devicenode); free (name_buf); + if (ret) + { + free (ofpath); + return NULL; + } + return ofpath; } From aa68ca1250102119cc3e4db557455b048c09f5b7 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 23 Dec 2011 21:13:09 +0100 Subject: [PATCH 3/7] simplify lib/arg.c and allow purely long options --- grub-core/lib/arg.c | 73 +++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 46 deletions(-) diff --git a/grub-core/lib/arg.c b/grub-core/lib/arg.c index 75b1dd53c..a8a508384 100644 --- a/grub-core/lib/arg.c +++ b/grub-core/lib/arg.c @@ -25,14 +25,11 @@ #include /* Built-in parser for default options. */ -#define SHORT_ARG_HELP -100 -#define SHORT_ARG_USAGE -101 - static const struct grub_arg_option help_options[] = { - {"help", SHORT_ARG_HELP, 0, + {"help", 0, 0, N_("Display this help and exit."), 0, ARG_TYPE_NONE}, - {"usage", SHORT_ARG_USAGE, 0, + {"usage", 0, 0, N_("Display the usage of this command and exit."), 0, ARG_TYPE_NONE}, {0, 0, 0, 0, 0, 0} }; @@ -125,9 +122,9 @@ grub_arg_show_help (grub_extcmd_t cmd) if (opt->shortarg && grub_isgraph (opt->shortarg)) grub_printf ("-%c%c ", opt->shortarg, opt->longarg ? ',':' '); - else if (opt->shortarg == SHORT_ARG_HELP && ! h_is_used) + else if (opt == help_options && ! h_is_used) grub_printf ("-h, "); - else if (opt->shortarg == SHORT_ARG_USAGE && ! u_is_used) + else if (opt == help_options + 1 && ! u_is_used) grub_printf ("-u, "); else grub_printf (" "); @@ -180,50 +177,34 @@ grub_arg_show_help (grub_extcmd_t cmd) static int -parse_option (grub_extcmd_t cmd, int key, char *arg, struct grub_arg_list *usr) +parse_option (grub_extcmd_t cmd, const struct grub_arg_option *opt, + char *arg, struct grub_arg_list *usr) { - switch (key) + if (opt == help_options) { - case SHORT_ARG_HELP: grub_arg_show_help (cmd); return -1; + } - case SHORT_ARG_USAGE: + if (opt == help_options + 1) + { show_usage (cmd); return -1; - - default: - { - int found = -1; - int i = 0; - const struct grub_arg_option *opt = cmd->options; - - while (opt->doc) - { - if (opt->shortarg && key == opt->shortarg) - { - found = i; - break; - } - opt++; - i++; - } - - if (found == -1) - return -1; - - if (opt->flags & GRUB_ARG_OPTION_REPEATABLE) - { - usr[found].args[usr[found].set++] = arg; - usr[found].args[usr[found].set] = NULL; - } - else - { - usr[found].set = 1; - usr[found].arg = arg; - } - } } + { + int found = opt - cmd->options; + + if (opt->flags & GRUB_ARG_OPTION_REPEATABLE) + { + usr[found].args[usr[found].set++] = arg; + usr[found].args[usr[found].set] = NULL; + } + else + { + usr[found].set = 1; + usr[found].arg = arg; + } + } return 0; } @@ -307,7 +288,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv, it can have an argument value. */ if (*curshort) { - if (parse_option (cmd, opt->shortarg, 0, usr) || grub_errno) + if (parse_option (cmd, opt, 0, usr) || grub_errno) goto fail; } else @@ -411,7 +392,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv, /* XXX: Not implemented. */ break; } - if (parse_option (cmd, opt->shortarg, option, usr) || grub_errno) + if (parse_option (cmd, opt, option, usr) || grub_errno) goto fail; } else @@ -424,7 +405,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv, goto fail; } - if (parse_option (cmd, opt->shortarg, 0, usr) || grub_errno) + if (parse_option (cmd, opt, 0, usr) || grub_errno) goto fail; } } From 706c46bdcadf982cda31065ca331c782af960726 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 23 Dec 2011 21:14:24 +0100 Subject: [PATCH 4/7] Fix *end restoring --- grub-core/commands/search.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c index ba80d80ef..efb44c25e 100644 --- a/grub-core/commands/search.c +++ b/grub-core/commands/search.c @@ -164,17 +164,20 @@ FUNC_NAME (const char *key, const char *var, int no_floppy, dev = grub_device_open (hints[i]); if (!dev) { - *end = ','; + if (!*end) + *end = ','; continue; } if (!dev->disk) { grub_device_close (dev); - *end = ','; + if (!*end) + *end = ','; continue; } ret = grub_partition_iterate (dev->disk, part_hook); - *end = ','; + if (!*end) + *end = ','; grub_device_close (dev); if (ret) return; From f4d5a8ce563a2ee21c98f09ebd0f89b0507085f4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 23 Dec 2011 21:14:34 +0100 Subject: [PATCH 5/7] search cache --- grub-core/commands/search.c | 69 +++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c index efb44c25e..d5117baef 100644 --- a/grub-core/commands/search.c +++ b/grub-core/commands/search.c @@ -33,11 +33,21 @@ GRUB_MOD_LICENSE ("GPLv3+"); +struct cache_entry +{ + struct cache_entry *next; + char *key; + char *value; +}; + +static struct cache_entry *cache; + void FUNC_NAME (const char *key, const char *var, int no_floppy, char **hints, unsigned nhints) { int count = 0; + int is_cache = 0; grub_fs_autoload_hook_t saved_autoload; auto int iterate_device (const char *name); @@ -50,6 +60,12 @@ FUNC_NAME (const char *key, const char *var, int no_floppy, name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9') return 0; +#ifdef DO_SEARCH_FS_UUID +#define compare_fn grub_strcasecmp +#else +#define compare_fn grub_strcmp +#endif + #ifdef DO_SEARCH_FILE { char *buf; @@ -81,10 +97,8 @@ FUNC_NAME (const char *key, const char *var, int no_floppy, fs = grub_fs_probe (dev); #ifdef DO_SEARCH_FS_UUID -#define compare_fn grub_strcasecmp #define read_fn uuid #else -#define compare_fn grub_strcmp #define read_fn label #endif @@ -106,6 +120,31 @@ FUNC_NAME (const char *key, const char *var, int no_floppy, } #endif + if (!is_cache && found && count == 0) + { + struct cache_entry *cache_ent; + cache_ent = grub_malloc (sizeof (*cache_ent)); + if (cache_ent) + { + cache_ent->key = grub_strdup (key); + cache_ent->value = grub_strdup (name); + if (cache_ent->value && cache_ent->key) + { + cache_ent->next = cache; + cache = cache_ent; + } + else + { + grub_free (cache_ent->value); + grub_free (cache_ent->key); + grub_free (cache_ent); + grub_errno = GRUB_ERR_NONE; + } + } + else + grub_errno = GRUB_ERR_NONE; + } + if (found) { count++; @@ -143,6 +182,32 @@ FUNC_NAME (const char *key, const char *var, int no_floppy, void try (void) { unsigned i; + struct cache_entry **prev; + struct cache_entry *cache_ent; + + for (prev = &cache, cache_ent = *prev; cache_ent; + prev = &cache_ent->next, cache_ent = *prev) + if (compare_fn (cache_ent->key, key) == 0) + break; + if (cache_ent) + { + is_cache = 1; + if (iterate_device (cache_ent->value)) + { + is_cache = 0; + return; + } + is_cache = 0; + /* Cache entry was outdated. Remove it. */ + if (!count) + { + grub_free (cache_ent->key); + grub_free (cache_ent->value); + grub_free (cache_ent); + *prev = cache_ent->next; + } + } + for (i = 0; i < nhints; i++) { char *end; From 93d0a0011607da7301505365a6bd26091d8930b4 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 24 Dec 2011 02:54:28 +0100 Subject: [PATCH 6/7] Fix IEEE1275 bugs in grub-probe --- util/grub-probe.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/util/grub-probe.c b/util/grub-probe.c index 250044637..ba96b8973 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -156,6 +156,7 @@ escape_of_path (const char *orig_path) *d++ = '\\'; *d++ = c; } + *d = 0; free ((char *) orig_path); @@ -350,16 +351,17 @@ probe (const char *path, char *device_name) if (print == PRINT_HINT_STR) { - const char *orig_path = grub_util_devname_to_ofpath (device_name); + const char *osdev = grub_util_biosdisk_get_osdev (dev->disk); + const char *orig_path = grub_util_devname_to_ofpath (osdev); char *biosname, *bare, *efi; const char *map; if (orig_path) { char *ofpath = escape_of_path (orig_path); - printf ("--hint-ieee1275="); + printf ("--hint-ieee1275='"); print_full_name (ofpath, dev); - printf (" "); + printf ("' "); free (ofpath); } @@ -395,9 +397,9 @@ probe (const char *path, char *device_name) map = grub_util_biosdisk_get_compatibility_hint (dev->disk); if (map) { - printf ("--hint="); + printf ("--hint='"); print_full_name (map, dev); - printf (" "); + printf ("' "); } printf ("\n"); @@ -435,7 +437,8 @@ probe (const char *path, char *device_name) } if (print == PRINT_IEEE1275_HINT) { - const char *orig_path = grub_util_devname_to_ofpath (device_name); + const char *osdev = grub_util_biosdisk_get_osdev (dev->disk); + const char *orig_path = grub_util_devname_to_ofpath (osdev); char *ofpath = escape_of_path (orig_path); const char *map; From a141ef409f518bd02ccae40fe7f94242dd145656 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 24 Dec 2011 13:37:28 +0100 Subject: [PATCH 7/7] Put recheck back --- util/grub-install.in | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/grub-install.in b/util/grub-install.in index dd31a6caf..e58ed9ab3 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -51,6 +51,7 @@ modules= install_device= no_floppy= force_lba= +recheck=no debug=no debug_image= @@ -106,6 +107,7 @@ Install GRUB on your drive. --no-floppy do not probe any floppy drive --allow-floppy Make the drive also bootable as floppy (default for fdX devices). May break on some BIOSes. + --recheck delete device map if it already exists --force install even if problems are detected EOF if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then @@ -217,7 +219,7 @@ do --no-floppy) no_floppy="--no-floppy" ;; --recheck) - ;; + recheck=yes ;; --removable) removable=yes ;; @@ -415,6 +417,11 @@ fi # Create the GRUB directory if it is not present. mkdir -p "$grubdir" || exit 1 +# If --recheck is specified, remove the device map, if present. +if test $recheck = yes; then + rm -f "$device_map" +fi + # Create the device map file if it is not present. if test -f "$device_map"; then # Make sure that there is no duplicated entry.