da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * GRUB -- GRand Unified Bootloader
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Copyright (C) 2002,2007 Free Software Foundation, Inc.
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * GRUB is free software: you can redistribute it and/or modify
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * it under the terms of the GNU General Public License as published by
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * the Free Software Foundation, either version 3 of the License, or
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * (at your option) any later version.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * GRUB is distributed in the hope that it will be useful,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * but WITHOUT ANY WARRANTY; without even the implied warranty of
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * GNU General Public License for more details.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * You should have received a copy of the GNU General Public License
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifndef GRUB_FILE_HEADER
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define GRUB_FILE_HEADER 1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <grub/types.h>
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner#include <grub/err.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <grub/device.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <grub/fs.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* File description. */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstruct grub_file
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* The underlying device. */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_device_t device;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* The underlying filesystem. */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_fs_t fs;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* The current offset. */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_off_t offset;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* The file size. */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_off_t size;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* If file is not easily seekable. Should be set by underlying layer. */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int not_easily_seekable;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* Filesystem-specific data. */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin void *data;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* This is called when a sector is read. Used only for a disk device. */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin unsigned offset, unsigned length);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int is_size_approximate;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int enable_progress;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_off_t progress_counter;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_uint64_t progress_last;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin};
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct grub_file *grub_file_t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* Filters with lower ID are executed first. */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef enum grub_file_filter_id
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin GRUB_FILE_FILTER_GZIO,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin GRUB_FILE_FILTER_XZIO,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin GRUB_FILE_FILTER_LZOPIO,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin GRUB_FILE_FILTER_MAX,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin } grub_file_filter_id_t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef grub_file_t (*grub_file_filter_t) (grub_file_t in);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern grub_file_filter_t EXPORT_VAR(grub_file_filters_all)[GRUB_FILE_FILTER_MAX];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern grub_file_filter_t EXPORT_VAR(grub_file_filters_enabled)[GRUB_FILE_FILTER_MAX];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int EXPORT_VAR(grub_file_force_not_easily_seekable);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic inline void
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingrub_file_filter_register (grub_file_filter_id_t id, grub_file_filter_t filter)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_file_filters_all[id] = filter;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_file_filters_enabled[id] = filter;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin};
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic inline void
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingrub_file_filter_unregister (grub_file_filter_id_t id)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_file_filters_all[id] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_file_filters_enabled[id] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin};
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic inline void
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingrub_file_filter_disable (grub_file_filter_id_t id)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_file_filters_enabled[id] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin};
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic inline void
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingrub_file_filter_disable_compression (void)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_file_filter_id_t id;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (id = GRUB_FILE_FILTER_COMPRESSION_FIRST;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin id <= GRUB_FILE_FILTER_COMPRESSION_LAST; id++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_file_filters_enabled[id] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin};
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* Get a device name from NAME. */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinchar *EXPORT_FUNC(grub_file_get_device_name) (const char *name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingrub_file_t EXPORT_FUNC(grub_file_open) (const char *name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinvoid EXPORT_FUNC(grub_file_progress_hook) (grub_file_t file,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_size_t amt_read, int done);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingrub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin grub_size_t len);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingrub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingrub_err_t EXPORT_FUNC(grub_file_close) (grub_file_t file);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* Return value of grub_file_size() in case file size is unknown. */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define GRUB_FILE_SIZE_UNKNOWN 0xffffffffffffffffULL
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic inline grub_off_t
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingrub_file_size (const grub_file_t file)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return file->size;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic inline grub_off_t
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingrub_file_tell (const grub_file_t file)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return file->offset;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic inline int
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingrub_file_seekable (const grub_file_t file)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return !file->not_easily_seekable;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* ! GRUB_FILE_HEADER */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin