]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
File type for fine-grained signature-verification controlling
authorVladimir Serbinenko <phcoder@gmail.com>
Wed, 20 Nov 2013 01:28:29 +0000 (02:28 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Tue, 9 May 2017 14:12:18 +0000 (16:12 +0200)
71 files changed:
grub-core/commands/acpi.c
grub-core/commands/blocklist.c
grub-core/commands/cat.c
grub-core/commands/cmp.c
grub-core/commands/efi/loadbios.c
grub-core/commands/file.c
grub-core/commands/hashsum.c
grub-core/commands/hexdump.c
grub-core/commands/i386/nthibr.c [new file with mode: 0644]
grub-core/commands/i386/pc/play.c
grub-core/commands/keylayouts.c
grub-core/commands/legacycfg.c
grub-core/commands/loadenv.c
grub-core/commands/ls.c
grub-core/commands/minicmd.c
grub-core/commands/nativedisk.c
grub-core/commands/parttool.c
grub-core/commands/search.c
grub-core/commands/test.c
grub-core/commands/testload.c
grub-core/commands/testspeed.c
grub-core/commands/verify.c
grub-core/disk/loopback.c
grub-core/efiemu/main.c
grub-core/font/font.c
grub-core/fs/zfs/zfscrypt.c
grub-core/gettext/gettext.c
grub-core/gfxmenu/theme_loader.c
grub-core/io/bufio.c
grub-core/io/gzio.c
grub-core/io/lzopio.c
grub-core/io/offset.c
grub-core/io/xzio.c
grub-core/kern/dl.c
grub-core/kern/elf.c
grub-core/kern/file.c
grub-core/lib/syslinux_parse.c
grub-core/loader/efi/chainloader.c
grub-core/loader/i386/bsd.c
grub-core/loader/i386/coreboot/chainloader.c
grub-core/loader/i386/linux.c
grub-core/loader/i386/pc/chainloader.c
grub-core/loader/i386/pc/freedos.c
grub-core/loader/i386/pc/linux.c
grub-core/loader/i386/pc/ntldr.c
grub-core/loader/i386/pc/plan9.c
grub-core/loader/i386/pc/pxechainloader.c
grub-core/loader/i386/pc/truecrypt.c
grub-core/loader/i386/xen.c
grub-core/loader/i386/xen_file.c
grub-core/loader/i386/xnu.c
grub-core/loader/linux.c
grub-core/loader/macho.c
grub-core/loader/mips/linux.c
grub-core/loader/multiboot.c
grub-core/loader/xnu.c
grub-core/loader/xnu_resume.c
grub-core/normal/autofs.c
grub-core/normal/crypto.c
grub-core/normal/dyncmd.c
grub-core/normal/main.c
grub-core/normal/term.c
grub-core/video/readers/jpeg.c
grub-core/video/readers/png.c
grub-core/video/readers/tga.c
include/grub/bufio.h
include/grub/elfload.h
include/grub/file.h
include/grub/machoload.h
util/grub-fstest.c
util/grub-mount.c

index 9f02f22019a465a25bba2ebe51228c14612b0e85..5a1499aa0e30ef7b5a683fea603bb2cd3bf30b49 100644 (file)
@@ -635,7 +635,7 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
       grub_size_t size;
       char *buf;
 
-      file = grub_file_open (args[i]);
+      file = grub_file_open (args[i], GRUB_FILE_TYPE_ACPI_TABLE);
       if (! file)
        {
          free_tables ();
index d1a47b504bf25258a32beeecdab237fd6696e3d5..944449b77d4bdb6fc26b7906853e47e142ffb2d8 100644 (file)
@@ -121,8 +121,8 @@ grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)),
   if (argc < 1)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
 
-  grub_file_filter_disable_compression ();
-  file = grub_file_open (args[0]);
+  file = grub_file_open (args[0], GRUB_FILE_TYPE_PRINT_BLOCKLIST
+                        | GRUB_FILE_TYPE_NO_DECOMPRESS);
   if (! file)
     return grub_errno;
 
index 88d90443602eef4131b682e12215b52b55720bdf..ba5f0061aa578be4c9ec4f4cf63d474d1f1b06ee 100644 (file)
@@ -56,7 +56,7 @@ grub_cmd_cat (grub_extcmd_context_t ctxt, int argc, char **args)
   if (argc != 1)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
 
-  file = grub_file_open (args[0]);
+  file = grub_file_open (args[0], GRUB_FILE_TYPE_CAT);
   if (! file)
     return grub_errno;
 
index cc23ee67ea372c6c0fc4014ce9cfaf56e3924545..e9c3b25d34cb6a472292611903d91bd9281e2507 100644 (file)
@@ -45,8 +45,8 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
   grub_printf_ (N_("Compare file `%s' with `%s':\n"), args[0],
                args[1]);
 
-  file1 = grub_file_open (args[0]);
-  file2 = grub_file_open (args[1]);
+  file1 = grub_file_open (args[0], GRUB_FILE_TYPE_CMP);
+  file2 = grub_file_open (args[1], GRUB_FILE_TYPE_CMP);
   if (! file1 || ! file2)
     goto cleanup;
 
index 132cadbc7643734620a576988986ee2156e69fb9..d41d521a4aebd21465fff9303d4556f763d53aa4 100644 (file)
@@ -169,7 +169,7 @@ grub_cmd_loadbios (grub_command_t cmd __attribute__ ((unused)),
 
   if (argc > 1)
     {
-      file = grub_file_open (argv[1]);
+      file = grub_file_open (argv[1], GRUB_FILE_TYPE_VBE_DUMP);
       if (! file)
        return grub_errno;
 
@@ -183,7 +183,7 @@ grub_cmd_loadbios (grub_command_t cmd __attribute__ ((unused)),
        return grub_errno;
     }
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_VBE_DUMP);
   if (! file)
     return grub_errno;
 
index 12fba99e06a23cb72af67fc4bfb758d97bfa0e67..9cacebf785dabcaaaa09707a77c0aa75cd1289e1 100644 (file)
@@ -163,7 +163,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
   if (type == -1)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, "no type specified");
 
-  file = grub_file_open (args[0]);
+  file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL);
   if (!file)
     return grub_errno;
   switch (type)
@@ -546,7 +546,8 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
     case IS_XNU64:
     case IS_XNU32:
       {
-       macho = grub_macho_open (args[0], (type == IS_XNU64));
+       macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL,
+                                (type == IS_XNU64));
        if (!macho)
          break;
        /* FIXME: more checks?  */
index d18687351a57ef9b95097f24d51dc0c68b79f52a..0f18f2cc16f2ed545e82087bd142dc0fda32cadc 100644 (file)
@@ -113,7 +113,7 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
   if (hash->mdlen > GRUB_CRYPTO_MAX_MDLEN)
     return grub_error (GRUB_ERR_BUG, "mdlen is too long");
 
-  hashlist = grub_file_open (hashfilename);
+  hashlist = grub_file_open (hashfilename, GRUB_FILE_TYPE_HASHLIST);
   if (!hashlist)
     return grub_errno;
   
@@ -141,17 +141,15 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
          filename = grub_xasprintf ("%s/%s", prefix, p);
          if (!filename)
            return grub_errno;
-         if (!uncompress)
-           grub_file_filter_disable_compression ();
-         file = grub_file_open (filename);
+         file = grub_file_open (filename, GRUB_FILE_TYPE_TO_HASH
+                                | (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
+                                   : 0));
          grub_free (filename);
        }
       else
