2009-06-04 Robert Millan <rmh.grub@aybabtu.com>
Simplify the code duplication in commands/search.c. * commands/search.c (search_label, search_fs_uuid): Merge into ... (search_fs): ... this. Update all users.
This commit is contained in:
parent
f6fd460a40
commit
2bf5885a3d
2 changed files with 22 additions and 66 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2009-06-04 Robert Millan <rmh.grub@aybabtu.com>
|
||||||
|
|
||||||
|
Simplify the code duplication in commands/search.c.
|
||||||
|
|
||||||
|
* commands/search.c (search_label, search_fs_uuid): Merge into ...
|
||||||
|
(search_fs): ... this. Update all users.
|
||||||
|
|
||||||
2009-06-03 Felix Zielcke <fzielcke@z-51.de>
|
2009-06-03 Felix Zielcke <fzielcke@z-51.de>
|
||||||
|
|
||||||
* util/grub-mkconfig.in (update_grub_dir): Rename to grub_mkconfig_dir.
|
* util/grub-mkconfig.in (update_grub_dir): Rename to grub_mkconfig_dir.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* search.c - search devices based on a file or a filesystem label */
|
/* search.c - search devices based on a file or a filesystem label */
|
||||||
/*
|
/*
|
||||||
* GRUB -- GRand Unified Bootloader
|
* GRUB -- GRand Unified Bootloader
|
||||||
* Copyright (C) 2005,2007,2008 Free Software Foundation, Inc.
|
* Copyright (C) 2005,2007,2008,2009 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* GRUB is free software: you can redistribute it and/or modify
|
* GRUB is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -37,7 +37,7 @@ static const struct grub_arg_option options[] =
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
search_label (const char *key, const char *var)
|
search_fs (const char *key, const char *var, int is_uuid)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
auto int iterate_device (const char *name);
|
auto int iterate_device (const char *name);
|
||||||
|
@ -53,14 +53,17 @@ search_label (const char *key, const char *var)
|
||||||
grub_fs_t fs;
|
grub_fs_t fs;
|
||||||
|
|
||||||
fs = grub_fs_probe (dev);
|
fs = grub_fs_probe (dev);
|
||||||
if (fs && fs->label)
|
|
||||||
{
|
|
||||||
char *label;
|
|
||||||
|
|
||||||
(fs->label) (dev, &label);
|
#define QUID(x) (is_uuid ? (x)->uuid : (x)->label)
|
||||||
if (grub_errno == GRUB_ERR_NONE && label)
|
|
||||||
|
if (fs && QUID(fs))
|
||||||
{
|
{
|
||||||
if (grub_strcmp (label, key) == 0)
|
char *quid;
|
||||||
|
|
||||||
|
(QUID(fs)) (dev, &quid);
|
||||||
|
if (grub_errno == GRUB_ERR_NONE && quid)
|
||||||
|
{
|
||||||
|
if (grub_strcmp (quid, key) == 0)
|
||||||
{
|
{
|
||||||
/* Found! */
|
/* Found! */
|
||||||
count++;
|
count++;
|
||||||
|
@ -73,61 +76,7 @@ search_label (const char *key, const char *var)
|
||||||
grub_printf (" %s", name);
|
grub_printf (" %s", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
grub_free (label);
|
grub_free (quid);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
grub_device_close (dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
grub_errno = GRUB_ERR_NONE;
|
|
||||||
return abort;
|
|
||||||
}
|
|
||||||
|
|
||||||
grub_device_iterate (iterate_device);
|
|
||||||
|
|
||||||
if (count == 0)
|
|
||||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
search_fs_uuid (const char *key, const char *var)
|
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
auto int iterate_device (const char *name);
|
|
||||||
|
|
||||||
int iterate_device (const char *name)
|
|
||||||
{
|
|
||||||
grub_device_t dev;
|
|
||||||
int abort = 0;
|
|
||||||
|
|
||||||
dev = grub_device_open (name);
|
|
||||||
if (dev)
|
|
||||||
{
|
|
||||||
grub_fs_t fs;
|
|
||||||
|
|
||||||
fs = grub_fs_probe (dev);
|
|
||||||
if (fs && fs->uuid)
|
|
||||||
{
|
|
||||||
char *uuid;
|
|
||||||
|
|
||||||
(fs->uuid) (dev, &uuid);
|
|
||||||
if (grub_errno == GRUB_ERR_NONE && uuid)
|
|
||||||
{
|
|
||||||
if (grub_strcasecmp (uuid, key) == 0)
|
|
||||||
{
|
|
||||||
/* Found! */
|
|
||||||
count++;
|
|
||||||
if (var)
|
|
||||||
{
|
|
||||||
grub_env_set (var, name);
|
|
||||||
abort = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
grub_printf (" %s", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
grub_free (uuid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,9 +156,9 @@ grub_cmd_search (grub_extcmd_t cmd, int argc, char **args)
|
||||||
var = state[3].arg ? state[3].arg : "root";
|
var = state[3].arg ? state[3].arg : "root";
|
||||||
|
|
||||||
if (state[1].set)
|
if (state[1].set)
|
||||||
search_label (args[0], var);
|
search_fs (args[0], var, 0);
|
||||||
else if (state[2].set)
|
else if (state[2].set)
|
||||||
search_fs_uuid (args[0], var);
|
search_fs (args[0], var, 1);
|
||||||
else
|
else
|
||||||
search_file (args[0], var);
|
search_file (args[0], var);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue