From fc2ef1172ca4e5b5407b5ca5d83221c2d4a325a8 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 5 Sep 2010 13:05:36 +0200 Subject: [PATCH] * grub-core/io/gzio.c (grub_gzio_open): Removed "transparent" parameter. Made static. (grub_gzfile_open): Removed. All users updated. (GRUB_MOD_INIT): New function. (GRUB_MOD_FINI): Likewise. * grub-core/kern/file.c (grub_file_filters_all): New variable. (grub_file_filters_enabled): Likewise. (grub_file_open): Handle filters. * grub-core/loader/i386/bsd.c (GRUB_MOD_INIT): Load gzio. * grub-core/normal/main.c (GRUB_MOD_INIT): Likewise. * include/grub/file.h (grub_file_filter_id_t): New type. (grub_file_filter_t): Likewise. (grub_file_filters_all): New extern variable. (grub_file_filters_enabled): Likewise. (grub_file_filter_register): New inline function. (grub_file_filter_unregister): Likewise. (grub_file_filter_disable): Likewise. (grub_file_filter_disable_compression): Likewise. * include/grub/gzio.h: Removed. --- ChangeLog | 22 ++++++++++++ grub-core/commands/acpi.c | 3 +- grub-core/commands/blocklist.c | 1 + grub-core/commands/cat.c | 3 +- grub-core/commands/cmp.c | 5 ++- grub-core/commands/crc.c | 1 + grub-core/commands/hashsum.c | 7 +++- grub-core/commands/hexdump.c | 3 +- grub-core/commands/loadenv.c | 2 ++ grub-core/commands/ls.c | 2 ++ grub-core/commands/search.c | 1 + grub-core/commands/test.c | 1 + grub-core/gettext/gettext.c | 5 ++- grub-core/io/gzio.c | 40 ++++++++------------- grub-core/kern/elf.c | 3 +- grub-core/kern/file.c | 26 ++++++++++++-- grub-core/loader/i386/bsd.c | 20 ++++++----- grub-core/loader/i386/linux.c | 1 + grub-core/loader/i386/pc/chainloader.c | 1 + grub-core/loader/i386/pc/linux.c | 1 + grub-core/loader/i386/xnu.c | 3 +- grub-core/loader/macho.c | 3 +- grub-core/loader/mips/linux.c | 1 + grub-core/loader/multiboot.c | 9 +++-- grub-core/loader/powerpc/ieee1275/linux.c | 1 + grub-core/loader/sparc64/ieee1275/linux.c | 3 +- grub-core/loader/xnu.c | 13 ++++--- grub-core/loader/xnu_resume.c | 1 + grub-core/normal/main.c | 3 ++ include/grub/file.h | 44 +++++++++++++++++++++++ include/grub/gzio.h | 28 --------------- util/grub-fstest.c | 1 + util/grub-probe.c | 1 + util/i386/pc/grub-setup.c | 2 ++ util/sparc64/ieee1275/grub-setup.c | 2 ++ 35 files changed, 165 insertions(+), 98 deletions(-) delete mode 100644 include/grub/gzio.h diff --git a/ChangeLog b/ChangeLog index 77f9232db..33de07ea1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2010-09-05 Vladimir Serbinenko + + * grub-core/io/gzio.c (grub_gzio_open): Removed "transparent" parameter. + Made static. + (grub_gzfile_open): Removed. All users updated. + (GRUB_MOD_INIT): New function. + (GRUB_MOD_FINI): Likewise. + * grub-core/kern/file.c (grub_file_filters_all): New variable. + (grub_file_filters_enabled): Likewise. + (grub_file_open): Handle filters. + * grub-core/loader/i386/bsd.c (GRUB_MOD_INIT): Load gzio. + * grub-core/normal/main.c (GRUB_MOD_INIT): Likewise. + * include/grub/file.h (grub_file_filter_id_t): New type. + (grub_file_filter_t): Likewise. + (grub_file_filters_all): New extern variable. + (grub_file_filters_enabled): Likewise. + (grub_file_filter_register): New inline function. + (grub_file_filter_unregister): Likewise. + (grub_file_filter_disable): Likewise. + (grub_file_filter_disable_compression): Likewise. + * include/grub/gzio.h: Removed. + 2010-09-04 BVK Chaitanya Filename expansion support for wildcards in GRUB script. diff --git a/grub-core/commands/acpi.c b/grub-core/commands/acpi.c index 1f17b63d6..b2edcc9cd 100644 --- a/grub-core/commands/acpi.c +++ b/grub-core/commands/acpi.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -628,7 +627,7 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args) grub_size_t size; char *buf; - file = grub_gzfile_open (args[i], 1); + file = grub_file_open (args[i]); if (! file) { free_tables (); diff --git a/grub-core/commands/blocklist.c b/grub-core/commands/blocklist.c index cace31113..4651fb32a 100644 --- a/grub-core/commands/blocklist.c +++ b/grub-core/commands/blocklist.c @@ -82,6 +82,7 @@ grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)), if (argc < 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified"); + grub_file_filter_disable_compression (); file = grub_file_open (args[0]); if (! file) return grub_errno; diff --git a/grub-core/commands/cat.c b/grub-core/commands/cat.c index a70118517..68ca83c5d 100644 --- a/grub-core/commands/cat.c +++ b/grub-core/commands/cat.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -48,7 +47,7 @@ grub_cmd_cat (grub_extcmd_context_t ctxt, int argc, char **args) if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required"); - file = grub_gzfile_open (args[0], 1); + file = grub_file_open (args[0]); if (! file) return grub_errno; diff --git a/grub-core/commands/cmp.c b/grub-core/commands/cmp.c index 626e1d022..d9e76a4d7 100644 --- a/grub-core/commands/cmp.c +++ b/grub-core/commands/cmp.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -44,8 +43,8 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)), grub_printf ("Compare file `%s' with `%s':\n", args[0], args[1]); - file1 = grub_gzfile_open (args[0], 1); - file2 = grub_gzfile_open (args[1], 1); + file1 = grub_file_open (args[0]); + file2 = grub_file_open (args[1]); if (! file1 || ! file2) goto cleanup; diff --git a/grub-core/commands/crc.c b/grub-core/commands/crc.c index 1c1a690aa..f165e1aaf 100644 --- a/grub-core/commands/crc.c +++ b/grub-core/commands/crc.c @@ -38,6 +38,7 @@ grub_cmd_crc (grub_command_t cmd __attribute__ ((unused)), if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required"); + grub_file_filter_disable_compression (); file = grub_file_open (args[0]); if (! file) return 0; diff --git a/grub-core/commands/hashsum.c b/grub-core/commands/hashsum.c index df85015a6..54f487cc7 100644 --- a/grub-core/commands/hashsum.c +++ b/grub-core/commands/hashsum.c @@ -115,11 +115,15 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename, filename = grub_xasprintf ("%s/%s", prefix, p); if (!filename) return grub_errno; + grub_file_filter_disable_compression (); file = grub_file_open (filename); grub_free (filename); } else - file = grub_file_open (p); + { + grub_file_filter_disable_compression (); + file = grub_file_open (p); + } if (!file) { grub_file_close (hashlist); @@ -206,6 +210,7 @@ grub_cmd_hashsum (struct grub_extcmd_context *ctxt, grub_file_t file; grub_err_t err; unsigned j; + grub_file_filter_disable_compression (); file = grub_file_open (args[i]); if (!file) { diff --git a/grub-core/commands/hexdump.c b/grub-core/commands/hexdump.c index 6c518f649..08a94eb64 100644 --- a/grub-core/commands/hexdump.c +++ b/grub-core/commands/hexdump.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -89,7 +88,7 @@ grub_cmd_hexdump (grub_extcmd_context_t ctxt, int argc, char **args) { grub_file_t file; - file = grub_gzfile_open (args[0], 1); + file = grub_file_open (args[0]); if (! file) return 0; diff --git a/grub-core/commands/loadenv.c b/grub-core/commands/loadenv.c index 381810a92..9a1873ba9 100644 --- a/grub-core/commands/loadenv.c +++ b/grub-core/commands/loadenv.c @@ -56,6 +56,7 @@ open_envblk_file (char *filename) grub_strcpy (filename, prefix); filename[len] = '/'; grub_strcpy (filename + len + 1, GRUB_ENVBLK_DEFCFG); + grub_file_filter_disable_compression (); file = grub_file_open (filename); grub_free (filename); return file; @@ -67,6 +68,7 @@ open_envblk_file (char *filename) } } + grub_file_filter_disable_compression (); return grub_file_open (filename); } diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c index b91ef2942..02915bac4 100644 --- a/grub-core/commands/ls.c +++ b/grub-core/commands/ls.c @@ -105,6 +105,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) /* XXX: For ext2fs symlinks are detected as files while they should be reported as directories. */ + grub_file_filter_disable_compression (); file = grub_file_open (pathname); if (! file) { @@ -211,6 +212,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) struct grub_dirhook_info info; grub_errno = 0; + grub_file_filter_disable_compression (); file = grub_file_open (dirname); if (! file) goto fail; diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c index 71267b117..8a646b452 100644 --- a/grub-core/commands/search.c +++ b/grub-core/commands/search.c @@ -54,6 +54,7 @@ FUNC_NAME (const char *key, const char *var, int no_floppy) if (! buf) return 1; + grub_file_filter_disable_compression (); file = grub_file_open (buf); if (file) { diff --git a/grub-core/commands/test.c b/grub-core/commands/test.c index 6995165cf..97b7fe6e4 100644 --- a/grub-core/commands/test.c +++ b/grub-core/commands/test.c @@ -334,6 +334,7 @@ test_parse (char **args, int *argn, int argc) if (grub_strcmp (args[*argn], "-s") == 0) { grub_file_t file; + grub_file_filter_disable_compression (); file = grub_file_open (args[*argn + 1]); update_val (file && (grub_file_size (file) != 0)); if (file) diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c index bc7d42824..2f94ac030 100644 --- a/grub-core/gettext/gettext.c +++ b/grub-core/gettext/gettext.c @@ -26,7 +26,6 @@ #include #include #include -#include #include /* @@ -219,7 +218,7 @@ grub_gettext_translate (const char *orig) return ret; } -/* This is similar to grub_gzfile_open. */ +/* This is similar to grub_file_open. */ static grub_file_t grub_mofile_open (const char *filename) { @@ -229,7 +228,7 @@ grub_mofile_open (const char *filename) /* Using fd_mo and not another variable because it's needed for grub_gettext_get_info. */ - fd_mo = grub_gzfile_open (filename, 1); + fd_mo = grub_file_open (filename); grub_errno = GRUB_ERR_NONE; if (!fd_mo) diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c index 0545e32bd..96b54790a 100644 --- a/grub-core/io/gzio.c +++ b/grub-core/io/gzio.c @@ -40,7 +40,7 @@ #include #include #include -#include +#include /* * Window Size @@ -1113,8 +1113,8 @@ initialize_tables (grub_file_t file) /* Open a new decompressing object on the top of IO. If TRANSPARENT is true, even if IO does not contain data compressed by gzip, return a valid file object. Note that this function won't close IO, even if an error occurs. */ -grub_file_t -grub_gzio_open (grub_file_t io, int transparent) +static grub_file_t +grub_gzio_open (grub_file_t io) { grub_file_t file; grub_gzio_t gzio = 0; @@ -1145,33 +1145,11 @@ grub_gzio_open (grub_file_t io, int transparent) grub_free (file); grub_file_seek (io, 0); - if (grub_errno == GRUB_ERR_BAD_FILE_TYPE && transparent) + if (grub_errno == GRUB_ERR_BAD_FILE_TYPE) { grub_errno = GRUB_ERR_NONE; return io; } - else - return 0; - } - - return file; -} - -/* This is similar to grub_gzio_open, but takes a file name as an argument. */ -grub_file_t -grub_gzfile_open (const char *name, int transparent) -{ - grub_file_t io, file; - - io = grub_file_open (name); - if (! io) - return 0; - - file = grub_gzio_open (io, transparent); - if (! file) - { - grub_file_close (io); - return 0; } return file; @@ -1252,3 +1230,13 @@ static struct grub_fs grub_gzio_fs = .label = 0, .next = 0 }; + +GRUB_MOD_INIT(gzio) +{ + grub_file_filter_register (GRUB_FILE_FILTER_GZIO, grub_gzio_open); +} + +GRUB_MOD_FINI(gzio) +{ + grub_file_filter_unregister (GRUB_FILE_FILTER_GZIO); +} diff --git a/grub-core/kern/elf.c b/grub-core/kern/elf.c index 875a855ea..4be408c31 100644 --- a/grub-core/kern/elf.c +++ b/grub-core/kern/elf.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -95,7 +94,7 @@ grub_elf_open (const char *name) grub_file_t file; grub_elf_t elf; - file = grub_gzfile_open (name, 1); + file = grub_file_open (name); if (! file) return 0; diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c index e17c35f95..c93fbf737 100644 --- a/grub-core/kern/file.c +++ b/grub-core/kern/file.c @@ -24,6 +24,9 @@ #include #include +grub_file_filter_t grub_file_filters_all[GRUB_FILE_FILTER_MAX]; +grub_file_filter_t grub_file_filters_enabled[GRUB_FILE_FILTER_MAX]; + /* Get the device part of the filename NAME. It is enclosed by parentheses. */ char * grub_file_get_device_name (const char *name) @@ -54,14 +57,15 @@ grub_file_get_device_name (const char *name) grub_file_t grub_file_open (const char *name) { - grub_device_t device; - grub_file_t file = 0; + grub_device_t device = 0; + grub_file_t file = 0, last_file = 0; char *device_name; char *file_name; + grub_file_filter_id_t filter; device_name = grub_file_get_device_name (name); if (grub_errno) - return 0; + goto fail; /* Get the file part of NAME. */ file_name = grub_strchr (name, ')'); @@ -94,6 +98,19 @@ grub_file_open (const char *name) if ((file->fs->open) (file, file_name) != GRUB_ERR_NONE) goto fail; + for (filter = 0; file && filter < ARRAY_SIZE (grub_file_filters_enabled); + filter++) + if (grub_file_filters_enabled[filter]) + { + last_file = file; + file = grub_file_filters_enabled[filter] (file); + } + if (!file) + grub_file_close (last_file); + + grub_memcpy (grub_file_filters_enabled, grub_file_filters_all, + sizeof (grub_file_filters_enabled)); + return file; fail: @@ -104,6 +121,9 @@ grub_file_open (const char *name) grub_free (file); + grub_memcpy (grub_file_filters_enabled, grub_file_filters_all, + sizeof (grub_file_filters_enabled)); + return 0; } diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c index 84459b15b..2e92bc42f 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -1326,7 +1325,7 @@ grub_bsd_load (int argc, char *argv[]) goto fail; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (!file) goto fail; @@ -1396,7 +1395,7 @@ grub_cmd_freebsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) if (err) return err; - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (! file) return grub_errno; @@ -1526,7 +1525,7 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) { grub_file_t file; - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (! file) return grub_errno; @@ -1630,7 +1629,7 @@ grub_cmd_freebsd_loadenv (grub_command_t cmd __attribute__ ((unused)), goto fail; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if ((!file) || (!file->size)) goto fail; @@ -1731,7 +1730,7 @@ grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)), return 0; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if ((!file) || (!file->size)) goto fail; @@ -1782,7 +1781,7 @@ grub_netbsd_module_load (char *filename, grub_uint32_t type) void *src; grub_err_t err; - file = grub_gzfile_open (filename, 1); + file = grub_file_open (filename); if ((!file) || (!file->size)) goto fail; @@ -1868,7 +1867,7 @@ grub_cmd_freebsd_module_elf (grub_command_t cmd __attribute__ ((unused)), return 0; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (!file) return grub_errno; if (!file->size) @@ -1904,7 +1903,7 @@ grub_cmd_openbsd_ramdisk (grub_command_t cmd __attribute__ ((unused)), if (!openbsd_ramdisk.max_size) return grub_error (GRUB_ERR_BAD_OS, "your kOpenBSD doesn't support ramdisk"); - file = grub_gzfile_open (args[0], 1); + file = grub_file_open (args[0]); if (! file) return grub_error (GRUB_ERR_FILE_NOT_FOUND, "couldn't load ramdisk"); @@ -1940,6 +1939,9 @@ static grub_command_t cmd_netbsd_module_elf, cmd_openbsd_ramdisk; GRUB_MOD_INIT (bsd) { + /* Net and OpenBSD kernels are often compressed. */ + grub_dl_load ("gzio"); + cmd_freebsd = grub_register_extcmd ("kfreebsd", grub_cmd_freebsd, GRUB_COMMAND_FLAG_BOTH, N_("FILE"), N_("Load kernel of FreeBSD."), diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 9cb26a0c2..cc2d20af3 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -1069,6 +1069,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } + grub_file_filter_disable_compression (); file = grub_file_open (argv[0]); if (! file) goto fail; diff --git a/grub-core/loader/i386/pc/chainloader.c b/grub-core/loader/i386/pc/chainloader.c index 502031d0e..e76f84f08 100644 --- a/grub-core/loader/i386/pc/chainloader.c +++ b/grub-core/loader/i386/pc/chainloader.c @@ -69,6 +69,7 @@ grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags) grub_dl_ref (my_mod); + grub_file_filter_disable_compression (); file = grub_file_open (filename); if (! file) goto fail; diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c index 0719cfb26..2f5dfec70 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c @@ -401,6 +401,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), addr_min = GRUB_LINUX_BZIMAGE_ADDR + grub_linux16_prot_size; + grub_file_filter_disable_compression (); file = grub_file_open (argv[0]); if (!file) goto fail; diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c index d35e9e0aa..a9435eff3 100644 --- a/grub-core/loader/i386/xnu.c +++ b/grub-core/loader/i386/xnu.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -535,7 +534,7 @@ grub_cmd_devprop_load (grub_command_t cmd __attribute__ ((unused)), if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required"); - file = grub_gzfile_open (args[0], 1); + file = grub_file_open (args[0]); if (! file) return grub_error (GRUB_ERR_FILE_NOT_FOUND, "couldn't load device-propertie dump"); diff --git a/grub-core/loader/macho.c b/grub-core/loader/macho.c index 199d6f111..ecf0d8c53 100644 --- a/grub-core/loader/macho.c +++ b/grub-core/loader/macho.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -149,7 +148,7 @@ grub_macho_open (const char *name) grub_file_t file; grub_macho_t macho; - file = grub_gzfile_open (name, 1); + file = grub_file_open (name); if (! file) return 0; diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index 018cfdcc5..48f77dffb 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -344,6 +344,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (initrd_loaded) return grub_error (GRUB_ERR_BAD_ARGUMENT, "only one initrd can be loaded."); + grub_file_filter_disable_compression (); file = grub_file_open (argv[0]); if (! file) return grub_errno; diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c index 1de1def86..8780ec061 100644 --- a/grub-core/loader/multiboot.c +++ b/grub-core/loader/multiboot.c @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -225,7 +224,7 @@ grub_cmd_multiboot (grub_command_t cmd __attribute__ ((unused)), if (argc == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no kernel specified"); - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (! file) return grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file"); @@ -291,9 +290,9 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), "you need to load the multiboot kernel first"); if (nounzip) - file = grub_file_open (argv[0]); - else - file = grub_gzfile_open (argv[0], 1); + grub_file_filter_disable_compression (); + + file = grub_file_open (argv[0]); if (! file) return grub_errno; diff --git a/grub-core/loader/powerpc/ieee1275/linux.c b/grub-core/loader/powerpc/ieee1275/linux.c index 351d050e5..249238d45 100644 --- a/grub-core/loader/powerpc/ieee1275/linux.c +++ b/grub-core/loader/powerpc/ieee1275/linux.c @@ -301,6 +301,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } + grub_file_filter_disable_compression (); file = grub_file_open (argv[0]); if (! file) goto fail; diff --git a/grub-core/loader/sparc64/ieee1275/linux.c b/grub-core/loader/sparc64/ieee1275/linux.c index 948729a5d..177a6976e 100644 --- a/grub-core/loader/sparc64/ieee1275/linux.c +++ b/grub-core/loader/sparc64/ieee1275/linux.c @@ -305,7 +305,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto out; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (!file) goto out; @@ -393,6 +393,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } + grub_file_filter_disable_compression (); file = grub_file_open (argv[0]); if (! file) goto fail; diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c index 92532ed35..ece65611a 100644 --- a/grub-core/loader/xnu.c +++ b/grub-core/loader/xnu.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -661,7 +660,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile) macho = 0; if (infoplistname) - infoplist = grub_gzfile_open (infoplistname, 1); + infoplist = grub_file_open (infoplistname); else infoplist = 0; grub_errno = GRUB_ERR_NONE; @@ -756,7 +755,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)), if (! grub_xnu_heap_size) return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded"); - file = grub_gzfile_open (args[0], 1); + file = grub_file_open (args[0]); if (! file) return grub_error (GRUB_ERR_FILE_NOT_FOUND, "couldn't load driver package"); @@ -869,7 +868,7 @@ grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)), if (! grub_xnu_heap_size) return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded"); - file = grub_gzfile_open (args[0], 1); + file = grub_file_open (args[0]); if (! file) return grub_error (GRUB_ERR_FILE_NOT_FOUND, "couldn't load ramdisk"); @@ -909,7 +908,7 @@ grub_xnu_check_os_bundle_required (char *plistname, char *osbundlereq, if (binname) *binname = 0; - file = grub_gzfile_open (plistname, 1); + file = grub_file_open (plistname); if (! file) { grub_file_close (file); @@ -1166,7 +1165,7 @@ grub_xnu_load_kext_from_dir (char *dirname, char *osbundlerequired, grub_strcpy (binname + grub_strlen (binname), "/"); grub_strcpy (binname + grub_strlen (binname), binsuffix); grub_dprintf ("xnu", "%s:%s\n", plistname, binname); - binfile = grub_gzfile_open (binname, 1); + binfile = grub_file_open (binname); if (! binfile) grub_errno = GRUB_ERR_NONE; @@ -1204,7 +1203,7 @@ grub_cmd_xnu_kext (grub_command_t cmd __attribute__ ((unused)), /* User explicitly specified plist and binary. */ if (grub_strcmp (args[1], "-") != 0) { - binfile = grub_gzfile_open (args[1], 1); + binfile = grub_file_open (args[1]); if (! binfile) { grub_error (GRUB_ERR_BAD_OS, "can't open file"); diff --git a/grub-core/loader/xnu_resume.c b/grub-core/loader/xnu_resume.c index 6aebc1f34..8f0e24483 100644 --- a/grub-core/loader/xnu_resume.c +++ b/grub-core/loader/xnu_resume.c @@ -52,6 +52,7 @@ grub_xnu_resume (char *imagename) grub_addr_t target_image; grub_err_t err; + grub_file_filter_disable_compression (); file = grub_file_open (imagename); if (! file) return 0; diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c index 6a008f577..c7e83fba0 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -474,6 +474,9 @@ static void (*grub_xputs_saved) (const char *str); GRUB_MOD_INIT(normal) { + /* Previously many modules depended on gzio. Be nice to user and load it. */ + grub_dl_load ("gzio"); + grub_context_init (); grub_script_init (); grub_menu_init (); diff --git a/include/grub/file.h b/include/grub/file.h index 05c9907d5..a9f9552da 100644 --- a/include/grub/file.h +++ b/include/grub/file.h @@ -51,6 +51,50 @@ struct grub_file }; typedef struct grub_file *grub_file_t; +/* Filters with lower ID are executed first. */ +typedef enum grub_file_filter_id + { + GRUB_FILE_FILTER_GZIO, + GRUB_FILE_FILTER_MAX, + GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO, + GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_GZIO, + } grub_file_filter_id_t; + +typedef grub_file_t (*grub_file_filter_t) (grub_file_t in); + +extern grub_file_filter_t EXPORT_VAR(grub_file_filters_all)[GRUB_FILE_FILTER_MAX]; +extern grub_file_filter_t EXPORT_VAR(grub_file_filters_enabled)[GRUB_FILE_FILTER_MAX]; + +static inline void +grub_file_filter_register (grub_file_filter_id_t id, grub_file_filter_t filter) +{ + grub_file_filters_all[id] = filter; + grub_file_filters_enabled[id] = filter; +}; + +static inline void +grub_file_filter_unregister (grub_file_filter_id_t id) +{ + grub_file_filters_all[id] = 0; + grub_file_filters_enabled[id] = 0; +}; + +static inline void +grub_file_filter_disable (grub_file_filter_id_t id) +{ + grub_file_filters_enabled[id] = 0; +}; + +static inline void +grub_file_filter_disable_compression (void) +{ + grub_file_filter_id_t id; + + for (id = GRUB_FILE_FILTER_COMPRESSION_FIRST; + id <= GRUB_FILE_FILTER_COMPRESSION_LAST; id++) + grub_file_filters_enabled[id] = 0; +}; + /* Get a device name from NAME. */ char *EXPORT_FUNC(grub_file_get_device_name) (const char *name); diff --git a/include/grub/gzio.h b/include/grub/gzio.h deleted file mode 100644 index cd7f39793..000000000 --- a/include/grub/gzio.h +++ /dev/null @@ -1,28 +0,0 @@ -/* gzio.h - prototypes for gzio */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2005,2007 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_GZIO_H -#define GRUB_GZIO_H 1 - -#include - -grub_file_t grub_gzio_open (grub_file_t io, int transparent); -grub_file_t grub_gzfile_open (const char *name, int transparent); - -#endif /* ! GRUB_GZIO_H */ diff --git a/util/grub-fstest.c b/util/grub-fstest.c index 48fcbc57f..3935ce08b 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -107,6 +107,7 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len)) return; } + grub_file_filter_disable_compression (); file = grub_file_open (pathname); if (!file) { diff --git a/util/grub-probe.c b/util/grub-probe.c index ab3e2713e..62206bf0e 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -245,6 +245,7 @@ probe (const char *path, char *device_name) grub_path = xasprintf ("(%s)%s", drive_name, rel_path); free (rel_path); grub_util_info ("reading %s via GRUB facilities", grub_path); + grub_file_filter_disable_compression (); file = grub_file_open (grub_path); if (! file) grub_util_error ("cannot open %s via GRUB facilities", grub_path); diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index 9788efe4a..642d9d104 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -454,6 +454,7 @@ unable_to_embed: grub_disk_cache_invalidate_all (); + grub_file_filter_disable_compression (); file = grub_file_open (core_path_dev); if (file) { @@ -524,6 +525,7 @@ unable_to_embed: } /* Now read the core image to determine where the sectors are. */ + grub_file_filter_disable_compression (); file = grub_file_open (core_path_dev); if (! file) grub_util_error ("%s", grub_errmsg); diff --git a/util/sparc64/ieee1275/grub-setup.c b/util/sparc64/ieee1275/grub-setup.c index 94734b977..d8481295f 100644 --- a/util/sparc64/ieee1275/grub-setup.c +++ b/util/sparc64/ieee1275/grub-setup.c @@ -228,6 +228,7 @@ setup (const char *prefix, const char *dir, grub_disk_cache_invalidate_all (); + grub_file_filter_disable_compression (); file = grub_file_open (core_path); if (file) { @@ -297,6 +298,7 @@ setup (const char *prefix, const char *dir, } /* Now read the core image to determine where the sectors are. */ + grub_file_filter_disable_compression (); file = grub_file_open (core_path); if (! file) grub_util_error ("%s", grub_errmsg);