-       {
-         if (!uncompress)
-           grub_file_filter_disable_compression ();
-         file = grub_file_open (p);
-       }
+       file = grub_file_open (p, GRUB_FILE_TYPE_TO_HASH
+                              | (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
+                                 : 0));
       if (!file)
        {
          grub_file_close (hashlist);
@@ -242,9 +240,9 @@ grub_cmd_hashsum (struct grub_extcmd_context *ctxt,
       grub_file_t file;
       grub_err_t err;
       unsigned j;
-      if (!uncompress)
-       grub_file_filter_disable_compression ();
-      file = grub_file_open (args[i]);
+      file = grub_file_open (args[i], GRUB_FILE_TYPE_TO_HASH
+                            | (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
+                               : 0));
       if (!file)
        {
          if (!keep)
index 4c884b3a19a47fc7470eafb4489b1e6fde1224b9..eaa12465bb381c5de0475175289e3e6c0e0bea7e 100644 (file)
@@ -90,7 +90,7 @@ grub_cmd_hexdump (grub_extcmd_context_t ctxt, int argc, char **args)
     {
       grub_file_t file;
 
-      file = grub_file_open (args[0]);
+      file = grub_file_open (args[0], GRUB_FILE_TYPE_HEXCAT);
       if (! file)
        return 0;
 
diff --git a/grub-core/commands/i386/nthibr.c b/grub-core/commands/i386/nthibr.c
new file mode 100644 (file)
index 0000000..b33f41e
--- /dev/null
@@ -0,0 +1,79 @@
+/* nthibr.c - tests whether an MS Windows system partition is hibernated */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2013  Peter Lustig
+ *  Copyright (C) 2013  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/>.
+ */
+
+#include <grub/types.h>
+#include <grub/mm.h>
+#include <grub/file.h>
+#include <grub/misc.h>
+#include <grub/dl.h>
+#include <grub/command.h>
+#include <grub/err.h>
+#include <grub/i18n.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static grub_err_t
+grub_cmd_nthibr (grub_command_t cmd __attribute__ ((unused)),
+                 int argc, char **args)
+{
+  grub_uint8_t hibr_file_magic[4];
+  grub_file_t hibr_file = 0;
+
+  if (argc != 1)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
+
+  hibr_file = grub_file_open (args[0], GRUB_FILE_TYPE_FILE_ID);
+  if (!hibr_file)
+    return grub_errno;
+
+  /* Try to read magic number of 'hiberfil.sys' */
+  if (grub_file_read (hibr_file, hibr_file_magic,
+                     sizeof (hibr_file_magic))
+      != (grub_ssize_t) sizeof (hibr_file_magic))
+    {
+      if (!grub_errno)
+       grub_error (GRUB_ERR_TEST_FAILURE, "false");
+      goto exit;
+    }
+
+  if (!(grub_memcmp ("hibr", hibr_file_magic, sizeof (hibr_file_magic)) == 0
+       || grub_memcmp ("HIBR", hibr_file_magic, sizeof (hibr_file_magic)) == 0))
+    grub_error (GRUB_ERR_TEST_FAILURE, "false");
+
+ exit:
+  grub_file_close (hibr_file);
+
+  return grub_errno;
+}
+
+static grub_command_t cmd;
+
+GRUB_MOD_INIT (check_nt_hiberfil)
+{
+  cmd = grub_register_command ("check_nt_hiberfil", grub_cmd_nthibr,
+                               N_("FILE"),
+                               N_("Test whether a hiberfil.sys is "
+                                  "in hibernated state."));
+}
+
+GRUB_MOD_FINI (check_nt_hiberfil)
+{
+  grub_unregister_command (cmd);
+}
index 7712e2a36a17d3b052585de7a165d86e31b65a35..c8181310515b5bdc9ea822657d408956c1ce1e1f 100644 (file)
@@ -93,7 +93,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
       grub_uint32_t tempo;
       grub_file_t file;
 
-      file = grub_file_open (args[0]);
+      file = grub_file_open (args[0], GRUB_FILE_TYPE_AUDIO);
 
       if (! file)
         return grub_errno;
index f4b7730208ab8ffafb1b0283294a140248839d7a..e36d3ac6727f8bd564f88edd83323303640d73b3 100644 (file)
@@ -220,7 +220,7 @@ grub_cmd_keymap (struct grub_command *cmd __attribute__ ((unused)),
   else
     filename = argv[0];
 
-  file = grub_file_open (filename);
+  file = grub_file_open (filename, GRUB_FILE_TYPE_KEYBOARD_LAYOUT);
   if (! file)
     goto fail;
 
index b32f3c74cb1e0614a61367a3e20ce56836758e90..db7a8f0027342a7c62383cef28534257c95837d7 100644 (file)
@@ -55,7 +55,7 @@ legacy_file (const char *filename)
   if (!suffix)
     return grub_errno;
 
-  file = grub_file_open (filename);
+  file = grub_file_open (filename, GRUB_FILE_TYPE_CONFIG);
   if (! file)
     {
       grub_free (suffix);
index acd93d123ed361e5bd7ae449f5166d5659104823..ada72df4081b753a5104571b4f8050bb8c600f68 100644 (file)
@@ -44,7 +44,8 @@ static const struct grub_arg_option options[] =
    PUBKEY filter (that insists upon properly signed files) as well.  PUBKEY
    filter is restored before the function returns. */
 static grub_file_t
-open_envblk_file (char *filename, int untrusted)
+open_envblk_file (char *filename,
+                 enum grub_file_type type)
 {
   grub_file_t file;
   char *buf = 0;
@@ -72,13 +73,7 @@ open_envblk_file (char *filename, int untrusted)
       grub_strcpy (filename + len + 1, GRUB_ENVBLK_DEFCFG);
     }
 
-  /* The filters that are disabled will be re-enabled by the call to
-     grub_file_open() after this particular file is opened. */
-  grub_file_filter_disable_compression ();
-  if (untrusted)
-    grub_file_filter_disable_pubkey ();
-
-  file = grub_file_open (filename);
+  file = grub_file_open (filename, type);
 
   grub_free (buf);
   return file;
@@ -171,7 +166,10 @@ grub_cmd_load_env (grub_extcmd_context_t ctxt, int argc, char **args)
   whitelist.list = args;
 
   /* state[0] is the -f flag; state[1] is the --skip-sig flag */
-  file = open_envblk_file ((state[0].set) ? state[0].arg : 0, state[1].set);
+  file = open_envblk_file ((state[0].set) ? state[0].arg : 0,
+                          GRUB_FILE_TYPE_LOADENV
+                          | (state[1].set
+                             ? GRUB_FILE_TYPE_SKIP_SIGNATURE : 0));
   if (! file)
     return grub_errno;
 
@@ -206,7 +204,10 @@ grub_cmd_list_env (grub_extcmd_context_t ctxt,
   grub_file_t file;
   grub_envblk_t envblk;
 
-  file = open_envblk_file ((state[0].set) ? state[0].arg : 0, 0);
+  file = open_envblk_file ((state[0].set) ? state[0].arg : 0,
+                          GRUB_FILE_TYPE_LOADENV
+                          | (state[1].set
+                             ? GRUB_FILE_TYPE_SKIP_SIGNATURE : 0));
   if (! file)
     return grub_errno;
 
@@ -390,7 +391,8 @@ grub_cmd_save_env (grub_extcmd_context_t ctxt, int argc, char **args)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, "no variable is specified");
 
   file = open_envblk_file ((state[0].set) ? state[0].arg : 0,
-                           1 /* allow untrusted */);
+                          GRUB_FILE_TYPE_SAVEENV
+                          | GRUB_FILE_TYPE_SKIP_SIGNATURE);
   if (! file)
     return grub_errno;
 
index 0eaf836527944ba69d499050ad080f919d3e57ef..f0d3c1caec4431832c4f21ad14ae936d146f57e1 100644 (file)
@@ -129,8 +129,8 @@ print_files_long (const char *filename, const struct grub_dirhook_info *info,
 
       /* 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);
+      file = grub_file_open (pathname, GRUB_FILE_TYPE_GET_SIZE
+                            | GRUB_FILE_TYPE_NO_DECOMPRESS);
       if (! file)
        {
          grub_errno = 0;
@@ -225,8 +225,8 @@ 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);
+         file = grub_file_open (dirname, GRUB_FILE_TYPE_GET_SIZE
+                                | GRUB_FILE_TYPE_NO_DECOMPRESS);
          if (! file)
            goto fail;
 
index a3a11824172869043cf1a36238d49ae3fa491d15..fc20c65631d7139ce7f065c6354109c8327c3ce6 100644 (file)
@@ -43,7 +43,7 @@ grub_mini_cmd_cat (struct grub_command *cmd __attribute__ ((unused)),
   if (argc < 1)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_CAT);
   if (! file)
     return grub_errno;
 
index 2f56a870e68b7e4463d2d7cd48b6659de2d9b9f6..c278f377b7fe81e0660492552257dcc92440f35e 100644 (file)
@@ -242,7 +242,8 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
       if (! filename)
        goto fail;
 
-      file = grub_file_open (filename);
+      file = grub_file_open (filename,
+                            GRUB_FILE_TYPE_GRUB_MODULE);
       grub_free (filename);
       if (! file)
        goto fail;
index 693e2cb42fc2ec0aea57b5a986ec72b627639469..22b46b187415d0b3d1a42580b0aa782dba8b9bf5 100644 (file)
@@ -193,7 +193,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
          {
            grub_file_t file;
 
-           file = grub_file_open (filename);
+           file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
            if (file)
              {
                char *buf = 0;
index 7dd32e445c9bc37b2044c5d701e0966898ce5e58..ddda6e7c590667938645d1159ea5401915b0ccbd 100644 (file)
@@ -81,8 +81,8 @@ iterate_device (const char *name, void *data)
       if (! buf)
        return 1;
 
-      grub_file_filter_disable_compression ();
-      file = grub_file_open (buf);
+      file = grub_file_open (buf, GRUB_FILE_TYPE_FS_SEARCH
+                            | GRUB_FILE_TYPE_NO_DECOMPRESS);
       if (file)
        {
          found = 1;
index 5f06642f6c69c11c4c3bd540a6b230334c69a3ba..13c6ed9534af9450a75d4430a3142cccf8112ebe 100644 (file)
@@ -355,8 +355,8 @@ 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]);
+             file = grub_file_open (args[*argn + 1], GRUB_FILE_TYPE_GET_SIZE
+                                    | GRUB_FILE_TYPE_NO_DECOMPRESS);
              update_val (file && (grub_file_size (file) != 0), &ctx);
              if (file)
                grub_file_close (file);
index cfab6763dc3f63faeefb99d71b9b53e35a81ddbb..ff01a0516dd71fb9a0ea87436bc3de4caa654db0 100644 (file)
@@ -57,7 +57,7 @@ grub_cmd_testload (struct grub_command *cmd __attribute__ ((unused)),
   if (argc < 1)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_TESTLOAD);
   if (! file)
     return grub_errno;
 
index 042645f8d26424695c525a1607fc3c61b28e2b5d..c13a9b8d8d2235e7c7b37e76f025556f19085093 100644 (file)
@@ -61,7 +61,7 @@ grub_cmd_testspeed (grub_extcmd_context_t ctxt, int argc, char **args)
   if (buffer == NULL)
     return grub_errno;
 
-  file = grub_file_open (args[0]);
+  file = grub_file_open (args[0], GRUB_FILE_TYPE_TESTLOAD);
   if (file == NULL)
     goto quit;
 
index 67cb1c785095e104b874e38c0adfbad48f95ad64..3616318676f23c80f74b38abfe028fcea08c3aee 100644 (file)
@@ -680,10 +680,12 @@ grub_cmd_trust (grub_extcmd_context_t ctxt,
   if (argc < 1)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
 
-  grub_file_filter_disable_compression ();
-  if (ctxt->state[OPTION_SKIP_SIG].set)
-    grub_file_filter_disable_pubkey ();
-  pkf = grub_file_open (args[0]);
+  pkf = grub_file_open (args[0],
+                       GRUB_FILE_TYPE_PUBLIC_KEY_TRUST
+                       | GRUB_FILE_TYPE_NO_DECOMPRESS
+                       | (ctxt->state[OPTION_SKIP_SIG].set
+                          ? GRUB_FILE_TYPE_SKIP_SIGNATURE
+                          : 0));
   if (!pkf)
     return grub_errno;
   pk = grub_load_public_key (pkf);
@@ -771,10 +773,12 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt,
   if (argc > 2)
     {
       grub_file_t pkf;
-      grub_file_filter_disable_compression ();
-      if (ctxt->state[OPTION_SKIP_SIG].set)
-       grub_file_filter_disable_pubkey ();
-      pkf = grub_file_open (args[2]);
+      pkf = grub_file_open (args[2],
+                           GRUB_FILE_TYPE_PUBLIC_KEY
+                           | GRUB_FILE_TYPE_NO_DECOMPRESS
+                           | (ctxt->state[OPTION_SKIP_SIG].set
+                              ? GRUB_FILE_TYPE_SKIP_SIGNATURE
+                              : 0));
       if (!pkf)
        return grub_errno;
       pk = grub_load_public_key (pkf);
@@ -786,16 +790,16 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt,
       grub_file_close (pkf);
     }
 
-  grub_file_filter_disable_all ();
-  f = grub_file_open (args[0]);
+  f = grub_file_open (args[0], GRUB_FILE_TYPE_VERIFY_SIGNATURE);
   if (!f)
     {
       err = grub_errno;
       goto fail;
     }
 
-  grub_file_filter_disable_all ();
-  sig = grub_file_open (args[1]);
+  sig = grub_file_open (args[1],
+                       GRUB_FILE_TYPE_SIGNATURE
+                       | GRUB_FILE_TYPE_NO_DECOMPRESS);
   if (!sig)
     {
       err = grub_errno;
@@ -858,33 +862,32 @@ struct grub_fs verified_fs =
 };
 
 static grub_file_t
-grub_pubkey_open (grub_file_t io, const char *filename)
+grub_pubkey_open (grub_file_t io, enum grub_file_type type)
 {
   grub_file_t sig;
   char *fsuf, *ptr;
   grub_err_t err;
-  grub_file_filter_t curfilt[GRUB_FILE_FILTER_MAX];
   grub_file_t ret;
   grub_verified_t verified;
 
+  if ((type & GRUB_FILE_TYPE_MASK) == GRUB_FILE_TYPE_SIGNATURE
+      || (type & GRUB_FILE_TYPE_MASK) == GRUB_FILE_TYPE_VERIFY_SIGNATURE
+      || (type & GRUB_FILE_TYPE_SKIP_SIGNATURE))
+    return io;
+
   if (!sec)
     return io;
   if (io->device->disk && 
       (io->device->disk->dev->id == GRUB_DISK_DEVICE_MEMDISK_ID
        || io->device->disk->dev->id == GRUB_DISK_DEVICE_PROCFS_ID))
     return io;
-  fsuf = grub_malloc (grub_strlen (filename) + sizeof (".sig"));
+  fsuf = grub_malloc (grub_strlen (io->name) + sizeof (".sig"));
   if (!fsuf)
     return NULL;
-  ptr = grub_stpcpy (fsuf, filename);
+  ptr = grub_stpcpy (fsuf, io->name);
   grub_memcpy (ptr, ".sig", sizeof (".sig"));
 
-  grub_memcpy (curfilt, grub_file_filters_enabled,
-              sizeof (curfilt));
-  grub_file_filter_disable_all ();
-  sig = grub_file_open (fsuf);
-  grub_memcpy (grub_file_filters_enabled, curfilt,
-              sizeof (curfilt));
+  sig = grub_file_open (fsuf, GRUB_FILE_TYPE_SIGNATURE);
   grub_free (fsuf);
   if (!sig)
     return NULL;
@@ -892,7 +895,7 @@ grub_pubkey_open (grub_file_t io, const char *filename)
   ret = grub_malloc (sizeof (*ret));
   if (!ret)
     {
-      grub_file_close (sig);
+      grub_free (fsuf);
       return NULL;
     }
   *ret = *io;
@@ -918,7 +921,7 @@ grub_pubkey_open (grub_file_t io, const char *filename)
   if (!verified->buf)
     {
       grub_file_close (sig);
-      grub_free (verified);
+      verified_free (verified);
       grub_free (ret);
       return NULL;
     }
@@ -926,7 +929,7 @@ grub_pubkey_open (grub_file_t io, const char *filename)
     {
       if (!grub_errno)
        grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
-                   filename);
+                   io->name);
       grub_file_close (sig);
       verified_free (verified);
       grub_free (ret);
index 2d8deaeafbd128cf6b791adc4a50fec4e53770a4..9406d931cdd80886f210352ea074b6078f9c3daf 100644 (file)
@@ -92,7 +92,8 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
   if (argc < 2)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
 
-  file = grub_file_open (args[1]);
+  file = grub_file_open (args[1], GRUB_FILE_TYPE_LOOPBACK
+                        | GRUB_FILE_TYPE_NO_DECOMPRESS);
   if (! file)
     return grub_errno;
 
index f6813b1ed15f26d05dea9a5aac8233eccc3bf5e5..a81934725bea6027edc2e6eb01c9c69f7bb79272 100644 (file)
@@ -187,7 +187,7 @@ grub_efiemu_load_file (const char *filename)
   grub_file_t file;
   grub_err_t err;
 
-  file = grub_file_open (filename);
+  file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE);
   if (! file)
     return grub_errno;
 
index 53d76a64d042f2dab0d8584723cfc90e91d8245c..85a292557ac7593da89fb97d31237f1efa43aecd 100644 (file)
@@ -418,7 +418,7 @@ grub_font_load (const char *filename)
 #endif
 
   if (filename[0] == '(' || filename[0] == '/' || filename[0] == '+')
-    file = grub_buffile_open (filename, 1024);
+    file = grub_buffile_open (filename, GRUB_FILE_TYPE_FONT, 1024);
   else
     {
       const char *prefix = grub_env_get ("prefix");
@@ -438,7 +438,7 @@ grub_font_load (const char *filename)
       ptr = grub_stpcpy (ptr, filename);
       ptr = grub_stpcpy (ptr, ".pf2");
       *ptr = 0;
-      file = grub_buffile_open (fullname, 1024);
+      file = grub_buffile_open (fullname, GRUB_FILE_TYPE_FONT, 1024);
       grub_free (fullname);
     }
   if (!file)
index 87eef621d6daf16d62d6196d2fc5897453e74fa3..1402e0bc29bed1e3871e1bf7bd07b4b9989e9025 100644 (file)
@@ -425,7 +425,7 @@ grub_cmd_zfs_key (grub_extcmd_context_t ctxt, int argc, char **args)
   if (argc > 0)
     {
       grub_file_t file;
-      file = grub_file_open (args[0]);
+      file = grub_file_open (args[0], GRUB_FILE_TYPE_ZFS_ENCRYPTION_KEY);
       if (!file)
        return grub_errno;
       real_size = grub_file_read (file, buf, 1024);
index 4880cefe3f8af2c83fbb84ae06258b4e3a485872..4d02e62c10995f283c1b0db5f1eaede816362bc9 100644 (file)
@@ -291,7 +291,7 @@ grub_mofile_open (struct grub_gettext_context *ctx,
   /* Using fd_mo and not another variable because
      it's needed for grub_gettext_get_info.  */
 
-  fd = grub_file_open (filename);
+  fd = grub_file_open (filename, GRUB_FILE_TYPE_GETTEXT_CATALOG);
 
   if (!fd)
     return grub_errno;
index 02978392ccc12299f6861b3b8d787ae40c4f67fe..d6829bb5e9070ca39931746c70771d35cbe85576 100644 (file)
@@ -743,7 +743,7 @@ grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path)
   p.view = view;
   p.theme_dir = grub_get_dirname (theme_path);
 
-  file = grub_file_open (theme_path);
+  file = grub_file_open (theme_path, GRUB_FILE_TYPE_THEME);
   if (! file)
     {
       grub_free (p.theme_dir);
index 22438277d7456358dfc6bcbb51317fd704987738..1049f5fbc8da6d3808da9e853ae30cd57338e95d 100644 (file)
@@ -43,7 +43,8 @@ typedef struct grub_bufio *grub_bufio_t;
 static struct grub_fs grub_bufio_fs;
 
 grub_file_t
-grub_bufio_open (grub_file_t io, int size)
+grub_bufio_open (grub_file_t io,
+                grub_size_t size)
 {
   grub_file_t file;
   grub_bufio_t bufio = 0;
@@ -57,7 +58,7 @@ grub_bufio_open (grub_file_t io, int size)
   else if (size > GRUB_BUFIO_MAX_SIZE)
     size = GRUB_BUFIO_MAX_SIZE;
 
-  if ((size < 0) || ((unsigned) size > io->size))
+  if (size > io->size)
     size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE :
             io->size);
 
@@ -81,11 +82,12 @@ grub_bufio_open (grub_file_t io, int size)
 }
 
 grub_file_t
-grub_buffile_open (const char *name, int size)
+grub_buffile_open (const char *name, enum grub_file_type type,
+                  grub_size_t size)
 {
   grub_file_t io, file;
 
-  io = grub_file_open (name);
+  io = grub_file_open (name, type);
   if (! io)
     return 0;
 
index 0f2ea6bd845227265eef205c212e7c52ee03ebcf..def5bc9698df83c1cd6e9d5e7322536e8ced2b4a 100644 (file)
@@ -1125,11 +1125,14 @@ initialize_tables (grub_gzio_t gzio)
    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.  */
 static grub_file_t
-grub_gzio_open (grub_file_t io, const char *name __attribute__ ((unused)))
+grub_gzio_open (grub_file_t io, enum grub_file_type type)
 {
   grub_file_t file;
   grub_gzio_t gzio = 0;
 
+  if (type & GRUB_FILE_TYPE_NO_DECOMPRESS)
+    return io;
+
   file = (grub_file_t) grub_zalloc (sizeof (*file));
   if (! file)
     return 0;
index 7559c6c9cab9a94d7052c819976dc21217a30ed8..84edf6dd2dc859822de692838ecd95fad636c05e 100644 (file)
@@ -407,12 +407,14 @@ CORRUPTED:
 }
 
 static grub_file_t
-grub_lzopio_open (grub_file_t io,
-                 const char *name __attribute__ ((unused)))
+grub_lzopio_open (grub_file_t io, enum grub_file_type type)
 {
   grub_file_t file;
   grub_lzopio_t lzopio;
 
+  if (type & GRUB_FILE_TYPE_NO_DECOMPRESS)
+    return io;
+
   file = (grub_file_t) grub_zalloc (sizeof (*file));
   if (!file)
     return 0;
index ebed0ebe63e127e2849a7a3e66cc339310f6d202..ec8e2320871d0d849cfda0dc08cabc011bf97848 100644 (file)
@@ -69,7 +69,8 @@ grub_file_offset_close (grub_file_t file)
 }
 
 grub_file_t
-grub_file_offset_open (grub_file_t parent, grub_off_t start, grub_off_t size)
+grub_file_offset_open (grub_file_t parent, enum grub_file_type type,
+                      grub_off_t start, grub_off_t size)
 {
   struct grub_offset_file *off_data;
   grub_file_t off_file, last_off_file;
@@ -95,10 +96,10 @@ grub_file_offset_open (grub_file_t parent, grub_off_t start, grub_off_t size)
   last_off_file = NULL;
   for (filter = GRUB_FILE_FILTER_COMPRESSION_FIRST;
        off_file && filter <= GRUB_FILE_FILTER_COMPRESSION_LAST; filter++)
-    if (grub_file_filters_enabled[filter])
+    if (grub_file_filters[filter])
       {
        last_off_file = off_file;
-       off_file = grub_file_filters_enabled[filter] (off_file, parent->name);
+       off_file = grub_file_filters[filter] (off_file, type);
       }
 
   if (!off_file)
index a3536ad73b19e0a2c0925796b4b9ce8e6fee2bff..42afeedcd6400351a576cf21813ee12a4df27dba 100644 (file)
@@ -169,12 +169,14 @@ ERROR:
 }
 
 static grub_file_t
-grub_xzio_open (grub_file_t io,
-               const char *name __attribute__ ((unused)))
+grub_xzio_open (grub_file_t io, enum grub_file_type type)
 {
   grub_file_t file;
   grub_xzio_t xzio;
 
+  if (type & GRUB_FILE_TYPE_NO_DECOMPRESS)
+    return io;
+
   file = (grub_file_t) grub_zalloc (sizeof (*file));
   if (!file)
     return 0;
index e394cd96f8c06705efd44ac17f589ffa09329df8..f8d58f029c275a418ede58f417474010f255a156 100644 (file)
@@ -688,7 +688,7 @@ grub_dl_load_file (const char *filename)
 
   grub_boot_time ("Loading module %s", filename);
 
-  file = grub_file_open (filename);
+  file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE);
   if (! file)
     return 0;
 
index 4f282c9cf431a79febf7aaa1a7879a2c846c08d5..9d7149b389272b18d4c6092b952bd4bbb284bfe7 100644 (file)
@@ -136,12 +136,12 @@ fail:
 }
 
 grub_elf_t
-grub_elf_open (const char *name)
+grub_elf_open (const char *name, enum grub_file_type type)
 {
   grub_file_t file;
   grub_elf_t elf;
 
-  file = grub_file_open (name);
+  file = grub_file_open (name, type);
   if (! file)
     return 0;
 
index 668f8930b1963d8476505beb29346f226228d5cb..643154237208a896723f88602b9daff80c255735 100644 (file)
@@ -28,8 +28,7 @@
 
 void (*EXPORT_VAR (grub_grubnet_fini)) (void);
 
-grub_file_filter_t grub_file_filters_all[GRUB_FILE_FILTER_MAX];
-grub_file_filter_t grub_file_filters_enabled[GRUB_FILE_FILTER_MAX];
+grub_file_filter_t grub_file_filters[GRUB_FILE_FILTER_MAX];
 
 /* Get the device part of the filename NAME. It is enclosed by parentheses.  */
 char *
@@ -59,7 +58,7 @@ grub_file_get_device_name (const char *name)
 }
 
 grub_file_t
-grub_file_open (const char *name)
+grub_file_open (const char *name, enum grub_file_type type)
 {
   grub_device_t device = 0;
   grub_file_t file = 0, last_file = 0;
@@ -114,18 +113,20 @@ grub_file_open (const char *name)
   file->name = grub_strdup (name);
   grub_errno = GRUB_ERR_NONE;
 
-  for (filter = 0; file && filter < ARRAY_SIZE (grub_file_filters_enabled);
+  for (filter = 0; file && filter < ARRAY_SIZE (grub_file_filters);
        filter++)
-    if (grub_file_filters_enabled[filter])
+    if (grub_file_filters[filter])
       {
        last_file = file;
-       file = grub_file_filters_enabled[filter] (file, name);
+       file = grub_file_filters[filter] (file, type);
+       if (file && file != last_file)
+         {
+           file->name = grub_strdup (name);
+           grub_errno = GRUB_ERR_NONE;
+         }
       }
   if (!file)
     grub_file_close (last_file);
-    
-  grub_memcpy (grub_file_filters_enabled, grub_file_filters_all,
-              sizeof (grub_file_filters_enabled));
 
   return file;
 
@@ -137,9 +138,6 @@ 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;
 }
 
index 28ba3aef0bb07b00b9554ec9b08c667b18717fa1..c96d85ee515e2fc2a16dd518ae14ec371ebbd54e 100644 (file)
@@ -696,7 +696,7 @@ syslinux_parse_real (struct syslinux_menu *menu)
   char *buf = NULL;
   grub_err_t err = GRUB_ERR_NONE;
 
-  file = grub_file_open (menu->filename);
+  file = grub_file_open (menu->filename, GRUB_FILE_TYPE_CONFIG);
   if (!file)
     return grub_errno;
   while ((grub_free (buf), buf = grub_file_getline (file)))
index adc8563663327ec9ddb255f2cb38c8facfaae1be..f706b1ac30a333aca71e05286654c34c86fb75a0 100644 (file)
@@ -219,7 +219,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
 
   b = grub_efi_system_table->boot_services;
 
-  file = grub_file_open (filename);
+  file = grub_file_open (filename, GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE);
   if (! file)
     goto fail;
 
index 7f96515da6523c1fefb42d673fd44ca88523fbd8..d34da14d981593a5a27a571741dc515135886d95 100644 (file)
@@ -1457,7 +1457,7 @@ grub_bsd_load (int argc, char *argv[])
       goto fail;
     }
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
   if (!file)
     goto fail;
 
@@ -1534,7 +1534,7 @@ grub_cmd_freebsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
          if (err)
            return err;
 
-         file = grub_file_open (argv[0]);
+         file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
          if (! file)
            return grub_errno;
 
@@ -1693,7 +1693,7 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
        {
          grub_file_t file;
 
-         file = grub_file_open (argv[0]);
+         file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
          if (! file)
            return grub_errno;
 
@@ -1802,7 +1802,7 @@ grub_cmd_freebsd_loadenv (grub_command_t cmd __attribute__ ((unused)),
       goto fail;
     }
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_ENV);
   if ((!file) || (!file->size))
     goto fail;
 
@@ -1907,7 +1907,7 @@ grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)),
       return 0;
     }
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_MODULE);
   if ((!file) || (!file->size))
     goto fail;
 
@@ -1958,7 +1958,7 @@ grub_netbsd_module_load (char *filename, grub_uint32_t type)
   void *src;
   grub_err_t err;
 
-  file = grub_file_open (filename);
+  file = grub_file_open (filename, GRUB_FILE_TYPE_NETBSD_MODULE);
   if ((!file) || (!file->size))
     goto fail;
 
@@ -2048,7 +2048,7 @@ grub_cmd_freebsd_module_elf (grub_command_t cmd __attribute__ ((unused)),
       return 0;
     }
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_MODULE_ELF);
   if (!file)
     return grub_errno;
   if (!file->size)
@@ -2088,7 +2088,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_file_open (args[0]);
+  file = grub_file_open (args[0], GRUB_FILE_TYPE_OPENBSD_RAMDISK);
   if (! file)
     return grub_errno;
 
index 2cb78eee090274b9a757ba693c88a01c17f4a91e..0a19ebb9c3e54a03de5d19d2e33278ffeea6a3c5 100644 (file)
@@ -439,7 +439,7 @@ grub_cmd_chain (grub_command_t cmd __attribute__ ((unused)),
 
   grub_loader_unset ();
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_COREBOOT_CHAINLOADER);
   if (!file)
     return grub_errno;
 
index 083f9417cb65e509e673dba09a71616c5661ab05..7ec71abadcdb4508a4cfd633d3f155bf274fd19a 100644 (file)
@@ -695,7 +695,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
       goto fail;
     }
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
   if (! file)
     goto fail;
 
index c79c4fe0fc99a876b3e92f0a24f16cd636e00a0d..54d7171828b1285c8056e33fcfabd436d561b155 100644 (file)
@@ -156,8 +156,8 @@ 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);
+  file = grub_file_open (filename, GRUB_FILE_TYPE_PCCHAINLOADER
+                        | GRUB_FILE_TYPE_NO_DECOMPRESS);
   if (! file)
     goto fail;
 
index 478f3c5139d43654c0d7bdc4bbe2a6d8e58cb1a0..aac6c9715f6913fc8fa0e781c208d3852eee38cc 100644 (file)
@@ -110,7 +110,7 @@ grub_cmd_freedos (grub_command_t cmd __attribute__ ((unused)),
   if (!rel)
     goto fail;
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEDOS);
   if (! file)
     goto fail;
 
index a293b17aa101b308635bbed4086ae1547b91b884..ae769bb2eccbe5ffbe4a61dc94745961ebd33e27 100644 (file)
@@ -139,7 +139,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
       goto fail;
     }
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
   if (! file)
     goto fail;
 
index 1b88f40d87198200e1f9f319d712f495d645928d..f0d74145b38d02ed284017830490782dd756a9a1 100644 (file)
@@ -90,7 +90,7 @@ grub_cmd_ntldr (grub_command_t cmd __attribute__ ((unused)),
   if (!rel)
     goto fail;
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_NTLDR);
   if (! file)
     goto fail;
 
index 814a49d5071fb2438c5d644916177aead7d445e0..0351090daf813d1a653741fd424685ff9c4e77cd 100644 (file)
@@ -413,7 +413,7 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
   if (!rel)
     goto fail;
 
-  fill_ctx.file = grub_file_open (argv[0]);
+  fill_ctx.file = grub_file_open (argv[0], GRUB_FILE_TYPE_PLAN9_KERNEL);
   if (! fill_ctx.file)
     goto fail;
 
