Integrate hints into autogeneration scripts.

* docs/grub.texi (Filesystems): Add a hostdisk example.
	* Makefile.util.def (grub-mkdevicemap): Remove ofpath.
	(grub-probe): Add ofpath.
	* gentpl.py: Remove group nosparc64.
	* grub-core/commands/search.c (cache_entry): New struct.
	(cache): New var.
	(FUNC_NAME): Use and save cache. Fix handling of trailing comma.
	* grub-core/commands/search_wrap.c (options): Add platform-specific
	hint options.
	(grub_cmd_search): Handle platform-specific hints.
	(GRUB_MOD_INIT): Declare grub_cmd_search as accept_dash.
	* grub-core/kern/emu/hostdisk.c (map): New field device_map.
	(grub_util_biosdisk_data): Likewise.
	(grub_util_biosdisk_open): Set device_map.
	(read_device_map): Handle "" as indication of no map.
	Set device_map.
	(find_system_device): Add hostdisk/ prefix for autogenerated entries.
	(grub_util_biosdisk_get_compatibility_hint): New function.
	* grub-core/normal/main.c (features): Add feature_platform_search_hint.
	* include/grub/emu/hostdisk.h
	(grub_util_biosdisk_get_compatibility_hint): New proto.
	* util/grub-install.in: Don't call grub-mkdevicemap.
	Add platform-specific hint to load.cfg.
	* util/grub-mkconfig.in: Don't call grub-mkdevicemap.
	* util/grub-mkconfig_lib.in (prepare_grub_to_access_device): Add
	hints. Set root preliminary to compatibility hint, not to OS name.
	* util/grub-probe.c (PRINT_*): Add hints.
	(print): Make static.
	(escape_of_path): New function.
	(guess_bios_drive): Likewise.
	(guess_efi_drive): Likewise.
	(guess_baremetal_drive): Likewise.
	(print_full_name): Likewise.
	(probe): Handle hints.
	(main): Likewise.
	* util/ieee1275/devicemap.c: Removed.
	* util/ieee1275/ofpath.c (find_obppath): Allow to fail. All users
	updated.
	(grub_util_devname_to_ofpath): Return NULL on failure.

	* grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_get_grub_dev): Fix
	resource leak.
	* util/getroot.c (grub_util_pull_device): Fix memory leak.

	* po/POTFILES.in: Regenerated.

	Allow purely long options

	* grub-core/lib/arg.c (SHORT_ARG_HELP): Removed.
	(SHORT_ARG_USAGE): Likewise.
	(grub_arg_show_help): Compare opt with help_options.
	(parse_option): Receive opt as argument. If makes big simplificatons.
	All users updated
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-12-24 15:09:26 +01:00
commit d3c13cbd62
19 changed files with 741 additions and 176 deletions

View file

@ -1,3 +1,61 @@
2011-12-24 Vladimir Serbinenko <phcoder@gmail.com>
Integrate hints into autogeneration scripts.
* docs/grub.texi (Filesystems): Add a hostdisk example.
* Makefile.util.def (grub-mkdevicemap): Remove ofpath.
(grub-probe): Add ofpath.
* gentpl.py: Remove group nosparc64.
* grub-core/commands/search.c (cache_entry): New struct.
(cache): New var.
(FUNC_NAME): Use and save cache. Fix handling of trailing comma.
* grub-core/commands/search_wrap.c (options): Add platform-specific
hint options.
(grub_cmd_search): Handle platform-specific hints.
(GRUB_MOD_INIT): Declare grub_cmd_search as accept_dash.
* grub-core/kern/emu/hostdisk.c (map): New field device_map.
(grub_util_biosdisk_data): Likewise.
(grub_util_biosdisk_open): Set device_map.
(read_device_map): Handle "" as indication of no map.
Set device_map.
(find_system_device): Add hostdisk/ prefix for autogenerated entries.
(grub_util_biosdisk_get_compatibility_hint): New function.
* grub-core/normal/main.c (features): Add feature_platform_search_hint.
* include/grub/emu/hostdisk.h
(grub_util_biosdisk_get_compatibility_hint): New proto.
* util/grub-install.in: Don't call grub-mkdevicemap.
Add platform-specific hint to load.cfg.
* util/grub-mkconfig.in: Don't call grub-mkdevicemap.
* util/grub-mkconfig_lib.in (prepare_grub_to_access_device): Add
hints. Set root preliminary to compatibility hint, not to OS name.
* util/grub-probe.c (PRINT_*): Add hints.
(print): Make static.
(escape_of_path): New function.
(guess_bios_drive): Likewise.
(guess_efi_drive): Likewise.
(guess_baremetal_drive): Likewise.
(print_full_name): Likewise.
(probe): Handle hints.
(main): Likewise.
* util/ieee1275/devicemap.c: Removed.
* util/ieee1275/ofpath.c (find_obppath): Allow to fail. All users
updated.
(grub_util_devname_to_ofpath): Return NULL on failure.
* grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_get_grub_dev): Fix
resource leak.
* util/getroot.c (grub_util_pull_device): Fix memory leak.
* po/POTFILES.in: Regenerated.
Allow purely long options
* grub-core/lib/arg.c (SHORT_ARG_HELP): Removed.
(SHORT_ARG_USAGE): Likewise.
(grub_arg_show_help): Compare opt with help_options.
(parse_option): Receive opt as argument. If makes big simplificatons.
All users updated
2011-12-24 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/lib/libgcrypt_wrap/cipher_wrap.h (WORDS_BIGENDIAN):

