2009-07-07 Pavel Roskin <proski@gnu.org>
* commands/search.c (search_file): Merge into ... (search_fs): ... this. Accept search type as argument. (grub_cmd_search): Pass search type to search_fs().
This commit is contained in:
parent
25f9a05a03
commit
7d8a52d3a2
2 changed files with 75 additions and 101 deletions
|
@ -1,5 +1,9 @@
|
||||||
2009-07-07 Pavel Roskin <proski@gnu.org>
|
2009-07-07 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
|
* commands/search.c (search_file): Merge into ...
|
||||||
|
(search_fs): ... this. Accept search type as argument.
|
||||||
|
(grub_cmd_search): Pass search type to search_fs().
|
||||||
|
|
||||||
* include/grub/util/console.h: New file.
|
* include/grub/util/console.h: New file.
|
||||||
* util/console.c: Use it instead of grub/machine/console.h.
|
* util/console.c: Use it instead of grub/machine/console.h.
|
||||||
* util/grub-emu.c: Likewise.
|
* util/grub-emu.c: Likewise.
|
||||||
|
|
|
@ -47,126 +47,96 @@ enum options
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
search_fs (const char *key, const char *var, int no_floppy, int is_uuid)
|
search_fs (const char *key, const char *var, int no_floppy, enum options type)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
char *buf = NULL;
|
||||||
|
|
||||||
auto int iterate_device (const char *name);
|
auto int iterate_device (const char *name);
|
||||||
|
|
||||||
int iterate_device (const char *name)
|
int iterate_device (const char *name)
|
||||||
{
|
{
|
||||||
grub_device_t dev;
|
int found = 0;
|
||||||
int abort = 0;
|
|
||||||
|
|
||||||
/* Skip floppy drives when requested. */
|
/* Skip floppy drives when requested. */
|
||||||
if (no_floppy &&
|
if (no_floppy &&
|
||||||
name[0] == 'f' && name[1] == 'd' &&
|
name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9')
|
||||||
name[2] >= '0' && name[2] <= '9')
|
return 0;
|
||||||
return 0;
|
|
||||||
|
|
||||||
dev = grub_device_open (name);
|
if (type == SEARCH_FILE)
|
||||||
if (dev)
|
{
|
||||||
{
|
grub_size_t len;
|
||||||
grub_fs_t fs;
|
char *p;
|
||||||
int (*compare_fn) (const char *, const char *);
|
grub_file_t file;
|
||||||
|
|
||||||
fs = grub_fs_probe (dev);
|
len = grub_strlen (name) + 2 + grub_strlen (key) + 1;
|
||||||
compare_fn = is_uuid ? grub_strcasecmp : grub_strcmp;
|
p = grub_realloc (buf, len);
|
||||||
|
if (! p)
|
||||||
|
return 1;
|
||||||
|
|
||||||
if (fs && (is_uuid ? fs->uuid : fs->label))
|
buf = p;
|
||||||
{
|
grub_sprintf (buf, "(%s)%s", name, key);
|
||||||
char *quid;
|
|
||||||
|
|
||||||
if (is_uuid)
|
file = grub_file_open (buf);
|
||||||
fs->uuid (dev, &quid);
|
if (file)
|
||||||
else
|
{
|
||||||
fs->label (dev, &quid);
|
found = 1;
|
||||||
|
grub_file_close (file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* type is SEARCH_FS_UUID or SEARCH_LABEL */
|
||||||
|
grub_device_t dev;
|
||||||
|
grub_fs_t fs;
|
||||||
|
int (*compare_fn) (const char *, const char *);
|
||||||
|
char *quid;
|
||||||
|
|
||||||
if (grub_errno == GRUB_ERR_NONE && quid)
|
dev = grub_device_open (name);
|
||||||
{
|
if (dev)
|
||||||
if (compare_fn (quid, key) == 0)
|
{
|
||||||
{
|
fs = grub_fs_probe (dev);
|
||||||
/* Found! */
|
compare_fn =
|
||||||
count++;
|
(type == SEARCH_FS_UUID) ? grub_strcasecmp : grub_strcmp;
|
||||||
if (var)
|
|
||||||
{
|
|
||||||
grub_env_set (var, name);
|
|
||||||
abort = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
grub_printf (" %s", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
grub_free (quid);
|
if (fs && ((type == SEARCH_FS_UUID) ? fs->uuid : fs->label))
|
||||||
}
|
{
|
||||||
}
|
if (type == SEARCH_FS_UUID)
|
||||||
|
fs->uuid (dev, &quid);
|
||||||
|
else
|
||||||
|
fs->label (dev, &quid);
|
||||||
|
|
||||||
grub_device_close (dev);
|
if (grub_errno == GRUB_ERR_NONE && quid)
|
||||||
}
|
{
|
||||||
|
if (compare_fn (quid, key) == 0)
|
||||||
|
found = 1;
|
||||||
|
|
||||||
grub_errno = GRUB_ERR_NONE;
|
grub_free (quid);
|
||||||
return abort;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
grub_device_iterate (iterate_device);
|
grub_device_close (dev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (count == 0)
|
if (found)
|
||||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key);
|
{
|
||||||
}
|
count++;
|
||||||
|
if (var)
|
||||||
|
grub_env_set (var, name);
|
||||||
|
else
|
||||||
|
grub_printf (" %s", name);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
grub_errno = GRUB_ERR_NONE;
|
||||||
search_file (const char *key, const char *var, int no_floppy)
|
return (found && var);
|
||||||
{
|
}
|
||||||
int count = 0;
|
|
||||||
char *buf = 0;
|
|
||||||
auto int iterate_device (const char *name);
|
|
||||||
|
|
||||||
int iterate_device (const char *name)
|
|
||||||
{
|
|
||||||
grub_size_t len;
|
|
||||||
char *p;
|
|
||||||
grub_file_t file;
|
|
||||||
int abort = 0;
|
|
||||||
|
|
||||||
/* Skip floppy drives when requested. */
|
|
||||||
if (no_floppy &&
|
|
||||||
name[0] == 'f' && name[1] == 'd' &&
|
|
||||||
name[2] >= '0' && name[2] <= '9')
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
len = grub_strlen (name) + 2 + grub_strlen (key) + 1;
|
|
||||||
p = grub_realloc (buf, len);
|
|
||||||
if (! p)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
buf = p;
|
|
||||||
grub_sprintf (buf, "(%s)%s", name, key);
|
|
||||||
|
|
||||||
file = grub_file_open (buf);
|
|
||||||
if (file)
|
|
||||||
{
|
|
||||||
/* Found! */
|
|
||||||
count++;
|
|
||||||
if (var)
|
|
||||||
{
|
|
||||||
grub_env_set (var, name);
|
|
||||||
abort = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
grub_printf (" %s", name);
|
|
||||||
|
|
||||||
grub_file_close (file);
|
|
||||||
}
|
|
||||||
|
|
||||||
grub_errno = GRUB_ERR_NONE;
|
|
||||||
return abort;
|
|
||||||
}
|
|
||||||
|
|
||||||
grub_device_iterate (iterate_device);
|
grub_device_iterate (iterate_device);
|
||||||
|
|
||||||
grub_free (buf);
|
grub_free (buf);
|
||||||
|
|
||||||
if (grub_errno == GRUB_ERR_NONE && count == 0)
|
if (grub_errno == GRUB_ERR_NONE && count == 0)
|
||||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such file: %s", key);
|
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static grub_err_t
|
static grub_err_t
|
||||||
|
@ -182,11 +152,11 @@ grub_cmd_search (grub_extcmd_t cmd, int argc, char **args)
|
||||||
var = state[SEARCH_SET].arg ? state[SEARCH_SET].arg : "root";
|
var = state[SEARCH_SET].arg ? state[SEARCH_SET].arg : "root";
|
||||||
|
|
||||||
if (state[SEARCH_LABEL].set)
|
if (state[SEARCH_LABEL].set)
|
||||||
search_fs (args[0], var, state[SEARCH_NO_FLOPPY].set, 0);
|
search_fs (args[0], var, state[SEARCH_NO_FLOPPY].set, SEARCH_LABEL);
|
||||||
else if (state[SEARCH_FS_UUID].set)
|
else if (state[SEARCH_FS_UUID].set)
|
||||||
search_fs (args[0], var, state[SEARCH_NO_FLOPPY].set, 1);
|
search_fs (args[0], var, state[SEARCH_NO_FLOPPY].set, SEARCH_FS_UUID);
|
||||||
else if (state[SEARCH_FILE].set)
|
else if (state[SEARCH_FILE].set)
|
||||||
search_file (args[0], var, state[SEARCH_NO_FLOPPY].set);
|
search_fs (args[0], var, state[SEARCH_NO_FLOPPY].set, SEARCH_FILE);
|
||||||
else
|
else
|
||||||
return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type");
|
return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue