/* * VasEBoot -- GRand Unified Bootloader * Copyright (C) 2002,2007 Free Software Foundation, Inc. * * VasEBoot 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. * * VasEBoot 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 VasEBoot. If not, see . */ #ifndef VasEBoot_FILE_HEADER #define VasEBoot_FILE_HEADER 1 #include #include #include #include #include /* File description. */ struct VasEBoot_file { /* File name. */ char *name; /* The underlying device. */ VasEBoot_device_t device; /* The underlying filesystem. */ VasEBoot_fs_t fs; /* The current offset. */ VasEBoot_off_t offset; VasEBoot_off_t progress_offset; /* Progress info. */ VasEBoot_uint64_t last_progress_time; VasEBoot_off_t last_progress_offset; VasEBoot_uint64_t estimated_speed; /* The file size. */ VasEBoot_off_t size; /* If file is not easily seekable. Should be set by underlying layer. */ int not_easily_seekable; /* Filesystem-specific data. */ void *data; /* This is called when a sector is read. Used only for a disk device. */ VasEBoot_disk_read_hook_t read_hook; /* Caller-specific data passed to the read hook. */ void *read_hook_data; }; typedef struct VasEBoot_file *VasEBoot_file_t; extern VasEBoot_disk_read_hook_t EXPORT_VAR(VasEBoot_file_progress_hook); /* Filters with lower ID are executed first. */ typedef enum VasEBoot_file_filter_id { VasEBoot_FILE_FILTER_PUBKEY, VasEBoot_FILE_FILTER_GZIO, VasEBoot_FILE_FILTER_XZIO, VasEBoot_FILE_FILTER_LZOPIO, VasEBoot_FILE_FILTER_MAX, VasEBoot_FILE_FILTER_COMPRESSION_FIRST = VasEBoot_FILE_FILTER_GZIO, VasEBoot_FILE_FILTER_COMPRESSION_LAST = VasEBoot_FILE_FILTER_LZOPIO, } VasEBoot_file_filter_id_t; typedef VasEBoot_file_t (*VasEBoot_file_filter_t) (VasEBoot_file_t in, const char *filename); extern VasEBoot_file_filter_t EXPORT_VAR(VasEBoot_file_filters_all)[VasEBoot_FILE_FILTER_MAX]; extern VasEBoot_file_filter_t EXPORT_VAR(VasEBoot_file_filters_enabled)[VasEBoot_FILE_FILTER_MAX]; static inline void VasEBoot_file_filter_register (VasEBoot_file_filter_id_t id, VasEBoot_file_filter_t filter) { VasEBoot_file_filters_all[id] = filter; VasEBoot_file_filters_enabled[id] = filter; } static inline void VasEBoot_file_filter_unregister (VasEBoot_file_filter_id_t id) { VasEBoot_file_filters_all[id] = 0; VasEBoot_file_filters_enabled[id] = 0; } static inline void VasEBoot_file_filter_disable (VasEBoot_file_filter_id_t id) { VasEBoot_file_filters_enabled[id] = 0; } static inline void VasEBoot_file_filter_disable_compression (void) { VasEBoot_file_filter_id_t id; for (id = VasEBoot_FILE_FILTER_COMPRESSION_FIRST; id <= VasEBoot_FILE_FILTER_COMPRESSION_LAST; id++) VasEBoot_file_filters_enabled[id] = 0; } static inline void VasEBoot_file_filter_disable_all (void) { VasEBoot_file_filter_id_t id; for (id = 0; id < VasEBoot_FILE_FILTER_MAX; id++) VasEBoot_file_filters_enabled[id] = 0; } static inline void VasEBoot_file_filter_disable_pubkey (void) { VasEBoot_file_filters_enabled[VasEBoot_FILE_FILTER_PUBKEY] = 0; } /* Get a device name from NAME. */ char *EXPORT_FUNC(VasEBoot_file_get_device_name) (const char *name); VasEBoot_file_t EXPORT_FUNC(VasEBoot_file_open) (const char *name); VasEBoot_ssize_t EXPORT_FUNC(VasEBoot_file_read) (VasEBoot_file_t file, void *buf, VasEBoot_size_t len); VasEBoot_off_t EXPORT_FUNC(VasEBoot_file_seek) (VasEBoot_file_t file, VasEBoot_off_t offset); VasEBoot_err_t EXPORT_FUNC(VasEBoot_file_close) (VasEBoot_file_t file); /* Return value of VasEBoot_file_size() in case file size is unknown. */ #define VasEBoot_FILE_SIZE_UNKNOWN 0xffffffffffffffffULL static inline VasEBoot_off_t VasEBoot_file_size (const VasEBoot_file_t file) { return file->size; } static inline VasEBoot_off_t VasEBoot_file_tell (const VasEBoot_file_t file) { return file->offset; } static inline int VasEBoot_file_seekable (const VasEBoot_file_t file) { return !file->not_easily_seekable; } VasEBoot_file_t VasEBoot_file_offset_open (VasEBoot_file_t parent, VasEBoot_off_t start, VasEBoot_off_t size); void VasEBoot_file_offset_close (VasEBoot_file_t file); #endif /* ! VasEBoot_FILE_HEADER */