Initial integration of hints
This commit is contained in:
parent
9a79fcf2c9
commit
6babad5e59
11 changed files with 489 additions and 106 deletions
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue