merge mainline into emu-mod
This commit is contained in:
commit
19a9fb834b
459 changed files with 26481 additions and 7640 deletions
|
@ -25,32 +25,14 @@
|
|||
#include <grub/device.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/search.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"file", 'f', 0, "Search devices by a file.", 0, 0},
|
||||
{"label", 'l', 0, "Search devices by a filesystem label.", 0, 0},
|
||||
{"fs-uuid", 'u', 0, "Search devices by a filesystem UUID.", 0, 0},
|
||||
{"set", 's', GRUB_ARG_OPTION_OPTIONAL, "Set a variable to the first device found.", "VAR", ARG_TYPE_STRING},
|
||||
{"no-floppy", 'n', 0, "Do not probe any floppy drive.", 0, 0},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
enum options
|
||||
{
|
||||
SEARCH_FILE,
|
||||
SEARCH_LABEL,
|
||||
SEARCH_FS_UUID,
|
||||
SEARCH_SET,
|
||||
SEARCH_NO_FLOPPY,
|
||||
};
|
||||
|
||||
static void
|
||||
search_fs (const char *key, const char *var, int no_floppy, enum options type)
|
||||
void
|
||||
FUNC_NAME (const char *key, const char *var, int no_floppy)
|
||||
{
|
||||
int count = 0;
|
||||
char *buf = NULL;
|
||||
grub_fs_autoload_hook_t saved_autoload;
|
||||
|
||||
auto int iterate_device (const char *name);
|
||||
|
@ -63,48 +45,46 @@ search_fs (const char *key, const char *var, int no_floppy, enum options type)
|
|||
name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9')
|
||||
return 0;
|
||||
|
||||
if (type == SEARCH_FILE)
|
||||
#ifdef DO_SEARCH_FILE
|
||||
{
|
||||
grub_size_t len;
|
||||
char *p;
|
||||
char *buf;
|
||||
grub_file_t file;
|
||||
|
||||
len = grub_strlen (name) + 2 + grub_strlen (key) + 1;
|
||||
p = grub_realloc (buf, len);
|
||||
if (! p)
|
||||
buf = grub_xasprintf ("(%s)%s", name, key);
|
||||
if (! buf)
|
||||
return 1;
|
||||
|
||||
buf = p;
|
||||
grub_sprintf (buf, "(%s)%s", name, key);
|
||||
|
||||
file = grub_file_open (buf);
|
||||
if (file)
|
||||
{
|
||||
found = 1;
|
||||
grub_file_close (file);
|
||||
}
|
||||
grub_free (buf);
|
||||
}
|
||||
else
|
||||
#else
|
||||
{
|
||||
/* type is SEARCH_FS_UUID or SEARCH_LABEL */
|
||||
/* SEARCH_FS_UUID or SEARCH_LABEL */
|
||||
grub_device_t dev;
|
||||
grub_fs_t fs;
|
||||
int (*compare_fn) (const char *, const char *);
|
||||
char *quid;
|
||||
|
||||
dev = grub_device_open (name);
|
||||
if (dev)
|
||||
{
|
||||
fs = grub_fs_probe (dev);
|
||||
compare_fn =
|
||||
(type == SEARCH_FS_UUID) ? grub_strcasecmp : grub_strcmp;
|
||||
|
||||
if (fs && ((type == SEARCH_FS_UUID) ? fs->uuid : fs->label))
|
||||
#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
|
||||
|
||||
if (fs && fs->read_fn)
|
||||
{
|
||||
if (type == SEARCH_FS_UUID)
|
||||
fs->uuid (dev, &quid);
|
||||
else
|
||||
fs->label (dev, &quid);
|
||||
fs->read_fn (dev, &quid);
|
||||
|
||||
if (grub_errno == GRUB_ERR_NONE && quid)
|
||||
{
|
||||
|
@ -118,6 +98,7 @@ search_fs (const char *key, const char *var, int no_floppy, enum options type)
|
|||
grub_device_close (dev);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (found)
|
||||
{
|
||||
|
@ -149,52 +130,45 @@ search_fs (const char *key, const char *var, int no_floppy, enum options type)
|
|||
else
|
||||
grub_device_iterate (iterate_device);
|
||||
|
||||
grub_free (buf);
|
||||
|
||||
if (grub_errno == GRUB_ERR_NONE && count == 0)
|
||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_search (grub_extcmd_t cmd, int argc, char **args)
|
||||
grub_cmd_do_search (grub_command_t cmd __attribute__ ((unused)), int argc,
|
||||
char **args)
|
||||
{
|
||||
struct grub_arg_list *state = cmd->state;
|
||||
const char *var = 0;
|
||||
|
||||
if (argc == 0)
|
||||
return grub_error (GRUB_ERR_INVALID_COMMAND, "no argument specified");
|
||||
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)
|
||||
search_fs (args[0], var, state[SEARCH_NO_FLOPPY].set, SEARCH_LABEL);
|
||||
else if (state[SEARCH_FS_UUID].set)
|
||||
search_fs (args[0], var, state[SEARCH_NO_FLOPPY].set, SEARCH_FS_UUID);
|
||||
else if (state[SEARCH_FILE].set)
|
||||
search_fs (args[0], var, state[SEARCH_NO_FLOPPY].set, SEARCH_FILE);
|
||||
else
|
||||
return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type");
|
||||
FUNC_NAME (args[0], argc == 1 ? 0 : args[1], 0);
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_extcmd_t cmd;
|
||||
static grub_command_t cmd;
|
||||
|
||||
GRUB_MOD_INIT(search)
|
||||
#ifdef DO_SEARCH_FILE
|
||||
GRUB_MOD_INIT(search_fs_file)
|
||||
#elif defined (DO_SEARCH_FS_UUID)
|
||||
GRUB_MOD_INIT(search_fs_uuid)
|
||||
#else
|
||||
GRUB_MOD_INIT(search_label)
|
||||
#endif
|
||||
{
|
||||
cmd =
|
||||
grub_register_extcmd ("search", grub_cmd_search,
|
||||
GRUB_COMMAND_FLAG_BOTH,
|
||||
"search [-f|-l|-u|-s|-n] NAME",
|
||||
"Search devices by file, filesystem label or filesystem UUID."
|
||||
" If --set is specified, the first device found is"
|
||||
" set to a variable. If no variable name is"
|
||||
" specified, \"root\" is used.",
|
||||
options);
|
||||
grub_register_command (COMMAND_NAME, grub_cmd_do_search,
|
||||
N_("NAME [VARIABLE]"),
|
||||
HELP_MESSAGE);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(search)
|
||||
#ifdef DO_SEARCH_FILE
|
||||
GRUB_MOD_FINI(search_fs_file)
|
||||
#elif defined (DO_SEARCH_FS_UUID)
|
||||
GRUB_MOD_FINI(search_fs_uuid)
|
||||
#else
|
||||
GRUB_MOD_FINI(search_label)
|
||||
#endif
|
||||
{
|
||||
grub_unregister_extcmd (cmd);
|
||||
grub_unregister_command (cmd);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue