From f4448a07923d0b4000f7d8d2d690863e38668ae4 Mon Sep 17 00:00:00 2001 From: robertmh Date: Thu, 4 Jun 2009 11:37:44 +0000 Subject: [PATCH] 2009-06-04 Robert Millan Prevent GRUB from probing floppies during boot. * conf/common.rmk (search_mod_CFLAGS): Use `-Werror -Wall'. * commands/search.c (options): Add --no-floppy. (search_fs, search_file, grub_cmd_search): Support --no-floppy. * util/grub-mkconfig_lib.in (prepare_grub_to_access_device): Use --no-floppy when searching for UUIDs. --- ChangeLog | 10 ++++++++++ commands/search.c | 31 ++++++++++++++++++++++--------- conf/common.rmk | 2 +- util/grub-mkconfig_lib.in | 2 +- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index d79342f8e..30d9c7969 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-06-04 Robert Millan + + Prevent GRUB from probing floppies during boot. + + * conf/common.rmk (search_mod_CFLAGS): Use `-Werror -Wall'. + * commands/search.c (options): Add --no-floppy. + (search_fs, search_file, grub_cmd_search): Support --no-floppy. + * util/grub-mkconfig_lib.in (prepare_grub_to_access_device): Use + --no-floppy when searching for UUIDs. + 2009-06-04 Robert Millan Simplify the code duplication in commands/search.c. diff --git a/commands/search.c b/commands/search.c index 5f8d1b51d..301b663e5 100644 --- a/commands/search.c +++ b/commands/search.c @@ -29,15 +29,16 @@ 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}, - {"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}, + {"file", 'f', 0, "search devices by a file (default)", 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} }; static void -search_fs (const char *key, const char *var, int is_uuid) +search_fs (const char *key, const char *var, int no_floppy, int is_uuid) { int count = 0; auto int iterate_device (const char *name); @@ -46,6 +47,12 @@ search_fs (const char *key, const char *var, int is_uuid) { grub_device_t dev; 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; dev = grub_device_open (name); if (dev) @@ -94,7 +101,7 @@ search_fs (const char *key, const char *var, int is_uuid) } static void -search_file (const char *key, const char *var) +search_file (const char *key, const char *var, int no_floppy) { int count = 0; char *buf = 0; @@ -107,6 +114,12 @@ search_file (const char *key, const char *var) 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) @@ -156,11 +169,11 @@ grub_cmd_search (grub_extcmd_t cmd, int argc, char **args) var = state[3].arg ? state[3].arg : "root"; if (state[1].set) - search_fs (args[0], var, 0); + search_fs (args[0], var, state[4].set, 0); else if (state[2].set) - search_fs (args[0], var, 1); + search_fs (args[0], var, state[4].set, 1); else - search_file (args[0], var); + search_file (args[0], var, state[4].set); return grub_errno; } diff --git a/conf/common.rmk b/conf/common.rmk index 1b9a6cdb4..ca18c534a 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -413,7 +413,7 @@ help_mod_LDFLAGS = $(COMMON_LDFLAGS) # For search.mod. search_mod_SOURCES = commands/search.c -search_mod_CFLAGS = $(COMMON_CFLAGS) +search_mod_CFLAGS = $(COMMON_CFLAGS) -Werror -Wall search_mod_LDFLAGS = $(COMMON_LDFLAGS) # For test.mod. diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 0c5c45621..9afbd3b1f 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -144,7 +144,7 @@ prepare_grub_to_access_device () # otherwise set root as per value in device.map. echo "set root=`${grub_probe} --device ${device} --target=drive`" if fs_uuid="`${grub_probe} --device ${device} --target=fs_uuid 2> /dev/null`" ; then - echo "search --fs-uuid --set ${fs_uuid}" + echo "search --no-floppy --fs-uuid --set ${fs_uuid}" fi }