2005-08-20 Yoshinori K. Okuji <okuji@enbug.org>

* partmap/pc.c (pc_partition_map_iterate): Include the value of an
        invalid magic in thre error.

        * commands/search.c: New file.

        * util/grub-emu.c (main): Call grub_search_init and
        grub_search_fini.

        * kern/rescue.c (grub_rescue_print_disks): Removed.
        (grub_rescue_print_devices): New function.
        (grub_rescue_cmd_ls): Use grub_device_iterate with
        grub_rescue_print_devices instead of grub_disk_dev_iterate with
        grub_rescue_print_disks.

        * kern/partition.c (grub_partition_iterate): Return the result of
        PARTMAP->ITERATE instead of GRUB_ERRNO.

        * kern/device.c: Include grub/partition.h.
        (grub_device_iterate): New function.

        * include/grub/partition.h (grub_partition_iterate): Return int
        instead of grub_err_t.

        * include/grub/normal.h [GRUB_UTIL] (grub_search_init): New
        prototype.
        [GRUB_UTIL] (grub_search_fini): Likewise.

        * include/grub/device.h (grub_device_iterate): New prototype.

        * conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Added
        commands/search.c.
        (pkgdata_MODULES): Added search.mod.
        (search_mod_SOURCES): New variable.
        (search_mod_CFLAGS): Likewise.

        * conf/i386-pc.rmk (grub_emu_SOURCES): Added commands/search.c.
        (pkgdata_MODULES): Added search.mod.
        (search_mod_SOURCES): New variable.
        (search_mod_CFLAGS): Likewise.

        * commands/ls.c (grub_ls_list_disks): Renamed to ...
        (grub_ls_list_devices): ... this, and use grub_device_iterate.
        All callers changed.

        * DISTLIST: Added commands/search.c.
This commit is contained in:
okuji 2005-08-20 07:49:02 +00:00
parent ef0954341c
commit 6a85ce7953
17 changed files with 466 additions and 104 deletions

View File

@ -1,3 +1,51 @@
2005-08-20 Yoshinori K. Okuji <okuji@enbug.org>
* partmap/pc.c (pc_partition_map_iterate): Include the value of an
invalid magic in thre error.
* commands/search.c: New file.
* util/grub-emu.c (main): Call grub_search_init and
grub_search_fini.
* kern/rescue.c (grub_rescue_print_disks): Removed.
(grub_rescue_print_devices): New function.
(grub_rescue_cmd_ls): Use grub_device_iterate with
grub_rescue_print_devices instead of grub_disk_dev_iterate with
grub_rescue_print_disks.
* kern/partition.c (grub_partition_iterate): Return the result of
PARTMAP->ITERATE instead of GRUB_ERRNO.
* kern/device.c: Include grub/partition.h.
(grub_device_iterate): New function.
* include/grub/partition.h (grub_partition_iterate): Return int
instead of grub_err_t.
* include/grub/normal.h [GRUB_UTIL] (grub_search_init): New
prototype.
[GRUB_UTIL] (grub_search_fini): Likewise.
* include/grub/device.h (grub_device_iterate): New prototype.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Added
commands/search.c.
(pkgdata_MODULES): Added search.mod.
(search_mod_SOURCES): New variable.
(search_mod_CFLAGS): Likewise.
* conf/i386-pc.rmk (grub_emu_SOURCES): Added commands/search.c.
(pkgdata_MODULES): Added search.mod.
(search_mod_SOURCES): New variable.
(search_mod_CFLAGS): Likewise.
* commands/ls.c (grub_ls_list_disks): Renamed to ...
(grub_ls_list_devices): ... this, and use grub_device_iterate.
All callers changed.
* DISTLIST: Added commands/search.c.
2005-08-20 Yoshinori K. Okuji <okuji@enbug.org>
* kern/term.c (grub_putchar): Use grub_utf8_to_ucs4 for the

View File

@ -44,6 +44,7 @@ commands/configfile.c
commands/default.c
commands/help.c
commands/ls.c
commands/search.c
commands/terminal.c
commands/timeout.c
conf/i386-pc.mk

2
NEWS
View File

@ -6,6 +6,8 @@ New in 1.91:
* Add VBE support.
* New commands, "search", "vbetest" and "vbeinfo".
New in 1.90 - 2005-08-07:

View File

@ -42,60 +42,20 @@ static const struct grub_arg_option options[] =
static const char grub_human_sizes[] = {' ', 'K', 'M', 'G', 'T'};
static grub_err_t
grub_ls_list_disks (int longlist)
grub_ls_list_devices (int longlist)
{
auto int grub_ls_print_disks (const char *name);
int grub_ls_print_disks (const char *name)
auto int grub_ls_print_devices (const char *name);
int grub_ls_print_devices (const char *name)
{
grub_device_t dev;
auto int print_partition (grub_disk_t disk, const grub_partition_t p);
int print_partition (grub_disk_t disk __attribute__ ((unused)),
const grub_partition_t p)
{
char *pname = grub_partition_get_name (p);
if (pname)
{
if (longlist)
{
char device_name[grub_strlen (name) + 1
+ grub_strlen (pname) + 1];
grub_sprintf (device_name, "%s,%s", name, pname);
grub_normal_print_device_info (device_name);
}
else
grub_printf ("(%s,%s) ", name, pname);
grub_free (pname);
}
return 0;
}
dev = grub_device_open (name);
grub_errno = GRUB_ERR_NONE;
if (dev)
{
if (longlist)
grub_normal_print_device_info (name);
else
grub_printf ("(%s) ", name);
if (dev->disk && dev->disk->has_partitions)
{
grub_partition_iterate (dev->disk, print_partition);
grub_errno = GRUB_ERR_NONE;
}
grub_device_close (dev);
}
if (longlist)
grub_normal_print_device_info (name);
else
grub_printf ("(%s) ", name);
return 0;
}
grub_disk_dev_iterate (grub_ls_print_disks);
grub_device_iterate (grub_ls_print_devices);
grub_putchar ('\n');
grub_refresh ();
@ -260,7 +220,7 @@ static grub_err_t
grub_cmd_ls (struct grub_arg_list *state, int argc, char **args)
{
if (argc == 0)
grub_ls_list_disks (state[0].set);
grub_ls_list_devices (state[0].set);
else
grub_ls_list_files (args[0], state[0].set, state[2].set,
state[1].set);

186
commands/search.c Normal file
View File

@ -0,0 +1,186 @@
/* search.c - search devices based on a file or a filesystem label */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005 Free Software Foundation, Inc.
*
* GRUB is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/normal.h>
#include <grub/arg.h>
#include <grub/device.h>
#include <grub/file.h>
#include <grub/env.h>
static const struct grub_arg_option options[] =
{
{"file", 'f', 0, "search devices by a file (default)", 0, 0},
{"label", 'l', 0, "search devices by a filesystem label", 0, 0},
{"set", 's', GRUB_ARG_OPTION_OPTIONAL, "set a variable to the first device found", "VAR", ARG_TYPE_STRING},
{0, 0, 0, 0, 0, 0}
};
static void
search_label (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;
dev = grub_device_open (name);
if (dev)
{
grub_fs_t fs;
fs = grub_fs_probe (dev);
if (fs && fs->label)
{
char *label;
(fs->label) (dev, &label);
if (grub_errno == GRUB_ERR_NONE && label)
{
if (grub_strcmp (label, key) == 0)
{
/* Found! */
grub_printf (" %s", name);
if (count++ == 0 && var)
grub_env_set (var, name);
}
grub_free (label);
}
}
grub_device_close (dev);
}
grub_errno = GRUB_ERR_NONE;
return 0;
}
grub_device_iterate (iterate_device);
if (count == 0)
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key);
}
static void
search_file (const char *key, const char *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;
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! */
grub_printf (" %s", name);
if (count++ == 0 && var)
grub_env_set (var, name);
grub_file_close (file);
}
grub_errno = GRUB_ERR_NONE;
return 0;
}
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");
}
static grub_err_t
grub_cmd_search (struct grub_arg_list *state, int argc, char **args)
{
const char *var = 0;
if (argc == 0)
return grub_error (GRUB_ERR_INVALID_COMMAND, "no argument specified");
if (state[2].set)
var = state[2].arg ? : "root";
if (state[1].set)
search_label (args[0], var);
else
search_file (args[0], var);
return grub_errno;
}
#ifdef GRUB_UTIL
void
grub_search_init (void)
{
grub_register_command ("search", grub_cmd_search, GRUB_COMMAND_FLAG_BOTH,
"search [-f|-l|-s] NAME",
"Search devices by a file or a filesystem label."
" If --set is specified, the first device found is"
" set to a variable. If no variable name is"
" specified, \"root\" is used.",
options);
}
void
grub_search_fini (void)
{
grub_unregister_command ("search");
}
#else /* ! GRUB_UTIL */
GRUB_MOD_INIT
{
(void) mod; /* To stop warning. */
grub_register_command ("search", grub_cmd_search, GRUB_COMMAND_FLAG_BOTH,
"search [-f|-l|-s] NAME",
"Search devices by a file or a filesystem label."
" If --set is specified, the first device found is"
" set to a variable. If no variable name is"
" specified, \"root\" is used.",
options);
}
GRUB_MOD_FINI
{
grub_unregister_command ("search");
}
#endif /* ! GRUB_UTIL */

View File

@ -674,7 +674,8 @@ grub_probefs-fs_fshelp.d: fs/fshelp.c
# For grub-emu.
grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \
commands/configfile.c commands/default.c commands/help.c \
commands/terminal.c commands/ls.c commands/timeout.c \
commands/terminal.c commands/ls.c commands/search.c \
commands/timeout.c \
commands/i386/pc/halt.c commands/i386/pc/reboot.c \
disk/loopback.c \
fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c fs/jfs.c \
@ -689,10 +690,10 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \
util/console.c util/grub-emu.c util/misc.c \
util/i386/pc/biosdisk.c util/i386/pc/getroot.c \
util/i386/pc/misc.c
CLEANFILES += grub-emu grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_i386_pc_halt.o grub_emu-commands_i386_pc_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_i386_pc_misc.o
MOSTLYCLEANFILES += grub_emu-commands_boot.d grub_emu-commands_cat.d grub_emu-commands_cmp.d grub_emu-commands_configfile.d grub_emu-commands_default.d grub_emu-commands_help.d grub_emu-commands_terminal.d grub_emu-commands_ls.d grub_emu-commands_timeout.d grub_emu-commands_i386_pc_halt.d grub_emu-commands_i386_pc_reboot.d grub_emu-disk_loopback.d grub_emu-fs_ext2.d grub_emu-fs_fat.d grub_emu-fs_fshelp.d grub_emu-fs_hfs.d grub_emu-fs_iso9660.d grub_emu-fs_jfs.d grub_emu-fs_minix.d grub_emu-fs_ufs.d grub_emu-kern_device.d grub_emu-kern_disk.d grub_emu-kern_dl.d grub_emu-kern_env.d grub_emu-kern_err.d grub_emu-kern_file.d grub_emu-kern_fs.d grub_emu-kern_loader.d grub_emu-kern_main.d grub_emu-kern_misc.d grub_emu-kern_partition.d grub_emu-kern_rescue.d grub_emu-kern_term.d grub_emu-normal_arg.d grub_emu-normal_cmdline.d grub_emu-normal_command.d grub_emu-normal_completion.d grub_emu-normal_context.d grub_emu-normal_main.d grub_emu-normal_menu.d grub_emu-normal_menu_entry.d grub_emu-normal_misc.d grub_emu-partmap_amiga.d grub_emu-partmap_apple.d grub_emu-partmap_pc.d grub_emu-partmap_sun.d grub_emu-util_console.d grub_emu-util_grub_emu.d grub_emu-util_misc.d grub_emu-util_i386_pc_biosdisk.d grub_emu-util_i386_pc_getroot.d grub_emu-util_i386_pc_misc.d
CLEANFILES += grub-emu grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_search.o grub_emu-commands_timeout.o grub_emu-commands_i386_pc_halt.o grub_emu-commands_i386_pc_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_i386_pc_misc.o
MOSTLYCLEANFILES += grub_emu-commands_boot.d grub_emu-commands_cat.d grub_emu-commands_cmp.d grub_emu-commands_configfile.d grub_emu-commands_default.d grub_emu-commands_help.d grub_emu-commands_terminal.d grub_emu-commands_ls.d grub_emu-commands_search.d grub_emu-commands_timeout.d grub_emu-commands_i386_pc_halt.d grub_emu-commands_i386_pc_reboot.d grub_emu-disk_loopback.d grub_emu-fs_ext2.d grub_emu-fs_fat.d grub_emu-fs_fshelp.d grub_emu-fs_hfs.d grub_emu-fs_iso9660.d grub_emu-fs_jfs.d grub_emu-fs_minix.d grub_emu-fs_ufs.d grub_emu-kern_device.d grub_emu-kern_disk.d grub_emu-kern_dl.d grub_emu-kern_env.d grub_emu-kern_err.d grub_emu-kern_file.d grub_emu-kern_fs.d grub_emu-kern_loader.d grub_emu-kern_main.d grub_emu-kern_misc.d grub_emu-kern_partition.d grub_emu-kern_rescue.d grub_emu-kern_term.d grub_emu-normal_arg.d grub_emu-normal_cmdline.d grub_emu-normal_command.d grub_emu-normal_completion.d grub_emu-normal_context.d grub_emu-normal_main.d grub_emu-normal_menu.d grub_emu-normal_menu_entry.d grub_emu-normal_misc.d grub_emu-partmap_amiga.d grub_emu-partmap_apple.d grub_emu-partmap_pc.d grub_emu-partmap_sun.d grub_emu-util_console.d grub_emu-util_grub_emu.d grub_emu-util_misc.d grub_emu-util_i386_pc_biosdisk.d grub_emu-util_i386_pc_getroot.d grub_emu-util_i386_pc_misc.d
grub-emu: grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_i386_pc_halt.o grub_emu-commands_i386_pc_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_i386_pc_misc.o
grub-emu: grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_search.o grub_emu-commands_timeout.o grub_emu-commands_i386_pc_halt.o grub_emu-commands_i386_pc_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_i386_pc_misc.o
$(BUILD_CC) -o $@ $^ $(BUILD_LDFLAGS) $(grub_emu_LDFLAGS)
grub_emu-commands_boot.o: commands/boot.c
@ -759,6 +760,14 @@ grub_emu-commands_ls.d: commands/ls.c
-include grub_emu-commands_ls.d
grub_emu-commands_search.o: commands/search.c
$(BUILD_CC) -Icommands -I$(srcdir)/commands $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -c -o $@ $<
grub_emu-commands_search.d: commands/search.c
set -e; $(BUILD_CC) -Icommands -I$(srcdir)/commands $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -M $< | sed 's,search\.o[ :]*,grub_emu-commands_search.o $@ : ,g' > $@; [ -s $@ ] || rm -f $@
-include grub_emu-commands_search.d
grub_emu-commands_timeout.o: commands/timeout.c
$(BUILD_CC) -Icommands -I$(srcdir)/commands $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -c -o $@ $<
@ -1150,7 +1159,7 @@ pkgdata_MODULES = _chain.mod _linux.mod linux.mod fat.mod ufs.mod \
terminal.mod fshelp.mod chain.mod multiboot.mod amiga.mod \
apple.mod pc.mod sun.mod loopback.mod reboot.mod halt.mod \
help.mod default.mod timeout.mod configfile.mod vbe.mod \
vesafb.mod vbetest.mod vbeinfo.mod
vesafb.mod vbetest.mod vbeinfo.mod search.mod
# For _chain.mod.
_chain_mod_SOURCES = loader/i386/pc/chainloader.c
@ -3180,6 +3189,56 @@ fs-vbetest.lst: commands/i386/pc/vbetest.c genfslist.sh
vbetest_mod_CFLAGS = $(COMMON_CFLAGS)
# For search.mod.
search_mod_SOURCES = commands/search.c
CLEANFILES += search.mod mod-search.o mod-search.c pre-search.o search_mod-commands_search.o def-search.lst und-search.lst
MOSTLYCLEANFILES += search_mod-commands_search.d
DEFSYMFILES += def-search.lst
UNDSYMFILES += und-search.lst
search.mod: pre-search.o mod-search.o
-rm -f $@
$(LD) -r -d -o $@ $^
$(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@
pre-search.o: search_mod-commands_search.o
-rm -f $@
$(LD) -r -d -o $@ $^
mod-search.o: mod-search.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(search_mod_CFLAGS) -c -o $@ $<
mod-search.c: moddep.lst genmodsrc.sh
sh $(srcdir)/genmodsrc.sh 'search' $< > $@ || (rm -f $@; exit 1)
def-search.lst: pre-search.o
$(NM) -g --defined-only -P -p $< | sed 's/^\([^ ]*\).*/\1 search/' > $@
und-search.lst: pre-search.o
echo 'search' > $@
$(NM) -u -P -p $< | cut -f1 -d' ' >> $@
search_mod-commands_search.o: commands/search.c
$(CC) -Icommands -I$(srcdir)/commands $(CPPFLAGS) $(CFLAGS) $(search_mod_CFLAGS) -c -o $@ $<
search_mod-commands_search.d: commands/search.c
set -e; $(CC) -Icommands -I$(srcdir)/commands $(CPPFLAGS) $(CFLAGS) $(search_mod_CFLAGS) -M $< | sed 's,search\.o[ :]*,search_mod-commands_search.o $@ : ,g' > $@; [ -s $@ ] || rm -f $@
-include search_mod-commands_search.d
CLEANFILES += cmd-search.lst fs-search.lst
COMMANDFILES += cmd-search.lst
FSFILES += fs-search.lst
cmd-search.lst: commands/search.c gencmdlist.sh
set -e; $(CC) -Icommands -I$(srcdir)/commands $(CPPFLAGS) $(CFLAGS) $(search_mod_CFLAGS) -E $< | sh $(srcdir)/gencmdlist.sh search > $@ || (rm -f $@; exit 1)
fs-search.lst: commands/search.c genfslist.sh
set -e; $(CC) -Icommands -I$(srcdir)/commands $(CPPFLAGS) $(CFLAGS) $(search_mod_CFLAGS) -E $< | sh $(srcdir)/genfslist.sh search > $@ || (rm -f $@; exit 1)
search_mod_CFLAGS = $(COMMON_CFLAGS)
CLEANFILES += moddep.lst command.lst fs.lst
pkgdata_DATA += moddep.lst command.lst fs.lst
moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep

View File

@ -78,7 +78,8 @@ grub_probefs_SOURCES = util/i386/pc/grub-probefs.c \
# For grub-emu.
grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \
commands/configfile.c commands/default.c commands/help.c \
commands/terminal.c commands/ls.c commands/timeout.c \
commands/terminal.c commands/ls.c commands/search.c \
commands/timeout.c \
commands/i386/pc/halt.c commands/i386/pc/reboot.c \
disk/loopback.c \
fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c fs/jfs.c \
@ -112,7 +113,7 @@ pkgdata_MODULES = _chain.mod _linux.mod linux.mod fat.mod ufs.mod \
terminal.mod fshelp.mod chain.mod multiboot.mod amiga.mod \
apple.mod pc.mod sun.mod loopback.mod reboot.mod halt.mod \
help.mod default.mod timeout.mod configfile.mod vbe.mod \
vesafb.mod vbetest.mod vbeinfo.mod
vesafb.mod vbetest.mod vbeinfo.mod search.mod
# For _chain.mod.
_chain_mod_SOURCES = loader/i386/pc/chainloader.c
@ -269,3 +270,7 @@ vbeinfo_mod_CFLAGS = $(COMMON_CFLAGS)
# For vbetest.mod.
vbetest_mod_SOURCES = commands/i386/pc/vbetest.c
vbetest_mod_CFLAGS = $(COMMON_CFLAGS)
# For search.mod.
search_mod_SOURCES = commands/search.c
search_mod_CFLAGS = $(COMMON_CFLAGS)

View File

@ -65,7 +65,8 @@ grub_mkimage-util_resolve.d: util/resolve.c
# For grub-emu
grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \
commands/configfile.c commands/default.c commands/help.c \
commands/terminal.c commands/ls.c commands/timeout.c \
commands/search.c commands/terminal.c commands/ls.c \
commands/timeout.c \
commands/ieee1275/halt.c commands/ieee1275/reboot.c \
disk/loopback.c \
fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c fs/jfs.c \
@ -80,10 +81,10 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \
util/console.c util/grub-emu.c util/misc.c \
util/i386/pc/biosdisk.c util/i386/pc/getroot.c \
util/powerpc/ieee1275/misc.c
CLEANFILES += grub-emu grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_powerpc_ieee1275_misc.o
MOSTLYCLEANFILES += grub_emu-commands_boot.d grub_emu-commands_cat.d grub_emu-commands_cmp.d grub_emu-commands_configfile.d grub_emu-commands_default.d grub_emu-commands_help.d grub_emu-commands_terminal.d grub_emu-commands_ls.d grub_emu-commands_timeout.d grub_emu-commands_ieee1275_halt.d grub_emu-commands_ieee1275_reboot.d grub_emu-disk_loopback.d grub_emu-fs_ext2.d grub_emu-fs_fat.d grub_emu-fs_fshelp.d grub_emu-fs_hfs.d grub_emu-fs_iso9660.d grub_emu-fs_jfs.d grub_emu-fs_minix.d grub_emu-fs_ufs.d grub_emu-kern_device.d grub_emu-kern_disk.d grub_emu-kern_dl.d grub_emu-kern_env.d grub_emu-kern_err.d grub_emu-kern_file.d grub_emu-kern_fs.d grub_emu-kern_loader.d grub_emu-kern_main.d grub_emu-kern_misc.d grub_emu-kern_partition.d grub_emu-kern_rescue.d grub_emu-kern_term.d grub_emu-normal_arg.d grub_emu-normal_cmdline.d grub_emu-normal_command.d grub_emu-normal_completion.d grub_emu-normal_context.d grub_emu-normal_main.d grub_emu-normal_menu.d grub_emu-normal_menu_entry.d grub_emu-normal_misc.d grub_emu-partmap_amiga.d grub_emu-partmap_apple.d grub_emu-partmap_pc.d grub_emu-partmap_sun.d grub_emu-util_console.d grub_emu-util_grub_emu.d grub_emu-util_misc.d grub_emu-util_i386_pc_biosdisk.d grub_emu-util_i386_pc_getroot.d grub_emu-util_powerpc_ieee1275_misc.d
CLEANFILES += grub-emu grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_search.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_powerpc_ieee1275_misc.o
MOSTLYCLEANFILES += grub_emu-commands_boot.d grub_emu-commands_cat.d grub_emu-commands_cmp.d grub_emu-commands_configfile.d grub_emu-commands_default.d grub_emu-commands_help.d grub_emu-commands_search.d grub_emu-commands_terminal.d grub_emu-commands_ls.d grub_emu-commands_timeout.d grub_emu-commands_ieee1275_halt.d grub_emu-commands_ieee1275_reboot.d grub_emu-disk_loopback.d grub_emu-fs_ext2.d grub_emu-fs_fat.d grub_emu-fs_fshelp.d grub_emu-fs_hfs.d grub_emu-fs_iso9660.d grub_emu-fs_jfs.d grub_emu-fs_minix.d grub_emu-fs_ufs.d grub_emu-kern_device.d grub_emu-kern_disk.d grub_emu-kern_dl.d grub_emu-kern_env.d grub_emu-kern_err.d grub_emu-kern_file.d grub_emu-kern_fs.d grub_emu-kern_loader.d grub_emu-kern_main.d grub_emu-kern_misc.d grub_emu-kern_partition.d grub_emu-kern_rescue.d grub_emu-kern_term.d grub_emu-normal_arg.d grub_emu-normal_cmdline.d grub_emu-normal_command.d grub_emu-normal_completion.d grub_emu-normal_context.d grub_emu-normal_main.d grub_emu-normal_menu.d grub_emu-normal_menu_entry.d grub_emu-normal_misc.d grub_emu-partmap_amiga.d grub_emu-partmap_apple.d grub_emu-partmap_pc.d grub_emu-partmap_sun.d grub_emu-util_console.d grub_emu-util_grub_emu.d grub_emu-util_misc.d grub_emu-util_i386_pc_biosdisk.d grub_emu-util_i386_pc_getroot.d grub_emu-util_powerpc_ieee1275_misc.d
grub-emu: grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_powerpc_ieee1275_misc.o
grub-emu: grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_search.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_powerpc_ieee1275_misc.o
$(BUILD_CC) -o $@ $^ $(BUILD_LDFLAGS) $(grub_emu_LDFLAGS)
grub_emu-commands_boot.o: commands/boot.c
@ -134,6 +135,14 @@ grub_emu-commands_help.d: commands/help.c
-include grub_emu-commands_help.d
grub_emu-commands_search.o: commands/search.c
$(BUILD_CC) -Icommands -I$(srcdir)/commands $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -c -o $@ $<
grub_emu-commands_search.d: commands/search.c
set -e; $(BUILD_CC) -Icommands -I$(srcdir)/commands $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -M $< | sed 's,search\.o[ :]*,grub_emu-commands_search.o $@ : ,g' > $@; [ -s $@ ] || rm -f $@
-include grub_emu-commands_search.d
grub_emu-commands_terminal.o: commands/terminal.c
$(BUILD_CC) -Icommands -I$(srcdir)/commands $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -c -o $@ $<
@ -738,7 +747,7 @@ pkgdata_MODULES = _linux.mod linux.mod fat.mod ufs.mod ext2.mod minix.mod \
hfs.mod jfs.mod normal.mod hello.mod font.mod ls.mod \
boot.mod cmp.mod cat.mod terminal.mod fshelp.mod amiga.mod apple.mod \
pc.mod suspend.mod loopback.mod help.mod reboot.mod halt.mod sun.mod \
default.mod timeout.mod configfile.mod
default.mod timeout.mod configfile.mod search.mod
# For fshelp.mod.
fshelp_mod_SOURCES = fs/fshelp.c
@ -2368,6 +2377,56 @@ fs-configfile.lst: commands/configfile.c genfslist.sh
configfile_mod_CFLAGS = $(COMMON_CFLAGS)
# For search.mod.
search_mod_SOURCES = commands/search.c
CLEANFILES += search.mod mod-search.o mod-search.c pre-search.o search_mod-commands_search.o def-search.lst und-search.lst
MOSTLYCLEANFILES += search_mod-commands_search.d
DEFSYMFILES += def-search.lst
UNDSYMFILES += und-search.lst
search.mod: pre-search.o mod-search.o
-rm -f $@
$(LD) -r -d -o $@ $^
$(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@
pre-search.o: search_mod-commands_search.o
-rm -f $@
$(LD) -r -d -o $@ $^
mod-search.o: mod-search.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(search_mod_CFLAGS) -c -o $@ $<
mod-search.c: moddep.lst genmodsrc.sh
sh $(srcdir)/genmodsrc.sh 'search' $< > $@ || (rm -f $@; exit 1)
def-search.lst: pre-search.o
$(NM) -g --defined-only -P -p $< | sed 's/^\([^ ]*\).*/\1 search/' > $@
und-search.lst: pre-search.o
echo 'search' > $@
$(NM) -u -P -p $< | cut -f1 -d' ' >> $@
search_mod-commands_search.o: commands/search.c
$(CC) -Icommands -I$(srcdir)/commands $(CPPFLAGS) $(CFLAGS) $(search_mod_CFLAGS) -c -o $@ $<
search_mod-commands_search.d: commands/search.c
set -e; $(CC) -Icommands -I$(srcdir)/commands $(CPPFLAGS) $(CFLAGS) $(search_mod_CFLAGS) -M $< | sed 's,search\.o[ :]*,search_mod-commands_search.o $@ : ,g' > $@; [ -s $@ ] || rm -f $@
-include search_mod-commands_search.d
CLEANFILES += cmd-search.lst fs-search.lst
COMMANDFILES += cmd-search.lst
FSFILES += fs-search.lst
cmd-search.lst: commands/search.c gencmdlist.sh
set -e; $(CC) -Icommands -I$(srcdir)/commands $(CPPFLAGS) $(CFLAGS) $(search_mod_CFLAGS) -E $< | sh $(srcdir)/gencmdlist.sh search > $@ || (rm -f $@; exit 1)
fs-search.lst: commands/search.c genfslist.sh
set -e; $(CC) -Icommands -I$(srcdir)/commands $(CPPFLAGS) $(CFLAGS) $(search_mod_CFLAGS) -E $< | sh $(srcdir)/genfslist.sh search > $@ || (rm -f $@; exit 1)
search_mod_CFLAGS = $(COMMON_CFLAGS)
CLEANFILES += moddep.lst command.lst fs.lst
pkgdata_DATA += moddep.lst command.lst fs.lst
moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep

View File

@ -35,7 +35,8 @@ grub_mkimage_SOURCES = util/powerpc/ieee1275/grub-mkimage.c util/misc.c \
# For grub-emu
grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \
commands/configfile.c commands/default.c commands/help.c \
commands/terminal.c commands/ls.c commands/timeout.c \
commands/search.c commands/terminal.c commands/ls.c \
commands/timeout.c \
commands/ieee1275/halt.c commands/ieee1275/reboot.c \
disk/loopback.c \
fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c fs/jfs.c \
@ -74,7 +75,7 @@ pkgdata_MODULES = _linux.mod linux.mod fat.mod ufs.mod ext2.mod minix.mod \
hfs.mod jfs.mod normal.mod hello.mod font.mod ls.mod \
boot.mod cmp.mod cat.mod terminal.mod fshelp.mod amiga.mod apple.mod \
pc.mod suspend.mod loopback.mod help.mod reboot.mod halt.mod sun.mod \
default.mod timeout.mod configfile.mod
default.mod timeout.mod configfile.mod search.mod
# For fshelp.mod.
fshelp_mod_SOURCES = fs/fshelp.c
@ -199,3 +200,7 @@ timeout_mod_CFLAGS = $(COMMON_CFLAGS)
# For configfile.mod
configfile_mod_SOURCES = commands/configfile.c
configfile_mod_CFLAGS = $(COMMON_CFLAGS)
# For search.mod.
search_mod_SOURCES = commands/search.c
search_mod_CFLAGS = $(COMMON_CFLAGS)

View File

@ -37,5 +37,6 @@ typedef struct grub_device *grub_device_t;
grub_device_t EXPORT_FUNC(grub_device_open) (const char *name);
grub_err_t EXPORT_FUNC(grub_device_close) (grub_device_t device);
int EXPORT_FUNC(grub_device_iterate) (int (*hook) (const char *name));
#endif /* ! GRUB_DEVICE_HEADER */

View File

@ -221,6 +221,8 @@ void grub_timeout_init (void);
void grub_timeout_fini (void);
void grub_configfile_init (void);
void grub_configfile_fini (void);
void grub_search_init (void);
void grub_search_fini (void);
#endif
#endif /* ! GRUB_NORMAL_HEADER */

View File

@ -72,8 +72,9 @@ struct grub_partition
grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk,
const char *str);
grub_err_t EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
int (*hook) (struct grub_disk *disk, const grub_partition_t partition));
int EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
int (*hook) (struct grub_disk *disk,
const grub_partition_t partition));
char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);
int EXPORT_FUNC(grub_partition_map_iterate) (int (*hook) (const grub_partition_map_t partmap));

View File

@ -25,6 +25,7 @@
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/env.h>
#include <grub/partition.h>
grub_device_t
grub_device_open (const char *name)
@ -78,3 +79,62 @@ grub_device_close (grub_device_t device)
return grub_errno;
}
int
grub_device_iterate (int (*hook) (const char *name))
{
auto int iterate_disk (const char *disk_name);
auto int iterate_partition (grub_disk_t disk,
const grub_partition_t partition);
int iterate_disk (const char *disk_name)
{
grub_device_t dev;
if (hook (disk_name))
return 1;
dev = grub_device_open (disk_name);
if (! dev)
return 1;
if (dev->disk && dev->disk->has_partitions)
if (grub_partition_iterate (dev->disk, iterate_partition))
{
grub_device_close (dev);
return 1;
}
grub_device_close (dev);
return 0;
}
int iterate_partition (grub_disk_t disk, const grub_partition_t partition)
{
char *partition_name;
char *device_name;
int ret;
partition_name = grub_partition_get_name (partition);
if (! partition_name)
return 1;
device_name = grub_malloc (grub_strlen (disk->name) + 1
+ grub_strlen (partition_name) + 1);
if (! device_name)
{
grub_free (partition_name);
return 1;
}
grub_sprintf (device_name, "%s,%s", disk->name, partition_name);
grub_free (partition_name);
ret = hook (device_name);
grub_free (device_name);
return ret;
}
/* Only disk devices are supported at the moment. */
return grub_disk_dev_iterate (iterate_disk);
}