index e60c62b1badd958ade575040384e10dff90f95dd..acb061169b94c3dd05b8e051bbb36dd8b4759cbb 100644 (file)
@@ -99,7 +99,7 @@ grub_cmd_pxechain (grub_command_t cmd __attribute__ ((unused)),
   if (!rel)
     goto fail;
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_PXECHAINLOADER);
   if (! file)
     goto fail;
 
index 9ea4fde42a560cccbd1b74ce3cd699a7512359c9..cbeeec7beaeaf3706f51160d29806d230de01b97 100644 (file)
@@ -99,7 +99,7 @@ grub_cmd_truecrypt (grub_command_t cmd __attribute__ ((unused)),
 
   grub_dl_ref (my_mod);
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_TRUECRYPT);
   if (! file)
     goto fail;
 
index 3073f64d5e514a5d4a7eda4b263d72ff3ee755a8..85cc8d93fc236bf7070d61044736afc422453b71 100644 (file)
@@ -648,7 +648,7 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)),
                              (char *) xen_state.next_start.cmd_line,
                              sizeof (xen_state.next_start.cmd_line) - 1);
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
   if (!file)
     return grub_errno;
 
@@ -893,9 +893,8 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
 
   xen_state.max_addr = ALIGN_UP (xen_state.max_addr, PAGE_SIZE);
 
