From 063e925fb0370f2753f5122f8dacb26d67ce7713 Mon Sep 17 00:00:00 2001 From: phcoder Date: Tue, 22 Sep 2009 09:27:59 +0200 Subject: [PATCH 1/9] split search --- commands/search.c | 101 ++++++++++++++++---------------------- conf/common.rmk | 20 +++++++- conf/i386-coreboot.rmk | 2 +- conf/i386-efi.rmk | 2 +- conf/i386-ieee1275.rmk | 2 +- conf/i386-pc.rmk | 2 +- conf/powerpc-ieee1275.rmk | 2 +- conf/sparc64-ieee1275.rmk | 2 +- conf/x86_64-efi.rmk | 2 +- 9 files changed, 66 insertions(+), 69 deletions(-) diff --git a/commands/search.c b/commands/search.c index 0cfd0ebbc..60b5bbf04 100644 --- a/commands/search.c +++ b/commands/search.c @@ -27,27 +27,8 @@ #include #include -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; @@ -63,7 +44,7 @@ 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; @@ -84,27 +65,29 @@ search_fs (const char *key, const char *var, int no_floppy, enum options type) grub_file_close (file); } } - 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 +101,7 @@ search_fs (const char *key, const char *var, int no_floppy, enum options type) grub_device_close (dev); } } +#endif if (found) { @@ -156,45 +140,42 @@ search_fs (const char *key, const char *var, int no_floppy, enum options type) } 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 SEARCH_FILE +GRUB_MOD_INIT(search_file) +#elif defined (SEARCH_FS_UUID) +GRUB_MOD_INIT(search_fs_uuid) +#else +GRUB_MOD_INIT(search_fs_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, + COMMAND_NAME " NAME [VARIABLE]", + "Search devices by " SEARCH_TARGET "." + " If VARIABLE is specified, the first device found is" + " set to a variable."); } -GRUB_MOD_FINI(search) +#ifdef SEARCH_FILE +GRUB_MOD_FINI(search_file) +#elif defined (SEARCH_FS_UUID) +GRUB_MOD_FINI(search_fs_uuid) +#else +GRUB_MOD_FINI(search_fs_label) +#endif { - grub_unregister_extcmd (cmd); + grub_unregister_command (cmd); } diff --git a/conf/common.rmk b/conf/common.rmk index e18dd1052..9c8ac078d 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -363,7 +363,8 @@ scsi_mod_LDFLAGS = $(COMMON_LDFLAGS) # Commands. pkglib_MODULES += minicmd.mod extcmd.mod hello.mod handler.mod \ - ls.mod cmp.mod cat.mod help.mod search.mod loopback.mod \ + ls.mod cmp.mod cat.mod help.mod search_file.mod \ + search_fs_uuid.mod search_fs_label.mod search.mod loopback.mod \ fs_file.mod fs_uuid.mod configfile.mod echo.mod \ terminfo.mod test.mod blocklist.mod hexdump.mod \ read.mod sleep.mod loadenv.mod crc.mod parttool.mod \ @@ -437,10 +438,25 @@ help_mod_CFLAGS = $(COMMON_CFLAGS) help_mod_LDFLAGS = $(COMMON_LDFLAGS) # For search.mod. -search_mod_SOURCES = commands/search.c +search_mod_SOURCES = commands/search_wrap.c search_mod_CFLAGS = $(COMMON_CFLAGS) search_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For search.mod. +search_file_mod_SOURCES = commands/search_file.c +search_file_mod_CFLAGS = $(COMMON_CFLAGS) +search_file_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For search.mod. +search_label_mod_SOURCES = commands/search_label.c +search_label_mod_CFLAGS = $(COMMON_CFLAGS) +search_label_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For search.mod. +search_uuid_mod_SOURCES = commands/search_uuid.c +search_uuid_mod_CFLAGS = $(COMMON_CFLAGS) +search_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For test.mod. test_mod_SOURCES = commands/test.c test_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index 09ec7787c..79c36eec1 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -108,7 +108,7 @@ util/grub-emu.c_DEPENDENCIES = grub_emu_init.h grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/configfile.c commands/echo.c commands/help.c \ commands/handler.c commands/ls.c commands/test.c \ - commands/search.c commands/blocklist.c commands/hexdump.c \ + commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/blocklist.c commands/hexdump.c \ commands/gptsync.c commands/probe.c commands/xnu_uuid.c \ commands/password.c commands/keystatus.c \ lib/hexdump.c commands/i386/cpuid.c \ diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk index 99ab06f64..c9a412aaf 100644 --- a/conf/i386-efi.rmk +++ b/conf/i386-efi.rmk @@ -36,7 +36,7 @@ util/grub-emu.c_DEPENDENCIES = grub_emu_init.h grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/configfile.c commands/help.c \ commands/handler.c commands/ls.c commands/test.c \ - commands/search.c commands/hexdump.c lib/hexdump.c \ + commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/hexdump.c lib/hexdump.c \ commands/halt.c commands/reboot.c commands/keystatus.c \ commands/i386/cpuid.c \ commands/password.c \ diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index 4b640de49..6b15b1473 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -62,7 +62,7 @@ util/grub-emu.c_DEPENDENCIES = grub_emu_init.h grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/configfile.c commands/echo.c commands/help.c \ commands/handler.c commands/ls.c commands/test.c \ - commands/search.c commands/blocklist.c commands/hexdump.c \ + commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/blocklist.c commands/hexdump.c \ lib/hexdump.c commands/halt.c commands/reboot.c \ lib/envblk.c commands/loadenv.c \ commands/gptsync.c commands/probe.c commands/xnu_uuid.c \ diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index bf8fbfb9d..87364223c 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -120,7 +120,7 @@ util/grub-emu.c_DEPENDENCIES = grub_emu_init.h grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/configfile.c commands/echo.c commands/help.c \ commands/handler.c commands/ls.c commands/test.c \ - commands/search.c commands/blocklist.c commands/hexdump.c \ + commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/blocklist.c commands/hexdump.c \ lib/hexdump.c commands/i386/pc/halt.c commands/reboot.c \ lib/envblk.c commands/loadenv.c \ commands/gptsync.c commands/probe.c commands/xnu_uuid.c \ diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index ee7f9ec27..df594cfd0 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -42,7 +42,7 @@ grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/deviceiter.c \ util/grub-emu.c_DEPENDENCIES = grub_emu_init.h grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/configfile.c commands/help.c \ - commands/search.c commands/handler.c commands/test.c \ + commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/handler.c commands/test.c \ commands/ls.c commands/blocklist.c commands/hexdump.c \ lib/hexdump.c commands/halt.c commands/reboot.c \ lib/envblk.c commands/loadenv.c \ diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index 62e951a5e..936d4818a 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -100,7 +100,7 @@ grub_ofpathname_SOURCES = util/sparc64/ieee1275/grub-ofpathname.c \ util/grub-emu.c_DEPENDENCIES = grub_emu_init.h grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/configfile.c commands/help.c \ - commands/search.c commands/handler.c commands/test.c \ + commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/handler.c commands/test.c \ commands/ls.c commands/blocklist.c commands/hexdump.c \ lib/hexdump.c commands/halt.c commands/reboot.c \ lib/envblk.c commands/loadenv.c \ diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index 934cd7284..a17cd5928 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -34,7 +34,7 @@ util/grub-emu.c_DEPENDENCIES = grub_emu_init.h grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/configfile.c commands/help.c \ commands/handler.c commands/ls.c commands/test.c \ - commands/search.c commands/hexdump.c lib/hexdump.c \ + commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/hexdump.c lib/hexdump.c \ commands/halt.c commands/reboot.c \ commands/i386/cpuid.c \ commands/password.c commands/keystatus.c \ From dab7cb49133a6a2eac0d39f6403b4eac388d012e Mon Sep 17 00:00:00 2001 From: phcoder Date: Tue, 22 Sep 2009 09:29:32 +0200 Subject: [PATCH 2/9] missed files --- commands/search_file.c | 5 +++ commands/search_label.c | 5 +++ commands/search_uuid.c | 5 +++ commands/search_wrap.c | 81 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 commands/search_file.c create mode 100644 commands/search_label.c create mode 100644 commands/search_uuid.c create mode 100644 commands/search_wrap.c diff --git a/commands/search_file.c b/commands/search_file.c new file mode 100644 index 000000000..265220001 --- /dev/null +++ b/commands/search_file.c @@ -0,0 +1,5 @@ +#define DO_SEARCH_FILE 1 +#define FUNC_NAME grub_search_fs_file +#define COMMAND_NAME "search.file" +#define SEARCH_TARGET "file" +#include "search.c" diff --git a/commands/search_label.c b/commands/search_label.c new file mode 100644 index 000000000..0047b0e8c --- /dev/null +++ b/commands/search_label.c @@ -0,0 +1,5 @@ +#define DO_SEARCH_FS_LABEL 1 +#define FUNC_NAME grub_search_label +#define COMMAND_NAME "search.fs_label" +#define SEARCH_TARGET "filesystem label" +#include "search.c" diff --git a/commands/search_uuid.c b/commands/search_uuid.c new file mode 100644 index 000000000..9767d6501 --- /dev/null +++ b/commands/search_uuid.c @@ -0,0 +1,5 @@ +#define DO_SEARCH_FS_UUID 1 +#define FUNC_NAME grub_search_fs_uuid +#define COMMAND_NAME "search.fs_uuid" +#define SEARCH_TARGET "filesystem UUID" +#include "search.c" diff --git a/commands/search_wrap.c b/commands/search_wrap.c new file mode 100644 index 000000000..35cce3f5e --- /dev/null +++ b/commands/search_wrap.c @@ -0,0 +1,81 @@ +/* search.c - search devices based on a file or a filesystem label */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2005,2007,2008,2009 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 3 of the License, or + * (at your option) any later version. + * + * GRUB 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, see . + */ + +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 grub_err_t +grub_cmd_search (grub_extcmd_t cmd, int argc, char **args) +{ + struct grub_arg_list *state = cmd->state; + const char *var = 0; + + if (argc == 0) + 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) + grub_search_label (args[0], var, state[SEARCH_NO_FLOPPY].set); + else if (state[SEARCH_FS_UUID].set) + grub_search_fs_uuid (args[0], var, state[SEARCH_NO_FLOPPY].set); + else if (state[SEARCH_FILE].set) + grub_search_fs_file (args[0], var, state[SEARCH_NO_FLOPPY].set); + else + return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type"); + + return grub_errno; +} + +static grub_extcmd_t cmd; + +GRUB_MOD_INIT(search) +{ + 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_MOD_FINI(search) +{ + grub_unregister_extcmd (cmd); +} From d6cb87a6351caef982c897523ee8171a1542be60 Mon Sep 17 00:00:00 2001 From: phcoder Date: Tue, 22 Sep 2009 09:31:18 +0200 Subject: [PATCH 3/9] remove fs_*.c --- conf/common.rmk | 12 +--- disk/fs_file.c | 136 ------------------------------------------- disk/fs_uuid.c | 149 ------------------------------------------------ 3 files changed, 1 insertion(+), 296 deletions(-) delete mode 100644 disk/fs_file.c delete mode 100644 disk/fs_uuid.c diff --git a/conf/common.rmk b/conf/common.rmk index 9c8ac078d..1dc13159c 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -365,7 +365,7 @@ scsi_mod_LDFLAGS = $(COMMON_LDFLAGS) pkglib_MODULES += minicmd.mod extcmd.mod hello.mod handler.mod \ ls.mod cmp.mod cat.mod help.mod search_file.mod \ search_fs_uuid.mod search_fs_label.mod search.mod loopback.mod \ - fs_file.mod fs_uuid.mod configfile.mod echo.mod \ + configfile.mod echo.mod \ terminfo.mod test.mod blocklist.mod hexdump.mod \ read.mod sleep.mod loadenv.mod crc.mod parttool.mod \ msdospart.mod memrw.mod normal.mod sh.mod lua.mod \ @@ -467,16 +467,6 @@ loopback_mod_SOURCES = disk/loopback.c loopback_mod_CFLAGS = $(COMMON_CFLAGS) loopback_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For fs_file.mod -fs_file_mod_SOURCES = disk/fs_file.c -fs_file_mod_CFLAGS = $(COMMON_CFLAGS) -fs_file_mod_LDFLAGS = $(COMMON_LDFLAGS) - -# For fs_uuid.mod -fs_uuid_mod_SOURCES = disk/fs_uuid.c -fs_uuid_mod_CFLAGS = $(COMMON_CFLAGS) -fs_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For configfile.mod configfile_mod_SOURCES = commands/configfile.c configfile_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/disk/fs_file.c b/disk/fs_file.c deleted file mode 100644 index e09568250..000000000 --- a/disk/fs_file.c +++ /dev/null @@ -1,136 +0,0 @@ -/* fs_file.c - Access partition by a file it contains. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 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 3 of the License, or - * (at your option) any later version. - * - * GRUB 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, see . - */ - -#include -#include -#include -#include -#include -#include - -static grub_device_t -search_fs_file (const char *key, unsigned long *count) -{ - char *filename = NULL; - grub_device_t ret = NULL; - *count = 0; - - auto int iterate_device (const char *name); - int iterate_device (const char *name) - { - int len; - grub_file_t file; - - (*count)++; - - len = grub_strlen (name) + 2 + grub_strlen (key) + 1; - filename = grub_realloc (filename, len); - if (! filename) - return 1; - - grub_sprintf (filename, "(%s)%s", name, key); - file = grub_file_open (filename); - if (file) - { - grub_file_close (file); - ret = grub_device_open (name); - return 1; - } - - grub_errno = GRUB_ERR_NONE; - return 0; - } - - grub_device_iterate (iterate_device); - grub_free (filename); - - return ret; -} - -static grub_err_t -grub_fs_file_open (const char *name, grub_disk_t disk) -{ - grub_device_t dev; - - if (grub_strncmp (name, "FILE=", sizeof ("FILE=") - 1)) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a FILE virtual volume"); - - dev = search_fs_file (name + sizeof ("FILE=") - 1, &disk->id); - if (! dev) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no matching file found"); - - disk->total_sectors = dev->disk->total_sectors; - disk->has_partitions = 0; - if (dev->disk->partition) - { - disk->partition = grub_malloc (sizeof (*disk->partition)); - if (disk->partition) - grub_memcpy (disk->partition, dev->disk->partition, - sizeof (*disk->partition)); - } - else - disk->partition = NULL; - - disk->data = dev; - - return GRUB_ERR_NONE; -} - -static void -grub_fs_file_close (grub_disk_t disk) -{ - grub_device_t parent = disk->data; - grub_device_close (parent); -} - -static grub_err_t -grub_fs_file_read (grub_disk_t disk, grub_disk_addr_t sector, - grub_size_t size, char *buf) -{ - grub_device_t parent = disk->data; - return parent->disk->dev->read (parent->disk, sector, size, buf); -} - -static grub_err_t -grub_fs_file_write (grub_disk_t disk, grub_disk_addr_t sector, - grub_size_t size, const char *buf) -{ - grub_device_t parent = disk->data; - return parent->disk->dev->write (parent->disk, sector, size, buf); -} - -static struct grub_disk_dev grub_fs_file_dev = { - .name = "fs_file", - .id = GRUB_DISK_DEVICE_FILE_ID, - .open = grub_fs_file_open, - .close = grub_fs_file_close, - .read = grub_fs_file_read, - .write = grub_fs_file_write, - .next = 0 -}; - -GRUB_MOD_INIT (fs_file) -{ - grub_disk_dev_register (&grub_fs_file_dev); -} - -GRUB_MOD_FINI (fs_file) -{ - grub_disk_dev_unregister (&grub_fs_file_dev); -} diff --git a/disk/fs_uuid.c b/disk/fs_uuid.c deleted file mode 100644 index 6901dbacf..000000000 --- a/disk/fs_uuid.c +++ /dev/null @@ -1,149 +0,0 @@ -/* fs_uuid.c - Access disks by their filesystem UUID. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008 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 3 of the License, or - * (at your option) any later version. - * - * GRUB 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, see . - */ - -#include -#include -#include -#include -#include -#include - -#include -#include - -static grub_device_t -search_fs_uuid (const char *key, unsigned long *count) -{ - *count = 0; - grub_device_t ret = NULL; - - 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->uuid) - { - char *uuid; - - (fs->uuid) (dev, &uuid); - if (grub_errno == GRUB_ERR_NONE && uuid) - { - (*count)++; - - if (grub_strcasecmp (uuid, key) == 0) - { - ret = dev; - grub_free (uuid); - return 1; - } - grub_free (uuid); - } - } - - grub_device_close (dev); - } - - grub_errno = GRUB_ERR_NONE; - return 0; - } - - grub_device_iterate (iterate_device); - - return ret; -} - -static grub_err_t -grub_fs_uuid_open (const char *name, grub_disk_t disk) -{ - grub_device_t dev; - - if (grub_strncmp (name, "UUID=", sizeof ("UUID=")-1)) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a UUID virtual volume"); - - dev = search_fs_uuid (name + sizeof ("UUID=") - 1, &disk->id); - if (! dev) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no matching UUID found"); - - disk->total_sectors = dev->disk->total_sectors; - disk->has_partitions = 0; - if (dev->disk->partition) - { - disk->partition = grub_malloc (sizeof (*disk->partition)); - if (disk->partition) - grub_memcpy (disk->partition, dev->disk->partition, - sizeof (*disk->partition)); - } - else - disk->partition = NULL; - - disk->data = dev; - - return GRUB_ERR_NONE; -} - -static void -grub_fs_uuid_close (grub_disk_t disk __attribute((unused))) -{ - grub_device_t parent = disk->data; - grub_device_close (parent); -} - -static grub_err_t -grub_fs_uuid_read (grub_disk_t disk, grub_disk_addr_t sector, - grub_size_t size, char *buf) -{ - grub_device_t parent = disk->data; - return parent->disk->dev->read (parent->disk, sector, size, buf); -} - -static grub_err_t -grub_fs_uuid_write (grub_disk_t disk, grub_disk_addr_t sector, - grub_size_t size, const char *buf) -{ - grub_device_t parent = disk->data; - return parent->disk->dev->write (parent->disk, sector, size, buf); -} - -static struct grub_disk_dev grub_fs_uuid_dev = - { - .name = "fs_uuid", - .id = GRUB_DISK_DEVICE_UUID_ID, - .open = grub_fs_uuid_open, - .close = grub_fs_uuid_close, - .read = grub_fs_uuid_read, - .write = grub_fs_uuid_write, - .next = 0 - }; - -GRUB_MOD_INIT(fs_uuid) -{ - grub_disk_dev_register (&grub_fs_uuid_dev); -} - -GRUB_MOD_FINI(fs_uuid) -{ - grub_disk_dev_unregister (&grub_fs_uuid_dev); -} From afba34eb21c649c8874b3ba58cad990a08557fbe Mon Sep 17 00:00:00 2001 From: phcoder Date: Tue, 22 Sep 2009 09:38:12 +0200 Subject: [PATCH 4/9] use search_fs_uuid --- util/i386/pc/grub-install.in | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/util/i386/pc/grub-install.in b/util/i386/pc/grub-install.in index 8ceb811dd..78500766c 100644 --- a/util/i386/pc/grub-install.in +++ b/util/i386/pc/grub-install.in @@ -271,6 +271,7 @@ modules="$modules $disk_module" modules="$modules $fs_module $partmap_module $devabstraction_module" prefix_drive= +config= if [ "x${devabstraction_module}" = "x" ] ; then if echo "${install_device}" | grep -qx "(.*)" ; then install_drive="${install_device}" @@ -289,16 +290,16 @@ if [ "x${devabstraction_module}" = "x" ] ; then echo "UUID needed with ata mod, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2 exit 1 fi - prefix_drive="(UUID=${uuid})" - modules="$modules fs_uuid" + config="search_fs_uuid ${uuid} root" + modules="$modules search_fs_uuid" elif [ "x${grub_drive}" != "x${install_drive}" ] ; then uuid="`$grub_probe --target=fs_uuid --device ${grub_device}`" if [ "x${uuid}" = "x" ] ; then echo "You attempted a cross-disk install, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2 exit 1 fi - prefix_drive="(UUID=${uuid})" - modules="$modules fs_uuid" + config="search_fs_uuid ${uuid} root" + modules="$modules search_fs_uuid" fi else prefix_drive=`$grub_probe --target=drive --device ${grub_device}` @@ -309,14 +310,20 @@ if [ "x${relative_grubdir}" = "x" ] ; then relative_grubdir=/ fi +config_opt= +echo $config > ${grubdir}/load.cfg +if [ x$config != x ]; then + config_opt="-c $config " +fi + if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then - $grub_mkimage --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1 + $grub_mkimage ${config_opt} --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1 # Now perform the installation. $grub_setup ${setup_verbose} ${setup_force} --directory=${grubdir} --device-map=${device_map} \ ${install_device} || exit 1 else - $grub_mkimage -d ${pkglibdir} --output=/boot/multiboot.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1 + $grub_mkimage ${config_opt} -d ${pkglibdir} --output=/boot/multiboot.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1 fi # Prompt the user to check if the device map is correct. From 7f4f3f581ce36c66644df68e7107466540e690ab Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 22 Nov 2009 12:22:19 +0100 Subject: [PATCH 5/9] Unify grub-install.in for sparc64 with i386-ieee1275 --- util/grub-install.in | 10 +- util/sparc64/ieee1275/grub-install.in | 276 -------------------------- 2 files changed, 6 insertions(+), 280 deletions(-) delete mode 100644 util/sparc64/ieee1275/grub-install.in diff --git a/util/grub-install.in b/util/grub-install.in index a004b2d11..a18a530a1 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -32,7 +32,7 @@ platform=@platform@ pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}` grub_setup=${sbindir}/`echo grub-setup | sed ${transform}` -if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then +if [ "${target_cpu}-${platform}" = "i386-pc" || "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` else grub_mkimage=${bindir}/`echo grub-mkelfimage | sed ${transform}` @@ -51,6 +51,8 @@ debug=no if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then disk_module=biosdisk +elif [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then + disk_module= else disk_module=ata fi @@ -177,7 +179,7 @@ device_map=${grubdir}/device.map grub_probe="${grub_probe} --device-map=${device_map}" # Check if GRUB is installed. -if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then +if [ "${target_cpu}-${platform}" = "i386-pc" || "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then set $grub_setup dummy if test -f "$1"; then : @@ -239,7 +241,7 @@ done for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do cp -f $file ${grubdir} || exit 1 done -if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then +if [ "${target_cpu}-${platform}" = "i386-pc" || "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then for file in ${pkglibdir}/*.img ${pkglibdir}/efiemu??.o; do if test -f $file; then cp -f $file ${grubdir} || exit 1 @@ -316,7 +318,7 @@ if [ x$config != x ]; then config_opt="-c $config " fi -if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then +if [ "${target_cpu}-${platform}" = "i386-pc" || "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then $grub_mkimage ${config_opt} --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1 # Now perform the installation. diff --git a/util/sparc64/ieee1275/grub-install.in b/util/sparc64/ieee1275/grub-install.in deleted file mode 100644 index a03869cb3..000000000 --- a/util/sparc64/ieee1275/grub-install.in +++ /dev/null @@ -1,276 +0,0 @@ -#! /bin/sh - -# Install GRUB on your drive. -# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 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 3 of the License, or -# (at your option) any later version. -# -# GRUB 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, see . - -# Initialize some variables. -transform="@program_transform_name@" - -prefix=@prefix@ -exec_prefix=@exec_prefix@ -sbindir=@sbindir@ -bindir=@bindir@ -libdir=@libdir@ -PACKAGE_NAME=@PACKAGE_NAME@ -PACKAGE_TARNAME=@PACKAGE_TARNAME@ -PACKAGE_VERSION=@PACKAGE_VERSION@ -target_cpu=@target_cpu@ -platform=@platform@ -pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}` - -# for make_system_path_relative_to_its_root() -. ${libdir}/grub/grub-mkconfig_lib - -grub_setup=${sbindir}/`echo grub-setup | sed ${transform}` -grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` -grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}` -grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` -rootdir= -grub_prefix=`echo /boot/grub | sed ${transform}` -modules= - -install_device= -no_floppy= -force_lba= -recheck=no -debug=no - -# Usage: usage -# Print the usage. -usage () { - cat <. -EOF -} - -# Check the arguments. -for option in "$@"; do - case "$option" in - -h | --help) - usage - exit 0 ;; - -v | --version) - echo "grub-install (GNU GRUB ${PACKAGE_VERSION})" - exit 0 ;; - --modules=*) - modules=`echo "$option" | sed 's/--modules=//'` ;; - --root-directory=*) - rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; - --grub-setup=*) - grub_setup=`echo "$option" | sed 's/--grub-setup=//'` ;; - --grub-mkimage=*) - grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;; - --grub-mkdevicemap=*) - grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;; - --grub-probe=*) - grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;; - --no-floppy) - no_floppy="--no-floppy" ;; - --recheck) - recheck=yes ;; - # This is an undocumented feature... - --debug) - debug=yes ;; - -*) - echo "Unrecognized option \`$option'" 1>&2 - usage - exit 1 - ;; - *) - if test "x$install_device" != x; then - echo "More than one install_devices?" 1>&2 - usage - exit 1 - fi - install_device="${option}" ;; - esac -done - -if test "x$install_device" = x; then - echo "install_device not specified." 1>&2 - usage - exit 1 -fi - -# If the debugging feature is enabled, print commands. -setup_verbose= -if test $debug = yes; then - set -x - setup_verbose="--verbose" -fi - -# Initialize these directories here, since ROOTDIR was initialized. -bootdir=${rootdir}/boot -grubdir=${bootdir}/`echo grub | sed ${transform}` -device_map=${grubdir}/device.map - -grub_probe="${grub_probe} --device-map=${device_map}" - -# Check if GRUB is installed. -set $grub_setup dummy -if test -f "$1"; then - : -else - echo "$1: Not found." 1>&2 - exit 1 -fi - -set $grub_mkimage dummy -if test -f "$1"; then - : -else - echo "$1: Not found." 1>&2 - exit 1 -fi - -set $grub_mkdevicemap dummy -if test -f "$1"; then - : -else - echo "$1: Not found." 1>&2 - exit 1 -fi - -# Create the GRUB directory if it is not present. -test -d "$bootdir" || mkdir "$bootdir" || exit 1 -test -d "$grubdir" || mkdir "$grubdir" || exit 1 - -# If --recheck is specified, remove the device map, if present. -if test $recheck = yes; then - rm -f $device_map -fi - -# Create the device map file if it is not present. -if test -f "$device_map"; then - : -else - # Create a safe temporary file. - test -n "$mklog" && log_file=`$mklog` - - $grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1 -fi - -# Make sure that there is no duplicated entry. -tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' $device_map \ - | sort | uniq -d | sed -n 1p` -if test -n "$tmp"; then - echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2 - exit 1 -fi - -# Copy the GRUB images to the GRUB directory. -for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img; do - if test -f $file && [ "`basename $file`" != menu.lst ]; then - rm -f $file || exit 1 - fi -done -for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do - cp -f $file ${grubdir} || exit 1 -done - -for file in ${pkglibdir}/*.img; do - cp -f $file ${grubdir} || exit 1 -done - -# Write device to a variable so we don't have to traverse /dev every time. -grub_device=`$grub_probe --target=device ${grubdir}` - -# Create the core image. First, auto-detect the filesystem module. -fs_module=`$grub_probe --target=fs --device ${grub_device}` -if test "x$fs_module" = x -a "x$modules" = x; then - echo "Auto-detection of a filesystem module failed." 1>&2 - echo "Please specify the module with the option \`--modules' explicitly." 1>&2 - exit 1 -fi - -# Then the partition map module. In order to support partition-less media, -# this command is allowed to fail (--target=fs already grants us that the -# filesystem will be accessible). -partmap_module=`$grub_probe --target=partmap --device ${grub_device} 2> /dev/null` - -# Device abstraction module, if any (lvm, raid). -devabstraction_module=`$grub_probe --target=abstraction --device ${grub_device}` - -modules="$modules $fs_module $partmap_module $devabstraction_module" - -prefix_drive= -if [ "x${devabstraction_module}" = "x" ] ; then - if echo "${install_device}" | grep -qx "(.*)" ; then - install_drive="${install_device}" - else - install_drive="`$grub_probe --target=drive --device ${install_device}`" - fi - grub_drive="`$grub_probe --target=drive --device ${grub_device}`" - - # Strip partition number - install_drive="`echo ${install_drive} | sed -e 's/\([^\]\),[0-9]*/\1/g'`" - grub_drive="`echo ${grub_drive} | sed -e 's/\([^\]\),[0-9]*/\1/g'`" - if [ "x${grub_drive}" != "x${install_drive}" ] ; then - uuid="`$grub_probe --target=fs_uuid --device ${grub_device}`" - if [ "x${uuid}" = "x" ] ; then - echo "You attempted a cross-disk install, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2 - exit 1 - fi - prefix_drive="(UUID=${uuid})" - modules="$modules fs_uuid" - fi -else - prefix_drive=`$grub_probe --target=drive --device ${grub_device}` -fi - -relative_grubdir=`make_system_path_relative_to_its_root ${grubdir}` || exit 1 -if [ "x${relative_grubdir}" = "x" ] ; then - relative_grubdir=/ -fi - -$grub_mkimage --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1 - -# Now perform the installation. -$grub_setup ${setup_verbose} --directory=${grubdir} --device-map=${device_map} \ - ${install_device} || exit 1 - -# Prompt the user to check if the device map is correct. -echo "Installation finished. No error reported." -echo "This is the contents of the device map $device_map." -echo "Check if this is correct or not. If any of the lines is incorrect," -echo "fix it and re-run the script \`grub-install'." -echo - -cat $device_map - -# Bye. -exit 0 From 937d332db3d491b2d1018519a84d54dec454a8f3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 22 Nov 2009 13:15:49 +0100 Subject: [PATCH 6/9] compile and configuration fixes --- commands/search.c | 2 +- commands/search_wrap.c | 12 ++++++++++++ conf/common.rmk | 17 +++++++++-------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/commands/search.c b/commands/search.c index 60b5bbf04..e885391cf 100644 --- a/commands/search.c +++ b/commands/search.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include void FUNC_NAME (const char *key, const char *var, int no_floppy) diff --git a/commands/search_wrap.c b/commands/search_wrap.c index 35cce3f5e..d28bb744e 100644 --- a/commands/search_wrap.c +++ b/commands/search_wrap.c @@ -17,6 +17,14 @@ * along with GRUB. If not, see . */ +#include +#include +#include +#include +#include +#include +#include + static const struct grub_arg_option options[] = { {"file", 'f', 0, "search devices by a file", 0, 0}, @@ -36,6 +44,10 @@ enum options SEARCH_NO_FLOPPY, }; +void grub_search_fs_file (const char *key, const char *var, int no_floppy); +void grub_search_fs_uuid (const char *key, const char *var, int no_floppy); +void grub_search_label (const char *key, const char *var, int no_floppy); + static grub_err_t grub_cmd_search (grub_extcmd_t cmd, int argc, char **args) { diff --git a/conf/common.rmk b/conf/common.rmk index 00830e54d..f27c837b8 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -370,8 +370,7 @@ scsi_mod_LDFLAGS = $(COMMON_LDFLAGS) # Commands. pkglib_MODULES += minicmd.mod extcmd.mod hello.mod handler.mod \ - ls.mod cmp.mod cat.mod help.mod search_file.mod \ - search_fs_uuid.mod search_fs_label.mod search.mod loopback.mod \ + ls.mod cmp.mod cat.mod help.mod search.mod loopback.mod \ configfile.mod echo.mod \ terminfo.mod test.mod blocklist.mod hexdump.mod \ read.mod sleep.mod loadenv.mod crc.mod parttool.mod \ @@ -449,10 +448,12 @@ search_mod_SOURCES = commands/search_wrap.c search_mod_CFLAGS = $(COMMON_CFLAGS) search_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += search_fs_file.mod search_fs_uuid.mod search_label.mod + # For search.mod. -search_file_mod_SOURCES = commands/search_file.c -search_file_mod_CFLAGS = $(COMMON_CFLAGS) -search_file_mod_LDFLAGS = $(COMMON_LDFLAGS) +search_fs_file_mod_SOURCES = commands/search_file.c +search_fs_file_mod_CFLAGS = $(COMMON_CFLAGS) +search_fs_file_mod_LDFLAGS = $(COMMON_LDFLAGS) # For search.mod. search_label_mod_SOURCES = commands/search_label.c @@ -460,9 +461,9 @@ search_label_mod_CFLAGS = $(COMMON_CFLAGS) search_label_mod_LDFLAGS = $(COMMON_LDFLAGS) # For search.mod. -search_uuid_mod_SOURCES = commands/search_uuid.c -search_uuid_mod_CFLAGS = $(COMMON_CFLAGS) -search_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS) +search_fs_uuid_mod_SOURCES = commands/search_uuid.c +search_fs_uuid_mod_CFLAGS = $(COMMON_CFLAGS) +search_fs_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS) # For test.mod. test_mod_SOURCES = commands/test.c From 4996893238fd3a2314aac73c856381cc09cacf5d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Mon, 23 Nov 2009 21:15:44 +0100 Subject: [PATCH 7/9] definition fixes --- commands/search.c | 9 ++--- commands/search_wrap.c | 5 +-- include/grub/search.h | 26 ++++++++++++++ po/ca.po | 81 +----------------------------------------- 4 files changed, 33 insertions(+), 88 deletions(-) create mode 100644 include/grub/search.h diff --git a/commands/search.c b/commands/search.c index e885391cf..fc73b550e 100644 --- a/commands/search.c +++ b/commands/search.c @@ -26,6 +26,7 @@ #include #include #include +#include void FUNC_NAME (const char *key, const char *var, int no_floppy) @@ -153,9 +154,9 @@ grub_cmd_do_search (grub_command_t cmd __attribute__ ((unused)), int argc, static grub_command_t cmd; -#ifdef SEARCH_FILE +#ifdef DO_SEARCH_FILE GRUB_MOD_INIT(search_file) -#elif defined (SEARCH_FS_UUID) +#elif defined (DO_SEARCH_FS_UUID) GRUB_MOD_INIT(search_fs_uuid) #else GRUB_MOD_INIT(search_fs_label) @@ -169,9 +170,9 @@ GRUB_MOD_INIT(search_fs_label) " set to a variable."); } -#ifdef SEARCH_FILE +#ifdef DO_SEARCH_FILE GRUB_MOD_FINI(search_file) -#elif defined (SEARCH_FS_UUID) +#elif defined (DO_SEARCH_FS_UUID) GRUB_MOD_FINI(search_fs_uuid) #else GRUB_MOD_FINI(search_fs_label) diff --git a/commands/search_wrap.c b/commands/search_wrap.c index d28bb744e..8bb26cd0c 100644 --- a/commands/search_wrap.c +++ b/commands/search_wrap.c @@ -24,6 +24,7 @@ #include #include #include +#include static const struct grub_arg_option options[] = { @@ -44,10 +45,6 @@ enum options SEARCH_NO_FLOPPY, }; -void grub_search_fs_file (const char *key, const char *var, int no_floppy); -void grub_search_fs_uuid (const char *key, const char *var, int no_floppy); -void grub_search_label (const char *key, const char *var, int no_floppy); - static grub_err_t grub_cmd_search (grub_extcmd_t cmd, int argc, char **args) { diff --git a/include/grub/search.h b/include/grub/search.h new file mode 100644 index 000000000..e8f9db285 --- /dev/null +++ b/include/grub/search.h @@ -0,0 +1,26 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 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 3 of the License, or + * (at your option) any later version. + * + * GRUB 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, see . + */ + +#ifndef GRUB_SEARCH_HEADER +#define GRUB_SEARCH_HEADER 1 + +void grub_search_fs_file (const char *key, const char *var, int no_floppy); +void grub_search_fs_uuid (const char *key, const char *var, int no_floppy); +void grub_search_label (const char *key, const char *var, int no_floppy); + +#endif diff --git a/po/ca.po b/po/ca.po index 3f9b0ac32..7c1025fdc 100644 --- a/po/ca.po +++ b/po/ca.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: GNU GRUB\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-11-19 00:16+0100\n" +"POT-Creation-Date: 2009-11-23 21:07+0100\n" "PO-Revision-Date: 2009-11-17 12:26+0100\n" "Last-Translator: Robert Millan \n" "Language-Team: None \n" @@ -22,30 +22,10 @@ msgstr "" msgid "cannot compress the kernel image" msgstr "" -#: util/i386/pc/grub-mkimage.c:117 -#, c-format -msgid "the size of memory disk is 0x%x" -msgstr "" - -#: util/i386/pc/grub-mkimage.c:124 -#, c-format -msgid "the size of config file is 0x%x" -msgstr "" - -#: util/i386/pc/grub-mkimage.c:132 -#, c-format -msgid "the total module size is 0x%x" -msgstr "" - #: util/i386/pc/grub-mkimage.c:138 msgid "prefix is too long" msgstr "" -#: util/i386/pc/grub-mkimage.c:199 -#, c-format -msgid "the core size is 0x%x" -msgstr "" - #: util/i386/pc/grub-mkimage.c:206 msgid "the core image is too big" msgstr "" @@ -89,20 +69,10 @@ msgstr "" msgid "cannot open %s" msgstr "" -#: util/i386/pc/grub-setup.c:162 -#, c-format -msgid "the first sector is <%llu,%u,%u>" -msgstr "" - #: util/i386/pc/grub-setup.c:166 msgid "The first sector of the core file is not sector-aligned" msgstr "" -#: util/i386/pc/grub-setup.c:176 -#, c-format -msgid "saving <%llu,%u,%u> with the segment 0x%x" -msgstr "" - #: util/i386/pc/grub-setup.c:180 msgid "Non-sector-aligned data is found in the core file" msgstr "" @@ -126,11 +96,6 @@ msgstr "" msgid "The size of `%s' is too large" msgstr "" -#: util/i386/pc/grub-setup.c:247 -#, c-format -msgid "setting the root device to `%s'" -msgstr "" - #: util/i386/pc/grub-setup.c:261 #, c-format msgid "Unable to identify a filesystem in %s; safety check can't be performed" @@ -149,11 +114,6 @@ msgstr "" msgid "No DOS-style partitions found" msgstr "" -#: util/i386/pc/grub-setup.c:325 -#, c-format -msgid "dos partition is %d, bsd partition is %d" -msgstr "" - #: util/i386/pc/grub-setup.c:330 util/i386/pc/grub-setup.c:355 msgid "" "Attempting to install GRUB to a partitionless disk. This is a BAD idea." @@ -185,11 +145,6 @@ msgstr "" msgid "Your embedding area is unusually small. core.img won't fit in it." msgstr "" -#: util/i386/pc/grub-setup.c:381 -#, c-format -msgid "the core image will be embedded at sector 0x%llx" -msgstr "" - #: util/i386/pc/grub-setup.c:418 msgid "" "Embedding is not possible, but this is required when the root device is on a " @@ -217,30 +172,6 @@ msgstr "" msgid "attempting to read the core image `%s' from GRUB again" msgstr "" -#: util/i386/pc/grub-setup.c:449 -#, c-format -msgid "" -"succeeded in opening the core image but the size is different (%d != %d)" -msgstr "" - -#: util/i386/pc/grub-setup.c:453 -#, c-format -msgid "succeeded in opening the core image but cannot read %d bytes" -msgstr "" - -#: util/i386/pc/grub-setup.c:476 -msgid "succeeded in opening the core image but the data is different" -msgstr "" - -#: util/i386/pc/grub-setup.c:487 -msgid "couldn't open the core image" -msgstr "" - -#: util/i386/pc/grub-setup.c:490 -#, c-format -msgid "error message = %s" -msgstr "" - #: util/i386/pc/grub-setup.c:498 #, c-format msgid "Cannot read `%s' correctly" @@ -258,11 +189,6 @@ msgstr "" msgid "Failed to read the rest sectors of the core image" msgstr "" -#: util/i386/pc/grub-setup.c:544 -#, c-format -msgid "opening the core image `%s'" -msgstr "" - #: util/i386/pc/grub-setup.c:547 #, c-format msgid "Cannot open `%s'" @@ -310,11 +236,6 @@ msgstr "" msgid "Invalid root device `%s'" msgstr "" -#: util/i386/pc/grub-setup.c:766 -#, c-format -msgid "guessing the root device failed, because of `%s'" -msgstr "" - #: util/i386/pc/grub-setup.c:768 msgid "Cannot guess the root device. Specify the option ``--root-device''." msgstr "" From 20f1afd41afa3db3b00c7c9398a4cdcd67cfde75 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 25 Nov 2009 22:34:35 +0100 Subject: [PATCH 8/9] Fixed various script issues. Thanks fezie for testing. --- util/grub-install.in | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/util/grub-install.in b/util/grub-install.in index a18a530a1..5118e6e56 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -32,7 +32,7 @@ platform=@platform@ pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}` grub_setup=${sbindir}/`echo grub-setup | sed ${transform}` -if [ "${target_cpu}-${platform}" = "i386-pc" || "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then +if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` else grub_mkimage=${bindir}/`echo grub-mkelfimage | sed ${transform}` @@ -179,7 +179,7 @@ device_map=${grubdir}/device.map grub_probe="${grub_probe} --device-map=${device_map}" # Check if GRUB is installed. -if [ "${target_cpu}-${platform}" = "i386-pc" || "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then +if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then set $grub_setup dummy if test -f "$1"; then : @@ -241,7 +241,7 @@ done for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do cp -f $file ${grubdir} || exit 1 done -if [ "${target_cpu}-${platform}" = "i386-pc" || "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then +if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then for file in ${pkglibdir}/*.img ${pkglibdir}/efiemu??.o; do if test -f $file; then cp -f $file ${grubdir} || exit 1 @@ -272,8 +272,14 @@ devabstraction_module=`$grub_probe --target=abstraction --device ${grub_device}` modules="$modules $disk_module" modules="$modules $fs_module $partmap_module $devabstraction_module" +relative_grubdir=`make_system_path_relative_to_its_root ${grubdir}` || exit 1 +if [ "x${relative_grubdir}" = "x" ] ; then + relative_grubdir=/ +fi + prefix_drive= -config= +config_opt= + if [ "x${devabstraction_module}" = "x" ] ; then if echo "${install_device}" | grep -qx "(.*)" ; then install_drive="${install_device}" @@ -292,7 +298,9 @@ if [ "x${devabstraction_module}" = "x" ] ; then echo "UUID needed with ata mod, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2 exit 1 fi - config="search_fs_uuid ${uuid} root" + echo "search.fs_uuid ${uuid} root " > ${grubdir}/load.cfg + echo 'set prefix=($root)'"${relative_grubdir}" >> ${grubdir}/load.cfg + config_opt="-c ${grubdir}/load.cfg " modules="$modules search_fs_uuid" elif [ "x${grub_drive}" != "x${install_drive}" ] ; then uuid="`$grub_probe --target=fs_uuid --device ${grub_device}`" @@ -300,25 +308,16 @@ if [ "x${devabstraction_module}" = "x" ] ; then echo "You attempted a cross-disk install, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2 exit 1 fi - config="search_fs_uuid ${uuid} root" + echo "search.fs_uuid ${uuid} root " > ${grubdir}/load.cfg + echo 'set prefix=($root)'"${relative_grubdir}" >> ${grubdir}/load.cfg + config_opt="-c ${grubdir}/load.cfg " modules="$modules search_fs_uuid" fi else prefix_drive=`$grub_probe --target=drive --device ${grub_device}` fi -relative_grubdir=`make_system_path_relative_to_its_root ${grubdir}` || exit 1 -if [ "x${relative_grubdir}" = "x" ] ; then - relative_grubdir=/ -fi - -config_opt= -echo $config > ${grubdir}/load.cfg -if [ x$config != x ]; then - config_opt="-c $config " -fi - -if [ "${target_cpu}-${platform}" = "i386-pc" || "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then +if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then $grub_mkimage ${config_opt} --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1 # Now perform the installation. From 03157a273d846d04d724857eee0b538f0ef191ca Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Sat, 12 Dec 2009 00:10:38 +0000 Subject: [PATCH 9/9] util/sparc64/ieee1275/grub-install.in was meant to be removed --- conf/sparc64-ieee1275.rmk | 2 +- util/sparc64/ieee1275/grub-install.in | 276 -------------------------- 2 files changed, 1 insertion(+), 277 deletions(-) delete mode 100644 util/sparc64/ieee1275/grub-install.in diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index d19e927a5..32723b635 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -93,7 +93,7 @@ grub_ofpathname_SOURCES = util/sparc64/ieee1275/grub-ofpathname.c \ sbin_SCRIPTS = grub-install # For grub-install. -grub_install_SOURCES = util/sparc64/ieee1275/grub-install.in +grub_install_SOURCES = util/grub-install.in # Modules. pkglib_MODULES = halt.mod \ diff --git a/util/sparc64/ieee1275/grub-install.in b/util/sparc64/ieee1275/grub-install.in deleted file mode 100644 index 5cfb858d7..000000000 --- a/util/sparc64/ieee1275/grub-install.in +++ /dev/null @@ -1,276 +0,0 @@ -#! /bin/sh - -# Install GRUB on your drive. -# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 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 3 of the License, or -# (at your option) any later version. -# -# GRUB 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, see . - -# Initialize some variables. -transform="@program_transform_name@" - -prefix=@prefix@ -exec_prefix=@exec_prefix@ -sbindir=@sbindir@ -bindir=@bindir@ -libdir=@libdir@ -PACKAGE_NAME=@PACKAGE_NAME@ -PACKAGE_TARNAME=@PACKAGE_TARNAME@ -PACKAGE_VERSION=@PACKAGE_VERSION@ -target_cpu=@target_cpu@ -platform=@platform@ -pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}` - -grub_setup=${sbindir}/`echo grub-setup | sed ${transform}` -grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` -grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}` -grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` -rootdir= -grub_prefix=`echo /boot/grub | sed ${transform}` -modules= - -install_device= -no_floppy= -force_lba= -recheck=no -debug=no - -# Usage: usage -# Print the usage. -usage () { - cat <. -EOF -} - -# Check the arguments. -for option in "$@"; do - case "$option" in - -h | --help) - usage - exit 0 ;; - -v | --version) - echo "grub-install (GNU GRUB ${PACKAGE_VERSION})" - exit 0 ;; - --modules=*) - modules=`echo "$option" | sed 's/--modules=//'` ;; - --root-directory=*) - rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; - --grub-setup=*) - grub_setup=`echo "$option" | sed 's/--grub-setup=//'` ;; - --grub-mkimage=*) - grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;; - --grub-mkdevicemap=*) - grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;; - --grub-probe=*) - grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;; - --no-floppy) - no_floppy="--no-floppy" ;; - --recheck) - recheck=yes ;; - # This is an undocumented feature... - --debug) - debug=yes ;; - -*) - echo "Unrecognized option \`$option'" 1>&2 - usage - exit 1 - ;; - *) - if test "x$install_device" != x; then - echo "More than one install_devices?" 1>&2 - usage - exit 1 - fi - install_device="${option}" ;; - esac -done - -# for make_system_path_relative_to_its_root() -. ${libdir}/grub/grub-mkconfig_lib - -if test "x$install_device" = x; then - echo "install_device not specified." 1>&2 - usage - exit 1 -fi - -# If the debugging feature is enabled, print commands. -setup_verbose= -if test $debug = yes; then - set -x - setup_verbose="--verbose" -fi - -# Initialize these directories here, since ROOTDIR was initialized. -bootdir=${rootdir}/boot -grubdir=${bootdir}/`echo grub | sed ${transform}` -device_map=${grubdir}/device.map - -grub_probe="${grub_probe} --device-map=${device_map}" - -# Check if GRUB is installed. -set $grub_setup dummy -if test -f "$1"; then - : -else - echo "$1: Not found." 1>&2 - exit 1 -fi - -set $grub_mkimage dummy -if test -f "$1"; then - : -else - echo "$1: Not found." 1>&2 - exit 1 -fi - -set $grub_mkdevicemap dummy -if test -f "$1"; then - : -else - echo "$1: Not found." 1>&2 - exit 1 -fi - -# Create the GRUB directory if it is not present. -test -d "$bootdir" || mkdir "$bootdir" || exit 1 -test -d "$grubdir" || mkdir "$grubdir" || exit 1 - -# If --recheck is specified, remove the device map, if present. -if test $recheck = yes; then - rm -f $device_map -fi - -# Create the device map file if it is not present. -if test -f "$device_map"; then - : -else - # Create a safe temporary file. - test -n "$mklog" && log_file=`$mklog` - - $grub_mkdevicemap --device-map=$device_map $no_floppy || exit 1 -fi - -# Make sure that there is no duplicated entry. -tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' $device_map \ - | sort | uniq -d | sed -n 1p` -if test -n "$tmp"; then - echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2 - exit 1 -fi - -# Copy the GRUB images to the GRUB directory. -for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img; do - if test -f $file && [ "`basename $file`" != menu.lst ]; then - rm -f $file || exit 1 - fi -done -for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do - cp -f $file ${grubdir} || exit 1 -done - -for file in ${pkglibdir}/*.img; do - cp -f $file ${grubdir} || exit 1 -done - -# Write device to a variable so we don't have to traverse /dev every time. -grub_device=`$grub_probe --target=device ${grubdir}` - -# Create the core image. First, auto-detect the filesystem module. -fs_module=`$grub_probe --target=fs --device ${grub_device}` -if test "x$fs_module" = x -a "x$modules" = x; then - echo "Auto-detection of a filesystem module failed." 1>&2 - echo "Please specify the module with the option \`--modules' explicitly." 1>&2 - exit 1 -fi - -# Then the partition map module. In order to support partition-less media, -# this command is allowed to fail (--target=fs already grants us that the -# filesystem will be accessible). -partmap_module=`$grub_probe --target=partmap --device ${grub_device} 2> /dev/null` - -# Device abstraction module, if any (lvm, raid). -devabstraction_module=`$grub_probe --target=abstraction --device ${grub_device}` - -modules="$modules $fs_module $partmap_module $devabstraction_module" - -prefix_drive= -if [ "x${devabstraction_module}" = "x" ] ; then - if echo "${install_device}" | grep -qx "(.*)" ; then - install_drive="${install_device}" - else - install_drive="`$grub_probe --target=drive --device ${install_device}`" - fi - grub_drive="`$grub_probe --target=drive --device ${grub_device}`" - - # Strip partition number - install_drive="`echo ${install_drive} | sed -e 's/\([^\]\),[0-9]*/\1/g'`" - grub_drive="`echo ${grub_drive} | sed -e 's/\([^\]\),[0-9]*/\1/g'`" - if [ "x${grub_drive}" != "x${install_drive}" ] ; then - uuid="`$grub_probe --target=fs_uuid --device ${grub_device}`" - if [ "x${uuid}" = "x" ] ; then - echo "You attempted a cross-disk install, but the filesystem containing ${grubdir} does not support UUIDs." 1>&2 - exit 1 - fi - prefix_drive="(UUID=${uuid})" - modules="$modules fs_uuid" - fi -else - prefix_drive=`$grub_probe --target=drive --device ${grub_device}` -fi - -relative_grubdir=`make_system_path_relative_to_its_root ${grubdir}` || exit 1 -if [ "x${relative_grubdir}" = "x" ] ; then - relative_grubdir=/ -fi - -$grub_mkimage --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1 - -# Now perform the installation. -$grub_setup ${setup_verbose} --directory=${grubdir} --device-map=${device_map} \ - ${install_device} || exit 1 - -# Prompt the user to check if the device map is correct. -echo "Installation finished. No error reported." -echo "This is the contents of the device map $device_map." -echo "Check if this is correct or not. If any of the lines is incorrect," -echo "fix it and re-run the script \`grub-install'." -echo - -cat $device_map - -# Bye. -exit 0