View File

@ -83,13 +83,14 @@ grub_partition_probe (struct grub_disk *disk, const char *str)
return part;
}
grub_err_t
int
grub_partition_iterate (struct grub_disk *disk,
int (*hook) (grub_disk_t disk,
const grub_partition_t partition))
{
grub_partition_map_t partmap = 0;
int ret = 0;
auto int part_map_iterate (const grub_partition_map_t p);
auto int part_map_iterate_hook (grub_disk_t d,
const grub_partition_t partition);
@ -117,9 +118,9 @@ grub_partition_iterate (struct grub_disk *disk,
grub_partition_map_iterate (part_map_iterate);
if (partmap)
partmap->iterate (disk, hook);
ret = partmap->iterate (disk, hook);
return grub_errno;
return ret;
}
char *

View File

@ -168,40 +168,9 @@ grub_rescue_cmd_cat (int argc, char *argv[])
}
static int
grub_rescue_print_disks (const char *name)
grub_rescue_print_devices (const char *name)
{
grub_device_t dev;
auto int print_partition (grub_disk_t disk, const grub_partition_t p);
int print_partition (grub_disk_t disk __attribute__ ((unused)),
const grub_partition_t p)
{
char *pname = grub_partition_get_name (p);
if (pname)
{
grub_printf ("(%s,%s) ", name, pname);
grub_free (pname);
}
return 0;
}
dev = grub_device_open (name);
grub_errno = GRUB_ERR_NONE;
if (dev)
{
grub_printf ("(%s) ", name);
if (dev->disk && dev->disk->has_partitions)
{
grub_partition_iterate (dev->disk, print_partition);
grub_errno = GRUB_ERR_NONE;
}
grub_device_close (dev);
}
grub_printf ("(%s) ", name);
return 0;
}
@ -220,7 +189,7 @@ grub_rescue_cmd_ls (int argc, char *argv[])
{
if (argc < 1)
{
grub_disk_dev_iterate (grub_rescue_print_disks);
grub_device_iterate (grub_rescue_print_devices);
grub_putchar ('\n');
grub_refresh ();
}

View File

@ -170,7 +170,8 @@ pc_partition_map_iterate (grub_disk_t disk,
if (label.magic
!= grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC))
return grub_error (GRUB_ERR_BAD_PART_TABLE,
"invalid disk label magic");
"invalid disk label magic 0x%x",
label.magic);
for (pcdata.bsd_part = 0;
pcdata.bsd_part < grub_cpu_to_le16 (label.num_partitions);

View File

@ -214,6 +214,7 @@ main (int argc, char *argv[])
grub_default_init ();
grub_timeout_init ();
grub_configfile_init ();
grub_search_init ();
/* XXX: Should normal mode be started by default? */
grub_normal_init ();
@ -222,6 +223,7 @@ main (int argc, char *argv[])
if (setjmp (main_env) == 0)
grub_main ();
grub_search_fini ();
grub_configfile_fini ();
grub_timeout_fini ();
grub_default_fini ();