diff -urBN orig//experimental/commands/acpi.c transparentio//experimental/commands/acpi.c --- orig//experimental/commands/acpi.c 2010-02-16 01:43:03.711945824 +0100 +++ transparentio//experimental/commands/acpi.c 2010-02-16 18:29:04.037133199 +0100 @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -627,7 +626,7 @@ grub_size_t size; char *buf; - file = grub_gzfile_open (args[i], 1); + file = grub_file_open (args[i]); if (! file) { free_tables (); diff -urBN orig//experimental/commands/cat.c transparentio//experimental/commands/cat.c --- orig//experimental/commands/cat.c 2010-02-16 01:43:03.755946959 +0100 +++ transparentio//experimental/commands/cat.c 2010-02-16 18:29:04.037133199 +0100 @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -39,7 +38,7 @@ 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 0; diff -urBN orig//experimental/commands/cmp.c transparentio//experimental/commands/cmp.c --- orig//experimental/commands/cmp.c 2010-02-16 01:43:03.783945497 +0100 +++ transparentio//experimental/commands/cmp.c 2010-02-16 18:29:04.037133199 +0100 @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -44,8 +43,8 @@ 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 -urBN orig//experimental/commands/hexdump.c transparentio//experimental/commands/hexdump.c --- orig//experimental/commands/hexdump.c 2010-02-16 01:43:03.900945869 +0100 +++ transparentio//experimental/commands/hexdump.c 2010-02-16 18:29:04.037133199 +0100 @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -89,7 +88,7 @@ { grub_file_t file; - file = grub_gzfile_open (args[0], 1); + file = grub_file_open (args[0]); if (! file) return 0; diff -urBN orig//experimental/gettext/gettext.c transparentio//experimental/gettext/gettext.c --- orig//experimental/gettext/gettext.c 2010-02-16 01:43:03.859945957 +0100 +++ transparentio//experimental/gettext/gettext.c 2010-02-16 18:29:04.100132573 +0100 @@ -26,7 +26,6 @@ #include #include #include -#include #include /* @@ -229,7 +228,7 @@ /* 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 -urBN orig//experimental/include/grub/err.h transparentio//experimental/include/grub/err.h --- orig//experimental/include/grub/err.h 2010-02-16 01:43:03.835943739 +0100 +++ transparentio//experimental/include/grub/err.h 2010-02-16 18:29:04.116149419 +0100 @@ -50,7 +50,7 @@ GRUB_ERR_BAD_FONT, GRUB_ERR_NOT_IMPLEMENTED_YET, GRUB_ERR_SYMLINK_LOOP, - GRUB_ERR_BAD_GZIP_DATA, + GRUB_ERR_BAD_IOFILTER_DATA, GRUB_ERR_MENU, GRUB_ERR_TIMEOUT, GRUB_ERR_IO, diff -urBN orig//experimental/include/grub/file.h transparentio//experimental/include/grub/file.h --- orig//experimental/include/grub/file.h 2010-02-16 01:43:03.843945875 +0100 +++ transparentio//experimental/include/grub/file.h 2010-02-16 18:29:04.116149419 +0100 @@ -48,6 +48,20 @@ }; typedef struct grub_file *grub_file_t; +/* The io filter structure. */ +struct grub_io_filter +{ + grub_file_t (*grub_io_open)(grub_file_t file); + struct grub_io_filter *next; +}; +typedef struct grub_io_filter *grub_io_filter_t; + +/* Register io filter. */ +void EXPORT_FUNC(grub_io_register) (grub_io_filter_t filter); + +/* Unregister io filter. */ +void EXPORT_FUNC(grub_io_unregister) (grub_io_filter_t filter); + /* Get a device name from NAME. */ char *EXPORT_FUNC(grub_file_get_device_name) (const char *name); diff -urBN orig//experimental/include/grub/gzio.h transparentio//experimental/include/grub/gzio.h --- orig//experimental/include/grub/gzio.h 2010-02-16 01:43:03.896944801 +0100 +++ transparentio//experimental/include/grub/gzio.h 1970-01-01 01:00:00.000000000 +0100 @@ -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 -urBN orig//experimental/io/gzio.c transparentio//experimental/io/gzio.c --- orig//experimental/io/gzio.c 2010-02-16 01:43:03.896944801 +0100 +++ transparentio//experimental/io/gzio.c 2010-02-16 18:29:04.164135704 +0100 @@ -40,7 +40,9 @@ #include #include #include -#include +#include + +/*grub_file_t grub_gzio_open (grub_file_t io);*/ /* * Window Size @@ -206,7 +208,7 @@ || ((hdr.flags & ORIG_NAME) && eat_field (gzio->file, -1)) || ((hdr.flags & COMMENT) && eat_field (gzio->file, -1))) { - grub_error (GRUB_ERR_BAD_GZIP_DATA, "unsupported gzip format"); + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "unsupported gzip format"); return 0; } @@ -644,7 +646,7 @@ { if (e == 99) { - grub_error (GRUB_ERR_BAD_GZIP_DATA, + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "an unused code found"); return 1; } @@ -683,7 +685,7 @@ { if (e == 99) { - grub_error (GRUB_ERR_BAD_GZIP_DATA, + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "an unused code found"); return 1; } @@ -769,7 +771,7 @@ DUMPBITS (16); NEEDBITS (16); if (gzio->block_len != (int) ((~b) & 0xffff)) - grub_error (GRUB_ERR_BAD_GZIP_DATA, + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "the length of a stored block does not match"); DUMPBITS (16); @@ -803,7 +805,7 @@ if (huft_build (l, 288, 257, cplens, cplext, &gzio->tl, &gzio->bl) != 0) { if (grub_errno == GRUB_ERR_NONE) - grub_error (GRUB_ERR_BAD_GZIP_DATA, + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "failed in building a Huffman code table"); return; } @@ -815,7 +817,7 @@ if (huft_build (l, 30, 0, cpdist, cpdext, &gzio->td, &gzio->bd) > 1) { if (grub_errno == GRUB_ERR_NONE) - grub_error (GRUB_ERR_BAD_GZIP_DATA, + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "failed in building a Huffman code table"); huft_free (gzio->tl); gzio->tl = 0; @@ -862,7 +864,7 @@ DUMPBITS (4); if (nl > 286 || nd > 30) { - grub_error (GRUB_ERR_BAD_GZIP_DATA, "too much data"); + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "too much data"); return; } @@ -880,7 +882,7 @@ gzio->bl = 7; if (huft_build (ll, 19, 19, NULL, NULL, &gzio->tl, &gzio->bl) != 0) { - grub_error (GRUB_ERR_BAD_GZIP_DATA, + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "failed in building a Huffman code table"); return; } @@ -904,7 +906,7 @@ DUMPBITS (2); if ((unsigned) i + j > n) { - grub_error (GRUB_ERR_BAD_GZIP_DATA, "too many codes found"); + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "too many codes found"); return; } while (j--) @@ -917,7 +919,7 @@ DUMPBITS (3); if ((unsigned) i + j > n) { - grub_error (GRUB_ERR_BAD_GZIP_DATA, "too many codes found"); + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "too many codes found"); return; } while (j--) @@ -932,7 +934,7 @@ DUMPBITS (7); if ((unsigned) i + j > n) { - grub_error (GRUB_ERR_BAD_GZIP_DATA, "too many codes found"); + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "too many codes found"); return; } while (j--) @@ -954,7 +956,7 @@ gzio->bl = lbits; if (huft_build (ll, nl, 257, cplens, cplext, &gzio->tl, &gzio->bl) != 0) { - grub_error (GRUB_ERR_BAD_GZIP_DATA, + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "failed in building a Huffman code table"); return; } @@ -963,7 +965,7 @@ { huft_free (gzio->tl); gzio->tl = 0; - grub_error (GRUB_ERR_BAD_GZIP_DATA, + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "failed in building a Huffman code table"); return; } @@ -1039,7 +1041,7 @@ } if (gzio->block_type > INFLATE_DYNAMIC) - grub_error (GRUB_ERR_BAD_GZIP_DATA, + grub_error (GRUB_ERR_BAD_IOFILTER_DATA, "unknown block type %d", gzio->block_type); if (grub_errno != GRUB_ERR_NONE) @@ -1111,8 +1113,8 @@ /* 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; @@ -1142,32 +1144,12 @@ grub_free (file); grub_file_seek (io, 0); - if (grub_errno == GRUB_ERR_BAD_FILE_TYPE && transparent) - { - 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; + /* Don't report bad file type as error. */ + if (grub_errno == GRUB_ERR_BAD_FILE_TYPE) + { + grub_errno = GRUB_ERR_NONE; + } - file = grub_gzio_open (io, transparent); - if (! file) - { - grub_file_close (io); return 0; } @@ -1237,8 +1219,6 @@ return grub_errno; } - - static struct grub_fs grub_gzio_fs = { .name = "gzio", @@ -1249,3 +1229,19 @@ .label = 0, .next = 0 }; + +static struct grub_io_filter grub_gzio_filter = { + .grub_io_open = grub_gzio_open, + .next = 0 +}; + + +GRUB_MOD_INIT (gzio) +{ + grub_io_register (&grub_gzio_filter); +} + +GRUB_MOD_FINI (gzio) +{ + grub_io_unregister (&grub_gzio_filter); +} diff -urBN orig//experimental/kern/elf.c transparentio//experimental/kern/elf.c --- orig//experimental/kern/elf.c 2010-02-16 01:43:03.831946861 +0100 +++ transparentio//experimental/kern/elf.c 2010-02-16 18:29:04.164135704 +0100 @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -95,7 +94,7 @@ grub_file_t file; grub_elf_t elf; - file = grub_gzfile_open (name, 1); + file = grub_file_open (name); if (! file) return 0; diff -urBN orig//experimental/kern/file.c transparentio//experimental/kern/file.c --- orig//experimental/kern/file.c 2010-02-16 01:43:03.843945875 +0100 +++ transparentio//experimental/kern/file.c 2010-02-16 18:29:04.164135704 +0100 @@ -24,6 +24,27 @@ #include #include +/* Registered filters list. */ +static grub_io_filter_t grub_io_filter_list = NULL; + +void grub_io_register(grub_io_filter_t filter) +{ + filter->next = grub_io_filter_list; + grub_io_filter_list = filter; +} + +void grub_io_unregister(grub_io_filter_t filter) +{ + grub_io_filter_t *p, q; + + for (p = &grub_io_filter_list, q = *p; q; p = &(q->next), q = q->next) + if (q == filter) + { + *p = q->next; + break; + } +} + /* Get the device part of the filename NAME. It is enclosed by parentheses. */ char * grub_file_get_device_name (const char *name) @@ -94,6 +115,20 @@ if ((file->fs->open) (file, file_name) != GRUB_ERR_NONE) goto fail; + /* Check available filters. */ + grub_file_t ffile; + grub_io_filter_t filter = grub_io_filter_list; + while (filter) + { + ffile = filter->grub_io_open(file); + if (ffile) + { + file = ffile; + break; + } + filter = filter->next; + } + return file; fail: diff -urBN orig//experimental/loader/i386/bsd.c transparentio//experimental/loader/i386/bsd.c --- orig//experimental/loader/i386/bsd.c 2010-02-16 01:43:03.747944543 +0100 +++ transparentio//experimental/loader/i386/bsd.c 2010-02-16 18:29:04.192133406 +0100 @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -904,7 +903,7 @@ goto fail; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (!file) goto fail; @@ -970,7 +969,7 @@ if (err) return err; - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (! file) return grub_errno; @@ -1086,7 +1085,7 @@ goto fail; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if ((!file) || (!file->size)) goto fail; @@ -1191,7 +1190,7 @@ return 0; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if ((!file) || (!file->size)) goto fail; @@ -1257,7 +1256,7 @@ return 0; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (!file) return grub_errno; if (!file->size) diff -urBN orig//experimental/loader/i386/multiboot.c transparentio//experimental/loader/i386/multiboot.c --- orig//experimental/loader/i386/multiboot.c 2010-02-16 01:43:03.996945519 +0100 +++ transparentio//experimental/loader/i386/multiboot.c 2010-02-16 18:29:04.192133406 +0100 @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -154,7 +153,7 @@ goto fail; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (! file) { grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file"); @@ -305,7 +304,7 @@ goto fail; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (! file) goto fail; diff -urBN orig//experimental/loader/i386/xnu.c transparentio//experimental/loader/i386/xnu.c --- orig//experimental/loader/i386/xnu.c 2010-02-16 01:43:04.123948020 +0100 +++ transparentio//experimental/loader/i386/xnu.c 2010-02-16 18:29:04.192133406 +0100 @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -536,7 +535,7 @@ 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 -urBN orig//experimental/loader/macho.c transparentio//experimental/loader/macho.c --- orig//experimental/loader/macho.c 2010-02-16 01:43:03.980946274 +0100 +++ transparentio//experimental/loader/macho.c 2010-02-16 18:29:04.192133406 +0100 @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -149,7 +148,7 @@ grub_file_t file; grub_macho_t macho; - file = grub_gzfile_open (name, 1); + file = grub_file_open (name); if (! file) return 0; diff -urBN orig//experimental/loader/multiboot_loader.c transparentio//experimental/loader/multiboot_loader.c --- orig//experimental/loader/multiboot_loader.c 2010-02-16 01:43:04.000945470 +0100 +++ transparentio//experimental/loader/multiboot_loader.c 2010-02-16 18:29:04.192133406 +0100 @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -74,7 +73,7 @@ goto fail; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (! file) { grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file"); diff -urBN orig//experimental/loader/sparc64/ieee1275/linux.c transparentio//experimental/loader/sparc64/ieee1275/linux.c --- orig//experimental/loader/sparc64/ieee1275/linux.c 2010-02-16 01:43:03.944945603 +0100 +++ transparentio//experimental/loader/sparc64/ieee1275/linux.c 2010-02-16 18:29:04.192133406 +0100 @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -306,7 +305,7 @@ goto out; } - file = grub_gzfile_open (argv[0], 1); + file = grub_file_open (argv[0]); if (!file) goto out; diff -urBN orig//experimental/loader/xnu.c transparentio//experimental/loader/xnu.c --- orig//experimental/loader/xnu.c 2010-02-16 01:43:04.123948020 +0100 +++ transparentio//experimental/loader/xnu.c 2010-02-16 18:29:04.192133406 +0100 @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -667,7 +666,7 @@ macho = 0; if (infoplistname) - infoplist = grub_gzfile_open (infoplistname, 1); + infoplist = grub_file_open (infoplistname); else infoplist = 0; grub_errno = GRUB_ERR_NONE; @@ -761,7 +760,7 @@ 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"); @@ -873,7 +872,7 @@ 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"); @@ -913,7 +912,7 @@ if (binname) *binname = 0; - file = grub_gzfile_open (plistname, 1); + file = grub_file_open (plistname); if (! file) { grub_file_close (file); @@ -1170,7 +1169,7 @@ 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; @@ -1208,7 +1207,7 @@ /* 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");