/* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2002,2007 Free Software Foundation, Inc. * * VAS_EBOOT 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. * * VAS_EBOOT 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 VAS_EBOOT. If not, see . */ #ifndef VAS_EBOOT_FILE_HEADER #define VAS_EBOOT_FILE_HEADER 1 #include #include #include #include #include enum VasEBoot_file_type { VAS_EBOOT_FILE_TYPE_NONE = 0, /* VAS_EBOOT module to be loaded. */ VAS_EBOOT_FILE_TYPE_VAS_EBOOT_MODULE, /* Loopback file to be represented as disk. */ VAS_EBOOT_FILE_TYPE_LOOPBACK, /* Linux kernel to be loaded. */ VAS_EBOOT_FILE_TYPE_LINUX_KERNEL, /* Linux initrd. */ VAS_EBOOT_FILE_TYPE_LINUX_INITRD, /* Multiboot kernel. */ VAS_EBOOT_FILE_TYPE_MULTIBOOT_KERNEL, /* Multiboot module. */ VAS_EBOOT_FILE_TYPE_MULTIBOOT_MODULE, /* Xen hypervisor - used on ARM only. */ VAS_EBOOT_FILE_TYPE_XEN_HYPERVISOR, /* Xen module - used on ARM only. */ VAS_EBOOT_FILE_TYPE_XEN_MODULE, VAS_EBOOT_FILE_TYPE_BSD_KERNEL, VAS_EBOOT_FILE_TYPE_FREEBSD_ENV, VAS_EBOOT_FILE_TYPE_FREEBSD_MODULE, VAS_EBOOT_FILE_TYPE_FREEBSD_MODULE_ELF, VAS_EBOOT_FILE_TYPE_NETBSD_MODULE, VAS_EBOOT_FILE_TYPE_OPENBSD_RAMDISK, VAS_EBOOT_FILE_TYPE_XNU_INFO_PLIST, VAS_EBOOT_FILE_TYPE_XNU_MKEXT, VAS_EBOOT_FILE_TYPE_XNU_KEXT, VAS_EBOOT_FILE_TYPE_XNU_KERNEL, VAS_EBOOT_FILE_TYPE_XNU_RAMDISK, VAS_EBOOT_FILE_TYPE_XNU_HIBERNATE_IMAGE, VAS_EBOOT_FILE_XNU_DEVPROP, VAS_EBOOT_FILE_TYPE_PLAN9_KERNEL, VAS_EBOOT_FILE_TYPE_NTLDR, VAS_EBOOT_FILE_TYPE_TRUECRYPT, VAS_EBOOT_FILE_TYPE_FREEDOS, VAS_EBOOT_FILE_TYPE_PXECHAINLOADER, VAS_EBOOT_FILE_TYPE_PCCHAINLOADER, VAS_EBOOT_FILE_TYPE_COREBOOT_CHAINLOADER, VAS_EBOOT_FILE_TYPE_EFI_CHAINLOADED_IMAGE, /* File holding signature. */ VAS_EBOOT_FILE_TYPE_SIGNATURE, /* File holding public key to verify signature once. */ VAS_EBOOT_FILE_TYPE_PUBLIC_KEY, /* File holding public key to add to trused keys. */ VAS_EBOOT_FILE_TYPE_PUBLIC_KEY_TRUST, /* File holding x509 certificiate to add to trusted keys. */ VAS_EBOOT_FILE_TYPE_CERTIFICATE_TRUST, /* File of which we intend to print a blocklist to the user. */ VAS_EBOOT_FILE_TYPE_PRINT_BLOCKLIST, /* File we intend to use for test loading or testing speed. */ VAS_EBOOT_FILE_TYPE_TESTLOAD, /* File we open only to get its size. E.g. in ls output. */ VAS_EBOOT_FILE_TYPE_GET_SIZE, /* Font file. */ VAS_EBOOT_FILE_TYPE_FONT, /* File holding encryption key for encrypted ZFS. */ VAS_EBOOT_FILE_TYPE_ZFS_ENCRYPTION_KEY, /* File holding the encryption key. */ VAS_EBOOT_FILE_TYPE_CRYPTODISK_ENCRYPTION_KEY, /* File holding the encryption metadata header */ VAS_EBOOT_FILE_TYPE_CRYPTODISK_DETACHED_HEADER, /* File we open n VasEBoot-fstest. */ VAS_EBOOT_FILE_TYPE_FSTEST, /* File we open n VasEBoot-mount. */ VAS_EBOOT_FILE_TYPE_MOUNT, /* File which we attempt to identify the type of. */ VAS_EBOOT_FILE_TYPE_FILE_ID, /* File holding ACPI table. */ VAS_EBOOT_FILE_TYPE_ACPI_TABLE, /* File holding Device Tree. */ VAS_EBOOT_FILE_TYPE_DEVICE_TREE_IMAGE, /* File we intend show to user. */ VAS_EBOOT_FILE_TYPE_CAT, VAS_EBOOT_FILE_TYPE_HEXCAT, /* One of pair of files we intend to compare. */ VAS_EBOOT_FILE_TYPE_CMP, /* List of hashes for hashsum. */ VAS_EBOOT_FILE_TYPE_HASHLIST, /* File hashed by hashsum. */ VAS_EBOOT_FILE_TYPE_TO_HASH, /* File holding certificiate/binary hash to add to db/dbx. */ VAS_EBOOT_FILE_TYPE_HASH_TRUST, /* Keyboard layout. */ VAS_EBOOT_FILE_TYPE_KEYBOARD_LAYOUT, /* Picture file. */ VAS_EBOOT_FILE_TYPE_PIXMAP, /* *.lst shipped by VAS_EBOOT. */ VAS_EBOOT_FILE_TYPE_VAS_EBOOT_MODULE_LIST, /* config file. */ VAS_EBOOT_FILE_TYPE_CONFIG, VAS_EBOOT_FILE_TYPE_THEME, VAS_EBOOT_FILE_TYPE_GETTEXT_CATALOG, VAS_EBOOT_FILE_TYPE_FS_SEARCH, VAS_EBOOT_FILE_TYPE_AUDIO, VAS_EBOOT_FILE_TYPE_VBE_DUMP, VAS_EBOOT_FILE_TYPE_LOADENV, VAS_EBOOT_FILE_TYPE_SAVEENV, VAS_EBOOT_FILE_TYPE_VERIFY_SIGNATURE, VAS_EBOOT_FILE_TYPE_MASK = 0xffff, /* --skip-sig is specified. */ VAS_EBOOT_FILE_TYPE_SKIP_SIGNATURE = 0x10000, VAS_EBOOT_FILE_TYPE_NO_DECOMPRESS = 0x20000 }; /* 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 { VAS_EBOOT_FILE_FILTER_VERIFY, VAS_EBOOT_FILE_FILTER_GZIO, VAS_EBOOT_FILE_FILTER_XZIO, VAS_EBOOT_FILE_FILTER_LZOPIO, VAS_EBOOT_FILE_FILTER_ZSTDIO, VAS_EBOOT_FILE_FILTER_MAX, VAS_EBOOT_FILE_FILTER_COMPRESSION_FIRST = VAS_EBOOT_FILE_FILTER_GZIO, VAS_EBOOT_FILE_FILTER_COMPRESSION_LAST = VAS_EBOOT_FILE_FILTER_ZSTDIO, } VasEBoot_file_filter_id_t; typedef VasEBoot_file_t (*VasEBoot_file_filter_t) (VasEBoot_file_t in, enum VasEBoot_file_type type); extern VasEBoot_file_filter_t EXPORT_VAR(VasEBoot_file_filters)[VAS_EBOOT_FILE_FILTER_MAX]; static inline void VasEBoot_file_filter_register (VasEBoot_file_filter_id_t id, VasEBoot_file_filter_t filter) { VasEBoot_file_filters[id] = filter; } static inline void VasEBoot_file_filter_unregister (VasEBoot_file_filter_id_t id) { VasEBoot_file_filters[id] = 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, enum VasEBoot_file_type type); 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 VAS_EBOOT_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, enum VasEBoot_file_type type, VasEBoot_off_t start, VasEBoot_off_t size); void VasEBoot_file_offset_close (VasEBoot_file_t file); #endif /* ! VAS_EBOOT_FILE_HEADER */