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-05 Vladimir Serbinenko <phcoder@gmail.com>
+
+ * 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 <bvk.groups@gmail.com>
Filename expansion support for wildcards in GRUB script.
#include <grub/disk.h>
#include <grub/term.h>
#include <grub/misc.h>
-#include <grub/gzio.h>
#include <grub/acpi.h>
#include <grub/mm.h>
#include <grub/machine/memory.h>
grub_size_t size;
char *buf;
- file = grub_gzfile_open (args[i], 1);
+ file = grub_file_open (args[i]);
if (! file)
{
free_tables ();
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;
#include <grub/disk.h>
#include <grub/term.h>
#include <grub/misc.h>
-#include <grub/gzio.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
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;
#include <grub/misc.h>
#include <grub/file.h>
#include <grub/mm.h>
-#include <grub/gzio.h>
#include <grub/command.h>
#include <grub/i18n.h>
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;
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;
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);
grub_file_t file;
grub_err_t err;
unsigned j;
+ grub_file_filter_disable_compression ();
file = grub_file_open (args[i]);
if (!file)
{
#include <grub/file.h>
#include <grub/disk.h>
#include <grub/misc.h>
-#include <grub/gzio.h>
#include <grub/lib/hexdump.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
{
grub_file_t file;
- file = grub_gzfile_open (args[0], 1);
+ file = grub_file_open (args[0]);
if (! file)
return 0;
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;
}
}
+ grub_file_filter_disable_compression ();
return grub_file_open (filename);
}
/* 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)
{
struct grub_dirhook_info info;
grub_errno = 0;
+ grub_file_filter_disable_compression ();
file = grub_file_open (dirname);
if (! file)
goto fail;
if (! buf)
return 1;
+ grub_file_filter_disable_compression ();
file = grub_file_open (buf);
if (file)
{
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)
#include <grub/normal.h>
#include <grub/file.h>
#include <grub/kernel.h>
-#include <grub/gzio.h>
#include <grub/i18n.h>
/*
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)
{
/* 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)
#include <grub/misc.h>
#include <grub/fs.h>
#include <grub/file.h>
-#include <grub/gzio.h>
+#include <grub/dl.h>
/*
* Window Size
/* 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;
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;
.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);
+}
#include <grub/elf.h>
#include <grub/elfload.h>
#include <grub/file.h>
-#include <grub/gzio.h>
#include <grub/misc.h>
#include <grub/mm.h>
grub_file_t file;
grub_elf_t elf;
- file = grub_gzfile_open (name, 1);
+ file = grub_file_open (name);
if (! file)
return 0;
#include <grub/fs.h>
#include <grub/device.h>
+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)
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, ')');
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:
grub_free (file);
+ grub_memcpy (grub_file_filters_enabled, grub_file_filters_all,
+ sizeof (grub_file_filters_enabled));
+
return 0;
}
#include <grub/elfload.h>
#include <grub/env.h>
#include <grub/misc.h>
-#include <grub/gzio.h>
#include <grub/aout.h>
#include <grub/command.h>
#include <grub/extcmd.h>
goto fail;
}
- file = grub_gzfile_open (argv[0], 1);
+ file = grub_file_open (argv[0]);
if (!file)
goto fail;
if (err)
return err;
- file = grub_gzfile_open (argv[0], 1);
+ file = grub_file_open (argv[0]);
if (! file)
return grub_errno;
{
grub_file_t file;
- file = grub_gzfile_open (argv[0], 1);
+ file = grub_file_open (argv[0]);
if (! file)
return grub_errno;
goto fail;
}
- file = grub_gzfile_open (argv[0], 1);
+ file = grub_file_open (argv[0]);
if ((!file) || (!file->size))
goto fail;
return 0;
}
- file = grub_gzfile_open (argv[0], 1);
+ file = grub_file_open (argv[0]);
if ((!file) || (!file->size))
goto fail;
void *src;
grub_err_t err;
- file = grub_gzfile_open (filename, 1);
+ file = grub_file_open (filename);
if ((!file) || (!file->size))
goto fail;
return 0;
}
- file = grub_gzfile_open (argv[0], 1);
+ file = grub_file_open (argv[0]);
if (!file)
return grub_errno;
if (!file->size)
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");
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."),
goto fail;
}
+ grub_file_filter_disable_compression ();
file = grub_file_open (argv[0]);
if (! file)
goto fail;
grub_dl_ref (my_mod);
+ grub_file_filter_disable_compression ();
file = grub_file_open (filename);
if (! file)
goto fail;
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;
#include <grub/charset.h>
#include <grub/term.h>
#include <grub/command.h>
-#include <grub/gzio.h>
#include <grub/i18n.h>
#include <grub/bitmap_scale.h>
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");
#include <grub/cpu/macho.h>
#include <grub/machoload.h>
#include <grub/file.h>
-#include <grub/gzio.h>
#include <grub/misc.h>
#include <grub/mm.h>
grub_file_t file;
grub_macho_t macho;
- file = grub_gzfile_open (name, 1);
+ file = grub_file_open (name);
if (! file)
return 0;
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;
#include <grub/dl.h>
#include <grub/mm.h>
#include <grub/misc.h>
-#include <grub/gzio.h>
#include <grub/env.h>
#include <grub/cpu/relocator.h>
#include <grub/video.h>
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");
"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;
goto fail;
}
+ grub_file_filter_disable_compression ();
file = grub_file_open (argv[0]);
if (! file)
goto fail;
goto out;
}
- file = grub_gzfile_open (argv[0], 1);
+ file = grub_file_open (argv[0]);
if (!file)
goto out;
goto fail;
}
+ grub_file_filter_disable_compression ();
file = grub_file_open (argv[0]);
if (! file)
goto fail;
#include <grub/machoload.h>
#include <grub/macho.h>
#include <grub/cpu/macho.h>
-#include <grub/gzio.h>
#include <grub/command.h>
#include <grub/misc.h>
#include <grub/extcmd.h>
macho = 0;
if (infoplistname)
- infoplist = grub_gzfile_open (infoplistname, 1);
+ infoplist = grub_file_open (infoplistname);
else
infoplist = 0;
grub_errno = GRUB_ERR_NONE;
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");
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");
if (binname)
*binname = 0;
- file = grub_gzfile_open (plistname, 1);
+ file = grub_file_open (plistname);
if (! file)
{
grub_file_close (file);
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;
/* 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");
grub_addr_t target_image;
grub_err_t err;
+ grub_file_filter_disable_compression ();
file = grub_file_open (imagename);
if (! file)
return 0;
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 ();
};
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);
+++ /dev/null
-/* 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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GRUB_GZIO_H
-#define GRUB_GZIO_H 1
-
-#include <grub/file.h>
-
-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 */
return;
}
+ grub_file_filter_disable_compression ();
file = grub_file_open (pathname);
if (!file)
{
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);
grub_disk_cache_invalidate_all ();
+ grub_file_filter_disable_compression ();
file = grub_file_open (core_path_dev);
if (file)
{
}
/* 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);
grub_disk_cache_invalidate_all ();
+ grub_file_filter_disable_compression ();
file = grub_file_open (core_path);
if (file)
{
}
/* 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);