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