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 ();
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;
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;
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;
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;
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;
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)
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? */
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;
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);
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)
{
grub_file_t file;
- file = grub_file_open (args[0]);
+ file = grub_file_open (args[0], GRUB_FILE_TYPE_HEXCAT);
if (! file)
return 0;
--- /dev/null
+/* 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);
+}
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;
else
filename = argv[0];
- file = grub_file_open (filename);
+ file = grub_file_open (filename, GRUB_FILE_TYPE_KEYBOARD_LAYOUT);
if (! file)
goto fail;
if (!suffix)
return grub_errno;
- file = grub_file_open (filename);
+ file = grub_file_open (filename, GRUB_FILE_TYPE_CONFIG);
if (! file)
{
grub_free (suffix);
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;
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;
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;
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;
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;
/* 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;
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;
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;
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;
{
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;
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;
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);
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;
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;
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);
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);
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;
};
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;
ret = grub_malloc (sizeof (*ret));
if (!ret)
{
- grub_file_close (sig);
+ grub_free (fsuf);
return NULL;
}
*ret = *io;
if (!verified->buf)
{
grub_file_close (sig);
- grub_free (verified);
+ verified_free (verified);
grub_free (ret);
return NULL;
}
{
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);
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;
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;
#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");
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)
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);
/* 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;
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);
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;
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);
}
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;
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;
}
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;
}
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;
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)
}
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;
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;
}
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;
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 *
}
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;
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;
grub_free (file);
- grub_memcpy (grub_file_filters_enabled, grub_file_filters_all,
- sizeof (grub_file_filters_enabled));
-
return 0;
}
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)))
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;
goto fail;
}
- file = grub_file_open (argv[0]);
+ file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
if (!file)
goto fail;
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;
{
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;
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;
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;
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;
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)
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;
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;
goto fail;
}
- file = grub_file_open (argv[0]);
+ file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
if (! file)
goto fail;
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;
if (!rel)
goto fail;
- file = grub_file_open (argv[0]);
+ file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEDOS);
if (! file)
goto fail;
goto fail;
}
- file = grub_file_open (argv[0]);
+ file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
if (! file)
goto fail;
if (!rel)
goto fail;
- file = grub_file_open (argv[0]);
+ file = grub_file_open (argv[0], GRUB_FILE_TYPE_NTLDR);
if (! file)
goto fail;
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;
if (!rel)
goto fail;
- file = grub_file_open (argv[0]);
+ file = grub_file_open (argv[0], GRUB_FILE_TYPE_PXECHAINLOADER);
if (! file)
goto fail;
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;
(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;
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);
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;
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);
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)
{
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);
}
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;
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;
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;
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;
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;
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;
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;
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;
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;
if (binname)
*binname = 0;
- file = grub_file_open (plistname);
+ file = grub_file_open (plistname, GRUB_FILE_TYPE_XNU_INFO_PLIST);
if (! file)
return 0;
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;
/* 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;
}
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;
{
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)
{
grub_free (p);
}
- grub_memcpy (grub_file_filters_enabled, grub_file_filters_was,
- sizeof (grub_file_filters_enabled));
-
return ret;
}
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. */
return;
}
- file = grub_file_open (filename);
+ file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
grub_free (filename);
if (!file)
{
{
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;
}
/* Try to open the config file. */
- rawfile = grub_file_open (config);
+ rawfile = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
if (! rawfile)
return 0;
return;
}
- file = grub_file_open (filename);
+ file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
grub_free (filename);
if (!file)
{
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;
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;
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;
#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 */
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);
#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
{
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);
}
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);
};
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);
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,
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;
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;
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)