-  if (nounzip)
-    grub_file_filter_disable_compression ();
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_INITRD |
+                        (nounzip ? GRUB_FILE_TYPE_NO_DECOMPRESS : 0));
   if (!file)
     return grub_errno;
   size = grub_file_size (file);
index 99fad4cadae42ab09497babca15cd9606557fcd2..52b75fad82c5f0c1ed3f7e64c54d1bfaeea52263 100644 (file)
@@ -78,7 +78,7 @@ grub_xen_file (grub_file_t file)
      Trim it.  */
   if (grub_memcmp (magic, XZ_MAGIC, sizeof (XZ_MAGIC) - 1) == 0)
     payload_length -= 4;
-  off_file = grub_file_offset_open (file, payload_offset,
+  off_file = grub_file_offset_open (file, GRUB_FILE_TYPE_LINUX_KERNEL, payload_offset,
                                    payload_length);
   if (!off_file)
     goto fail;
index 59ef73a73850bdca6b78efd3807042b7260f0557..e64ed08f580f2704619f48c74725be3f8b7fd132 100644 (file)
@@ -487,7 +487,7 @@ grub_cmd_devprop_load (grub_command_t cmd __attribute__ ((unused)),
   if (argc != 1)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
 
-  file = grub_file_open (args[0]);
+  file = grub_file_open (args[0], GRUB_FILE_XNU_DEVPROP);
   if (! file)
     return grub_errno;
   size = grub_file_size (file);
index be6fa0f4d45126f1ca5f67925241a8a6a944ae45..471b214d6c37b588c88fa6c3e7c3bcb4a286a14b 100644 (file)
@@ -173,7 +173,6 @@ grub_initrd_init (int argc, char *argv[],
          eptr = grub_strchr (ptr, ':');
          if (eptr)
            {
-             grub_file_filter_disable_compression ();
              initrd_ctx->components[i].newc_name = grub_strndup (ptr, eptr - ptr);
              if (!initrd_ctx->components[i].newc_name)
                {
@@ -198,8 +197,9 @@ grub_initrd_init (int argc, char *argv[],
          root = 0;
          newc = 0;
        }
-      grub_file_filter_disable_compression ();
-      initrd_ctx->components[i].file = grub_file_open (fname);
+      initrd_ctx->components[i].file = grub_file_open (fname,
+                                                      GRUB_FILE_TYPE_LINUX_INITRD
+                                                      | GRUB_FILE_TYPE_NO_DECOMPRESS);
       if (!initrd_ctx->components[i].file)
        {
          grub_initrd_close (initrd_ctx);
index 59b195e27eaba9ff77d3bf5a0bb8ac23427fb9a4..085f9c6890a3aa51a2dc738f1b5d60a63badef20 100644 (file)
@@ -188,12 +188,12 @@ fail:
 }
 
 grub_macho_t
-grub_macho_open (const char *name, int is_64bit)
+grub_macho_open (const char *name, enum grub_file_type type, int is_64bit)
 {
   grub_file_t file;
   grub_macho_t macho;
 
-  file = grub_file_open (name);
+  file = grub_file_open (name, type);
   if (! file)
     return 0;
 
index 5f383be3d076985199474410f7a09fbb5c3e581b..7b28ba73166928eb7cb5e87f47b7c63534552f14 100644 (file)
@@ -237,7 +237,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   if (argc == 0)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
 
-  elf = grub_elf_open (argv[0]);
+  elf = grub_elf_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
   if (! elf)
     return grub_errno;
 
index bd9d5b3e698588db594a2c334d715e0e883bab92..0730e47c8ee7207030e7c2b45a051a62757faf67 100644 (file)
@@ -306,7 +306,7 @@ grub_cmd_multiboot (grub_command_t cmd __attribute__ ((unused)),
   if (argc == 0)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
 
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_MULTIBOOT_KERNEL);
   if (! file)
     return grub_errno;
 
@@ -372,10 +372,8 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
     return grub_error (GRUB_ERR_BAD_ARGUMENT,
                       N_("you need to load the kernel first"));
 
-  if (nounzip)
-    grub_file_filter_disable_compression ();
-
-  file = grub_file_open (argv[0]);
+  file = grub_file_open (argv[0], GRUB_FILE_TYPE_MULTIBOOT_MODULE
+                        | (nounzip ? GRUB_FILE_TYPE_NO_DECOMPRESS : 0));
   if (! file)
     return grub_errno;
 
index c9885b1bcd7304785eab07e020208fc833732bc9..84c8b939c8177e8da5fed9a18bcd2c39644fd227 100644 (file)
@@ -351,7 +351,7 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
 
   grub_xnu_unload ();
 
-  macho = grub_macho_open (args[0], 0);
+  macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL, 0);
   if (! macho)
     return grub_errno;
 
@@ -456,7 +456,7 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
 
   grub_xnu_unload ();
 
-  macho = grub_macho_open (args[0], 1);
+  macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL, 1);
   if (! macho)
     return grub_errno;
 
@@ -674,7 +674,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile,
     macho = 0;
 
   if (infoplistname)
-    infoplist = grub_file_open (infoplistname);
+    infoplist = grub_file_open (infoplistname, GRUB_FILE_TYPE_XNU_INFO_PLIST);
   else
     infoplist = 0;
   grub_errno = GRUB_ERR_NONE;
@@ -771,7 +771,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
   if (! grub_xnu_heap_size)
     return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
 
-  file = grub_file_open (args[0]);
+  file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_MKEXT);
   if (! file)
     return grub_errno;
 
@@ -885,7 +885,7 @@ grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)),
   if (! grub_xnu_heap_size)
     return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
 
-  file = grub_file_open (args[0]);
+  file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_RAMDISK);
   if (! file)
     return grub_errno;
 
@@ -925,7 +925,7 @@ grub_xnu_check_os_bundle_required (char *plistname,
   if (binname)
     *binname = 0;
 
-  file = grub_file_open (plistname);
+  file = grub_file_open (plistname, GRUB_FILE_TYPE_XNU_INFO_PLIST);
   if (! file)
     return 0;
 
@@ -1210,7 +1210,7 @@ grub_xnu_load_kext_from_dir (char *dirname, const char *osbundlerequired,
                grub_strcpy (binname + grub_strlen (binname), "/");
              grub_strcpy (binname + grub_strlen (binname), binsuffix);
              grub_dprintf ("xnu", "%s:%s\n", ctx.plistname, binname);
-             binfile = grub_file_open (binname);
+             binfile = grub_file_open (binname, GRUB_FILE_TYPE_XNU_KEXT);
              if (! binfile)
                grub_errno = GRUB_ERR_NONE;
 
@@ -1253,7 +1253,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_file_open (args[1]);
+         binfile = grub_file_open (args[1], GRUB_FILE_TYPE_XNU_KEXT);
          if (! binfile)
            return grub_errno;
        }
index 534a74438b2b1ff2223f44067a58fc94fe7d6635..8089804d4822a00a1d8b4ab331069386f0db8c97 100644 (file)
@@ -53,8 +53,8 @@ grub_xnu_resume (char *imagename)
   grub_addr_t target_image;
   grub_err_t err;
 
-  grub_file_filter_disable_compression ();
-  file = grub_file_open (imagename);
+  file = grub_file_open (imagename, GRUB_FILE_TYPE_XNU_HIBERNATE_IMAGE
+                        | GRUB_FILE_TYPE_NO_DECOMPRESS);
   if (! file)
     return 0;
 
index 721b9c3256db793da31ab9c51ed7a3d688baf91e..7a7cf2b0f7e3d72cb70b849c33b57f4c5784e540 100644 (file)
@@ -33,12 +33,6 @@ autoload_fs_module (void)
 {
   grub_named_list_t p;
   int ret = 0;
-  grub_file_filter_t grub_file_filters_was[GRUB_FILE_FILTER_MAX];
-
-  grub_memcpy (grub_file_filters_was, grub_file_filters_enabled,
-              sizeof (grub_file_filters_enabled));
-  grub_memcpy (grub_file_filters_enabled, grub_file_filters_all,
-              sizeof (grub_file_filters_enabled));
 
   while ((p = fs_module_list) != NULL)
     {
@@ -56,9 +50,6 @@ autoload_fs_module (void)
       grub_free (p);
     }
 
-  grub_memcpy (grub_file_filters_enabled, grub_file_filters_was,
-              sizeof (grub_file_filters_enabled));
-
   return ret;
 }
 
@@ -82,7 +73,7 @@ read_fs_list (const char *prefix)
          tmp_autoload_hook = grub_fs_autoload_hook;
          grub_fs_autoload_hook = NULL;
 
-         file = grub_file_open (filename);
+         file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
          if (file)
            {
              /* Override previous fs.lst.  */
index 2bfd67c8ef388097701a7415df3cd7321c6a1e57..d5443380284a4af92270c474b91be0575bee7015 100644 (file)
@@ -94,7 +94,7 @@ read_crypto_list (const char *prefix)
       return;
     }
 
-  file = grub_file_open (filename);
+  file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
   grub_free (filename);
   if (!file)
     {
index 169c126f5080dda6599c8059823bb9dc1d134f56..719ebf477f2f6178c7a5667f76c3595a646251f9 100644 (file)
@@ -106,7 +106,7 @@ read_command_list (const char *prefix)
        {
          grub_file_t file;
 
-         file = grub_file_open (filename);
+         file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
          if (file)
            {
              char *buf = NULL;
index 78a70a8bf479bfeb7f8ee9411a148d12d8f7c5df..1b03dfd57b9113ba0e6fee3475d25d55534a15e5 100644 (file)
@@ -123,7 +123,7 @@ read_config_file (const char *config)
     }
 
   /* Try to open the config file.  */
-  rawfile = grub_file_open (config);
+  rawfile = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
   if (! rawfile)
     return 0;
 
index ac5d69f0fb5e0bda21875ec7736fafc96cb6cd9c..a1e5c5a0daf657887b4fa89f7d275ac19d99b9a8 100644 (file)
@@ -331,7 +331,7 @@ read_terminal_list (const char *prefix)
       return;
     }
 
-  file = grub_file_open (filename);
+  file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
   grub_free (filename);
   if (!file)
     {
index 21b0d9ded672aca9063a6b6f013b285a3d9ef215..31359a4c9c8a5bd289d9d1d620962a3d163d171a 100644 (file)
@@ -772,7 +772,7 @@ grub_video_reader_jpeg (struct grub_video_bitmap **bitmap,
   grub_file_t file;
   struct grub_jpeg_data *data;
 
-  file = grub_buffile_open (filename, 0);
+  file = grub_buffile_open (filename, GRUB_FILE_TYPE_PIXMAP, 0);
   if (!file)
     return grub_errno;
 
index e1a01e99fd09190040d8a3f3ee61a633f11eb796..777e71334cb2772b9c0bad138e3ab24a510cc36f 100644 (file)
@@ -1086,7 +1086,7 @@ grub_video_reader_png (struct grub_video_bitmap **bitmap,
   grub_file_t file;
   struct grub_png_data *data;
 
-  file = grub_buffile_open (filename, 0);
+  file = grub_buffile_open (filename, GRUB_FILE_TYPE_PIXMAP, 0);
   if (!file)
     return grub_errno;
 
index c7a16fa9cc473baef9ba480d7de8fc948e71f493..7cb9d1d2a0cb3bfae13c46c5b61128b29c0986a8 100644 (file)
@@ -297,7 +297,7 @@ grub_video_reader_tga (struct grub_video_bitmap **bitmap,
 
   grub_memset (&data, 0, sizeof (data));
 
-  data.file = grub_buffile_open (filename, 0);
+  data.file = grub_buffile_open (filename, GRUB_FILE_TYPE_PIXMAP, 0);
   if (! data.file)
     return grub_errno;
 
index acdd0c882c6b882485136fcc6108b5bec3fc2fbc..0ff72d1033c1e389b7e265785a7131625380cefd 100644 (file)
@@ -22,7 +22,9 @@
 
 #include <grub/file.h>
 
-grub_file_t EXPORT_FUNC (grub_bufio_open) (grub_file_t io, int size);
-grub_file_t EXPORT_FUNC (grub_buffile_open) (const char *name, int size);
+grub_file_t EXPORT_FUNC (grub_bufio_open) (grub_file_t io, grub_size_t size);
+grub_file_t EXPORT_FUNC (grub_buffile_open) (const char *name,
+                                            enum grub_file_type type,
+                                            grub_size_t size);
 
 #endif /* ! GRUB_BUFIO_H */
index 9a7ae4ebb30a7ac15d481b06d1f37f63b77fd9fe..dbb609c9b207864c050b4ebbf3005204836d1a74 100644 (file)
@@ -42,7 +42,7 @@ typedef int (*grub_elf32_phdr_iterate_hook_t)
 typedef int (*grub_elf64_phdr_iterate_hook_t)
   (grub_elf_t elf, Elf64_Phdr *phdr, void *arg);
 
-grub_elf_t grub_elf_open (const char *);
+grub_elf_t grub_elf_open (const char *, enum grub_file_type type);
 grub_elf_t grub_elf_file (grub_file_t file, const char *filename);
 grub_err_t grub_elf_close (grub_elf_t);
 
index 739488cbe59aaa044b37611d00fb2c6c615e2c31..e2795d1718338d50f9f54c72de59b55dae83a116 100644 (file)
 #include <grub/fs.h>
 #include <grub/disk.h>
 
+enum grub_file_type
+  {
+    /* GRUB module to be loaded.  */
+    GRUB_FILE_TYPE_GRUB_MODULE,
+    /* Loopback file to be represented as disk.  */
+    GRUB_FILE_TYPE_LOOPBACK,
+    /* Linux kernel to be loaded.  */
+    GRUB_FILE_TYPE_LINUX_KERNEL,
+    /* Linux initrd.  */
+    GRUB_FILE_TYPE_LINUX_INITRD,
+
+    /* Multiboot kernel.  */
+    GRUB_FILE_TYPE_MULTIBOOT_KERNEL,
+    /* Multiboot module.  */
+    GRUB_FILE_TYPE_MULTIBOOT_MODULE,
+
+    GRUB_FILE_TYPE_BSD_KERNEL,
+    GRUB_FILE_TYPE_FREEBSD_ENV,
+    GRUB_FILE_TYPE_FREEBSD_MODULE,
+    GRUB_FILE_TYPE_FREEBSD_MODULE_ELF,
+    GRUB_FILE_TYPE_NETBSD_MODULE,
+    GRUB_FILE_TYPE_OPENBSD_RAMDISK,
+
+    GRUB_FILE_TYPE_XNU_INFO_PLIST,
+    GRUB_FILE_TYPE_XNU_MKEXT,
+    GRUB_FILE_TYPE_XNU_KEXT,
+    GRUB_FILE_TYPE_XNU_KERNEL,
+    GRUB_FILE_TYPE_XNU_RAMDISK,
+    GRUB_FILE_TYPE_XNU_HIBERNATE_IMAGE,
+    GRUB_FILE_XNU_DEVPROP,
+
+    GRUB_FILE_TYPE_PLAN9_KERNEL,
+
+    GRUB_FILE_TYPE_NTLDR,
+    GRUB_FILE_TYPE_TRUECRYPT,
+    GRUB_FILE_TYPE_FREEDOS,
+    GRUB_FILE_TYPE_PXECHAINLOADER,
+    GRUB_FILE_TYPE_PCCHAINLOADER,
+
+    GRUB_FILE_TYPE_COREBOOT_CHAINLOADER,
+
+    GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE,
+
+    /* File holding signature.  */
+    GRUB_FILE_TYPE_SIGNATURE,
+    /* File holding public key to verify signature once.  */
+    GRUB_FILE_TYPE_PUBLIC_KEY,
+    /* File holding public key to add to trused keys.  */
+    GRUB_FILE_TYPE_PUBLIC_KEY_TRUST,
+    /* File of which we intend to print a blocklist to the user.  */
+    GRUB_FILE_TYPE_PRINT_BLOCKLIST,
+    /* File we intend to use for test loading or testing speed.  */
+    GRUB_FILE_TYPE_TESTLOAD,
+    /* File we open only to get its size. E.g. in ls output.  */
+    GRUB_FILE_TYPE_GET_SIZE,
+    /* Font file.  */
+    GRUB_FILE_TYPE_FONT,
+    /* File holding encryption key for encrypted ZFS.  */
+    GRUB_FILE_TYPE_ZFS_ENCRYPTION_KEY,
+    /* File we open n grub-fstest.  */
+    GRUB_FILE_TYPE_FSTEST,
+    /* File we open n grub-mount.  */
+    GRUB_FILE_TYPE_MOUNT,
+    /* File which we attempt to identify the type of.  */
+    GRUB_FILE_TYPE_FILE_ID,
+    /* File holding ACPI table.  */
+    GRUB_FILE_TYPE_ACPI_TABLE,
+    /* File we intend show to user.  */
+    GRUB_FILE_TYPE_CAT,
+    GRUB_FILE_TYPE_HEXCAT,
+    /* One of pair of files we intend to compare.  */
+    GRUB_FILE_TYPE_CMP,
+    /* List of hashes for hashsum.  */
+    GRUB_FILE_TYPE_HASHLIST,
+    /* File hashed by hashsum.  */
+    GRUB_FILE_TYPE_TO_HASH,
+    /* Keyboard layout.  */
+    GRUB_FILE_TYPE_KEYBOARD_LAYOUT,
+    /* Picture file.  */
+    GRUB_FILE_TYPE_PIXMAP,
+    /* *.lst shipped by GRUB.  */
+    GRUB_FILE_TYPE_GRUB_MODULE_LIST,
+    /* config file.  */
+    GRUB_FILE_TYPE_CONFIG,
+    GRUB_FILE_TYPE_THEME,
+    GRUB_FILE_TYPE_GETTEXT_CATALOG,
+    GRUB_FILE_TYPE_FS_SEARCH,
+    GRUB_FILE_TYPE_AUDIO,
+    GRUB_FILE_TYPE_VBE_DUMP,
+
+    GRUB_FILE_TYPE_LOADENV,
+    GRUB_FILE_TYPE_SAVEENV,
+
+    GRUB_FILE_TYPE_VERIFY_SIGNATURE,
+
+    GRUB_FILE_TYPE_MASK = 0xffff,
+
+    /* --skip-sig is specified.  */
+    GRUB_FILE_TYPE_SKIP_SIGNATURE = 0x10000,
+    GRUB_FILE_TYPE_NO_DECOMPRESS = 0x20000,
+  };
+
 /* File description.  */
 struct grub_file
 {
@@ -77,61 +179,26 @@ typedef enum grub_file_filter_id
     GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO,
   } grub_file_filter_id_t;
 
-typedef grub_file_t (*grub_file_filter_t) (grub_file_t in, const char *filename);
+typedef grub_file_t (*grub_file_filter_t) (grub_file_t in, enum grub_file_type type);
 
-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];
+extern grub_file_filter_t EXPORT_VAR(grub_file_filters)[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;
+  grub_file_filters[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;
-}
-
-static inline void
-grub_file_filter_disable_all (void)
-{
-  grub_file_filter_id_t id;
-
-  for (id = 0;
-       id < GRUB_FILE_FILTER_MAX; id++)
-    grub_file_filters_enabled[id] = 0;
-}
-
-static inline void
-grub_file_filter_disable_pubkey (void)
-{
-  grub_file_filters_enabled[GRUB_FILE_FILTER_PUBKEY] = 0;
+  grub_file_filters[id] = 0;
 }
 
 /* Get a device name from NAME.  */
 char *EXPORT_FUNC(grub_file_get_device_name) (const char *name);
 
-grub_file_t EXPORT_FUNC(grub_file_open) (const char *name);
+grub_file_t EXPORT_FUNC(grub_file_open) (const char *name, enum grub_file_type type);
 grub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf,
                                          grub_size_t len);
 grub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset);
@@ -159,8 +226,8 @@ grub_file_seekable (const grub_file_t file)
 }
 
 grub_file_t
-grub_file_offset_open (grub_file_t parent, grub_off_t start,
-                      grub_off_t size);
+grub_file_offset_open (grub_file_t parent, enum grub_file_type type,
+                      grub_off_t start, grub_off_t size);
 void
 grub_file_offset_close (grub_file_t file);
 
index 1eec118f15f7651f764a54ca5d1db05ea811bd41..f1157f4105b76df450fc660807105e1a6d7e5630 100644 (file)
@@ -49,7 +49,8 @@ struct grub_macho_file
 };
 typedef struct grub_macho_file *grub_macho_t;
 
-grub_macho_t grub_macho_open (const char *, int is_64bit);
+grub_macho_t grub_macho_open (const char *, enum grub_file_type type,
+                             int is_64bit);
 grub_macho_t grub_macho_file (grub_file_t file, const char *filename,
                              int is_64bit);
 grub_err_t grub_macho_close (grub_macho_t);
index a358ae47152b75e549a891e9d66f80dacd7a905a..f0a17d00bb0eabadf3bf0d90849e24061bec2018 100644 (file)
@@ -120,9 +120,9 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len, void
       return;
     }
 
-  if (uncompress == 0)
-    grub_file_filter_disable_compression ();
-  file = grub_file_open (pathname);
+  file = grub_file_open (pathname, ((uncompress == 0)
+                                   ? GRUB_FILE_TYPE_NO_DECOMPRESS : 0)
+                        | GRUB_FILE_TYPE_FSTEST);
   if (!file)
     {
       grub_util_error (_("cannot open `%s': %s"), pathname,
index a25db8a7181f446e5e69d767eb5eab1e5689cf4e..e32b502e7e4d33990d6523ca023005b577d4df87 100644 (file)
@@ -208,7 +208,7 @@ fuse_getattr (const char *path, struct stat *st)
   if (!ctx.file_info.dir)
     {
       grub_file_t file;
-      file = grub_file_open (path);
+      file = grub_file_open (path, GRUB_FILE_TYPE_GET_SIZE);
       if (! file && grub_errno == GRUB_ERR_BAD_FILE_TYPE)
        {
          grub_errno = GRUB_ERR_NONE;
@@ -244,7 +244,7 @@ static int
 fuse_open (const char *path, struct fuse_file_info *fi __attribute__ ((unused)))
 {
   grub_file_t file;
-  file = grub_file_open (path);
+  file = grub_file_open (path, GRUB_FILE_TYPE_MOUNT);
   if (! file)
     return translate_error ();
   files[first_fd++] = file;
@@ -308,7 +308,7 @@ fuse_readdir_call_fill (const char *filename,
       grub_file_t file;
       char *tmp;
       tmp = xasprintf ("%s/%s", ctx->path, filename);
-      file = grub_file_open (tmp);
+      file = grub_file_open (tmp, GRUB_FILE_TYPE_GET_SIZE);
       free (tmp);
       /* Symlink to directory.  */
       if (! file && grub_errno == GRUB_ERR_BAD_FILE_TYPE)