View file

@ -281,10 +281,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 = libgrubgcry.a;
@ -298,6 +295,7 @@ program = {
installdir = sbin;
mansection = 8;
common = util/grub-probe.c;
common = util/ieee1275/ofpath.c;
ldadd = libgrubmods.a;
ldadd = libgrubgcry.a;

View file

@ -2249,8 +2249,9 @@ RAID (md), ofdisk (ieee1275), LVM (lv) and arcdisk (arc) use intrinsic name
of disk prefixed by driver name. Conflicts are solved by suffixing a number
if necessarry. Commas need to be escaped.
Loopback uses whatever name specified to @command{loopback} command.
Hostdisk uses names specified in device.map or hostdisk/<OS NAME>.
For crypto and RAID (md) additionally you can use the syntax
<driver name>uuid/<uuid>
<driver name>uuid/<uuid>.
@example
(fd0)
@ -2265,10 +2266,11 @@ For crypto and RAID (md) additionally you can use the syntax
(lv/system-root)
(md/myraid)
(md/0)
(ieee1275/disk)
(ieee1275/disk2)
(memdisk)
(host)
(myloop)
(hostdisk//dev/sda)
@end example
@var{part-num} represents the partition number of @var{device}, starting

View file

@ -47,7 +47,6 @@ GROUPS["terminfomodule"] = GRUB_PLATFORMS[:];
for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i)
# Miscelaneous groups schedulded to disappear in future
GROUPS["nosparc64"] = GRUB_PLATFORMS[:]; GROUPS["nosparc64"].remove("sparc64_ieee1275")
GROUPS["i386_coreboot_multiboot_qemu"] = ["i386_coreboot", "i386_multiboot", "i386_qemu"]
GROUPS["nopc"] = GRUB_PLATFORMS[:]; GROUPS["nopc"].remove("i386_pc")

View file

@ -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;
@ -164,17 +229,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;

View file

@ -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"

View file

@ -723,6 +723,8 @@ GRUB_MOD_INIT (tar)
GRUB_MOD_INIT (odc)
#elif defined (MODE_NEWC)
GRUB_MOD_INIT (newc)
#elif defined (MODE_BIGENDIAN)
GRUB_MOD_INIT (cpio_be)
#else
GRUB_MOD_INIT (cpio)
#endif
@ -737,6 +739,8 @@ GRUB_MOD_FINI (tar)
GRUB_MOD_FINI (odc)
#elif defined (MODE_NEWC)
GRUB_MOD_FINI (newc)
#elif defined (MODE_BIGENDIAN)
GRUB_MOD_FINI (cpio_be)
#else
GRUB_MOD_FINI (cpio)
#endif

View file

@ -137,6 +137,7 @@ struct
{
char *drive;
char *device;
int device_map;
} map[256];
struct grub_util_biosdisk_data
@ -145,6 +146,7 @@ struct grub_util_biosdisk_data
int access_mode;
int fd;
int is_disk;
int device_map;
};
#ifdef __linux__
@ -364,6 +366,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__)
@ -1120,6 +1123,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)
{
@ -1160,6 +1169,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. */
@ -1760,7 +1770,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;
}
@ -1927,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;
}
@ -1963,6 +1977,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)
{

View file

@ -25,14 +25,11 @@
#include <grub/i18n.h>
/* 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;
}
}

View file

@ -473,7 +473,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)

View file

@ -29,6 +29,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);
void grub_util_pull_device (const char *osname);
grub_err_t

View file

@ -19,6 +19,7 @@
./grub-core/commands/arc/lsdev.c
./grub-core/commands/blocklist.c
./grub-core/commands/boot.c
./grub-core/commands/cacheinfo.c
./grub-core/commands/cat.c
./grub-core/commands/cmp.c
./grub-core/commands/configfile.c
@ -127,8 +128,12 @@
./grub-core/font/font.c
./grub-core/font/font_cmd.c
./grub-core/fs/affs.c
./grub-core/fs/afs.c
./grub-core/fs/bfs.c
./grub-core/fs/btrfs.c
./grub-core/fs/cpio_be.c
./grub-core/fs/cpio.c
./grub-core/fs/exfat.c
./grub-core/fs/ext2.c
./grub-core/fs/fat.c
./grub-core/fs/fshelp.c
@ -139,9 +144,11 @@
./grub-core/fs/minix2.c
./grub-core/fs/minix3.c
./grub-core/fs/minix.c
./grub-core/fs/newc.c
./grub-core/fs/nilfs2.c
./grub-core/fs/ntfs.c
./grub-core/fs/ntfscomp.c
./grub-core/fs/odc.c
./grub-core/fs/reiserfs.c
./grub-core/fs/romfs.c
./grub-core/fs/sfs.c
@ -152,6 +159,7 @@
./grub-core/fs/ufs.c
./grub-core/fs/xfs.c
./grub-core/fs/zfs/zfs.c
./grub-core/fs/zfs/zfscrypt.c
./grub-core/fs/zfs/zfs_fletcher.c
./grub-core/fs/zfs/zfsinfo.c
./grub-core/fs/zfs/zfs_lzjb.c
@ -231,6 +239,7 @@
./grub-core/hook/datehook.c
./grub-core/io/bufio.c
./grub-core/io/gzio.c
./grub-core/io/lzopio.c
./grub-core/io/xzio.c
./grub-core/kern/command.c
./grub-core/kern/corecmd.c
@ -295,14 +304,17 @@
./grub-core/kern/time.c
./grub-core/kern/vga_init.c
./grub-core/kern/x86_64/dl.c
./grub-core/lib/adler32.c
./grub-core/lib/arc/datetime.c
./grub-core/lib/arg.c
./grub-core/lib/cmdline.c
./grub-core/lib/cmos_datetime.c
./grub-core/lib/crc64.c
./grub-core/lib/crc.c
./grub-core/lib/crypto.c
./grub-core/lib/efi/datetime.c
./grub-core/lib/efi/halt.c
./grub-core/lib/efi/reboot.c
./grub-core/lib/efi/relocator.c
./grub-core/lib/emu/halt.c
./grub-core/lib/envblk.c
@ -310,10 +322,12 @@
./grub-core/lib/i386/halt.c
./grub-core/lib/i386/pc/biosnum.c
./grub-core/lib/i386/pc/vesa_modes_table.c
./grub-core/lib/i386/reboot.c
./grub-core/lib/i386/relocator.c
./grub-core/lib/ieee1275/cmos.c
./grub-core/lib/ieee1275/datetime.c
./grub-core/lib/ieee1275/halt.c
./grub-core/lib/ieee1275/reboot.c
./grub-core/lib/ieee1275/relocator.c
./grub-core/lib/legacy_parse.c
./grub-core/lib/libgcrypt/cipher/ac.c
@ -376,9 +390,14 @@
./grub-core/lib/LzFind.c
./grub-core/lib/LzmaDec.c
./grub-core/lib/LzmaEnc.c
./grub-core/lib/minilzo/minilzo.c
./grub-core/lib/mips/arc/reboot.c
./grub-core/lib/mips/loongson/reboot.c
./grub-core/lib/mips/qemu_mips/reboot.c
./grub-core/lib/mips/relocator.c
./grub-core/lib/pbkdf2.c
./grub-core/lib/powerpc/relocator.c
./grub-core/lib/priority_queue.c
./grub-core/lib/reed_solomon.c
./grub-core/lib/relocator.c
./grub-core/lib/xzembed/xz_dec_bcj.c
@ -399,6 +418,7 @@
./grub-core/loader/i386/pc/freedos.c
./grub-core/loader/i386/pc/linux.c
./grub-core/loader/i386/pc/ntldr.c
./grub-core/loader/i386/pc/plan9.c
./grub-core/loader/i386/xnu.c
./grub-core/loader/ia64/efi/linux.c
./grub-core/loader/macho32.c
@ -421,14 +441,19 @@
./grub-core/mmap/mmap.c
./grub-core/net/arp.c
./grub-core/net/bootp.c
./grub-core/net/dns.c
./grub-core/net/drivers/efi/efinet.c
./grub-core/net/drivers/emu/emunet.c
./grub-core/net/drivers/i386/pc/pxe.c
./grub-core/net/drivers/ieee1275/ofnet.c
./grub-core/net/ethernet.c
./grub-core/net/http.c
./grub-core/net/icmp6.c
./grub-core/net/icmp.c
./grub-core/net/ip.c
./grub-core/net/netbuff.c
./grub-core/net/net.c
./grub-core/net/tcp.c
./grub-core/net/tftp.c
./grub-core/net/udp.c
./grub-core/normal/auth.c
@ -454,6 +479,7 @@
./grub-core/partmap/dvh.c
./grub-core/partmap/gpt.c
./grub-core/partmap/msdos.c
./grub-core/partmap/plan.c
./grub-core/partmap/sun.c
./grub-core/partmap/sunpc.c
./grub-core/parttool/msdospart.c
@ -496,6 +522,7 @@
./grub-core/video/i386/pc/vbe.c
./grub-core/video/i386/pc/vga.c
./grub-core/video/ieee1275.c
./grub-core/video/radeon_fuloong2e.c
./grub-core/video/readers/jpeg.c
./grub-core/video/readers/png.c
./grub-core/video/readers/tga.c
@ -506,6 +533,7 @@
./grub-core/video/video.c
./tests/example_unit_test.c
./tests/lib/unit_test.c
./tests/printf_unit_test.c
./util/bin2h.c
./util/deviceiter.c
./util/devicemap.c
@ -521,11 +549,11 @@
./util/grub-mklayout.c
./util/grub-mkpasswd-pbkdf2.c
./util/grub-mkrelpath.c
./util/grub-mount.c
./util/grub-pe2elf.c
./util/grub-probe.c
./util/grub-script-check.c
./util/grub-setup.c
./util/ieee1275/devicemap.c
./util/ieee1275/grub-ofpathname.c
./util/ieee1275/ofpath.c
./util/lvm.c

View file

@ -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;
}
}

View file

@ -107,7 +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 probe a device map even if it already exists
--recheck delete device map if it already exists
--force install even if problems are detected
EOF
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
@ -424,20 +424,15 @@ 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.
@ -560,7 +555,21 @@ 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"

View file

@ -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

View file

@ -146,9 +146,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
}

View file

@ -33,6 +33,8 @@
#include <grub/env.h>
#include <grub/raid.h>
#include <grub/i18n.h>
#include <grub/emu/misc.h>
#include <grub/util/ofpath.h>
#include <grub/crypto.h>
#include <grub/cryptodisk.h>
@ -55,10 +57,17 @@ enum {
PRINT_DEVICE,
PRINT_PARTMAP,
PRINT_ABSTRACTION,
PRINT_CRYPTODISK_UUID
PRINT_CRYPTODISK_UUID,
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;
static int print = PRINT_FS;
static unsigned int argument_is_device = 0;
static void
@ -124,6 +133,136 @@ 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;
}
*d = 0;
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)
{
char *pname = grub_partition_get_name (dev->disk->partition);
printf ("%s,%s", drive, pname);
free (pname);
}
else
printf ("%s", drive);
}
static void
probe_abstraction (grub_disk_t disk)
{
@ -210,6 +349,179 @@ probe (const char *path, char *device_name)
if (! dev)
grub_util_error ("%s", _(grub_errmsg));
if (print == PRINT_HINT_STR)
{
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='");
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 (bare);
/* 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)
{
print_full_name (map, dev);
printf ("\n");
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 *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;
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)
{
probe_abstraction (dev->disk);
@ -358,6 +670,20 @@ main (int argc, char *argv[])
print = PRINT_ABSTRACTION;
else if (!strcmp (optarg, "cryptodisk_uuid"))
print = PRINT_CRYPTODISK_UUID;
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;

View file

@ -1,49 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <grub/types.h>
#include <grub/util/deviceiter.h>
#include <grub/util/ofpath.h>
#include <grub/util/misc.h>
/* 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);
}

View file

@ -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, 2 * chan + devno);
ret = __of_path_common(of_path, sysfs_path, device, 2 * chan + 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;
}