2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2007 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef GRUB_FILE_HEADER
20 #define GRUB_FILE_HEADER 1
22 #include <grub/types.h>
24 #include <grub/device.h>
26 #include <grub/disk.h>
30 GRUB_FILE_TYPE_NONE
= 0,
31 /* GRUB module to be loaded. */
32 GRUB_FILE_TYPE_GRUB_MODULE
,
33 /* Loopback file to be represented as disk. */
34 GRUB_FILE_TYPE_LOOPBACK
,
35 /* Linux kernel to be loaded. */
36 GRUB_FILE_TYPE_LINUX_KERNEL
,
38 GRUB_FILE_TYPE_LINUX_INITRD
,
40 /* Multiboot kernel. */
41 GRUB_FILE_TYPE_MULTIBOOT_KERNEL
,
42 /* Multiboot module. */
43 GRUB_FILE_TYPE_MULTIBOOT_MODULE
,
45 /* Xen hypervisor - used on ARM only. */
46 GRUB_FILE_TYPE_XEN_HYPERVISOR
,
47 /* Xen module - used on ARM only. */
48 GRUB_FILE_TYPE_XEN_MODULE
,
50 GRUB_FILE_TYPE_BSD_KERNEL
,
51 GRUB_FILE_TYPE_FREEBSD_ENV
,
52 GRUB_FILE_TYPE_FREEBSD_MODULE
,
53 GRUB_FILE_TYPE_FREEBSD_MODULE_ELF
,
54 GRUB_FILE_TYPE_NETBSD_MODULE
,
55 GRUB_FILE_TYPE_OPENBSD_RAMDISK
,
57 GRUB_FILE_TYPE_XNU_INFO_PLIST
,
58 GRUB_FILE_TYPE_XNU_MKEXT
,
59 GRUB_FILE_TYPE_XNU_KEXT
,
60 GRUB_FILE_TYPE_XNU_KERNEL
,
61 GRUB_FILE_TYPE_XNU_RAMDISK
,
62 GRUB_FILE_TYPE_XNU_HIBERNATE_IMAGE
,
63 GRUB_FILE_XNU_DEVPROP
,
65 GRUB_FILE_TYPE_PLAN9_KERNEL
,
68 GRUB_FILE_TYPE_TRUECRYPT
,
69 GRUB_FILE_TYPE_FREEDOS
,
70 GRUB_FILE_TYPE_PXECHAINLOADER
,
71 GRUB_FILE_TYPE_PCCHAINLOADER
,
73 GRUB_FILE_TYPE_COREBOOT_CHAINLOADER
,
75 GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE
,
77 /* File holding signature. */
78 GRUB_FILE_TYPE_SIGNATURE
,
79 /* File holding public key to verify signature once. */
80 GRUB_FILE_TYPE_PUBLIC_KEY
,
81 /* File holding public key to add to trused keys. */
82 GRUB_FILE_TYPE_PUBLIC_KEY_TRUST
,
83 /* File of which we intend to print a blocklist to the user. */
84 GRUB_FILE_TYPE_PRINT_BLOCKLIST
,
85 /* File we intend to use for test loading or testing speed. */
86 GRUB_FILE_TYPE_TESTLOAD
,
87 /* File we open only to get its size. E.g. in ls output. */
88 GRUB_FILE_TYPE_GET_SIZE
,
91 /* File holding encryption key for encrypted ZFS. */
92 GRUB_FILE_TYPE_ZFS_ENCRYPTION_KEY
,
93 /* File we open n grub-fstest. */
94 GRUB_FILE_TYPE_FSTEST
,
95 /* File we open n grub-mount. */
97 /* File which we attempt to identify the type of. */
98 GRUB_FILE_TYPE_FILE_ID
,
99 /* File holding ACPI table. */
100 GRUB_FILE_TYPE_ACPI_TABLE
,
101 /* File holding Device Tree. */
102 GRUB_FILE_TYPE_DEVICE_TREE_IMAGE
,
103 /* File we intend show to user. */
105 GRUB_FILE_TYPE_HEXCAT
,
106 /* One of pair of files we intend to compare. */
108 /* List of hashes for hashsum. */
109 GRUB_FILE_TYPE_HASHLIST
,
110 /* File hashed by hashsum. */
111 GRUB_FILE_TYPE_TO_HASH
,
112 /* Keyboard layout. */
113 GRUB_FILE_TYPE_KEYBOARD_LAYOUT
,
115 GRUB_FILE_TYPE_PIXMAP
,
116 /* *.lst shipped by GRUB. */
117 GRUB_FILE_TYPE_GRUB_MODULE_LIST
,
119 GRUB_FILE_TYPE_CONFIG
,
120 GRUB_FILE_TYPE_THEME
,
121 GRUB_FILE_TYPE_GETTEXT_CATALOG
,
122 GRUB_FILE_TYPE_FS_SEARCH
,
123 GRUB_FILE_TYPE_AUDIO
,
124 GRUB_FILE_TYPE_VBE_DUMP
,
126 GRUB_FILE_TYPE_LOADENV
,
127 GRUB_FILE_TYPE_SAVEENV
,
129 GRUB_FILE_TYPE_VERIFY_SIGNATURE
,
131 GRUB_FILE_TYPE_MASK
= 0xffff,
133 /* --skip-sig is specified. */
134 GRUB_FILE_TYPE_SKIP_SIGNATURE
= 0x10000,
135 GRUB_FILE_TYPE_NO_DECOMPRESS
= 0x20000,
136 GRUB_FILE_TYPE_NO_VLNK
= 0x40000,
139 /* File description. */
147 /* The underlying device. */
148 grub_device_t device
;
150 /* The underlying filesystem. */
153 /* The current offset. */
155 grub_off_t progress_offset
;
158 grub_uint64_t last_progress_time
;
159 grub_off_t last_progress_offset
;
160 grub_uint64_t estimated_speed
;
165 /* If file is not easily seekable. Should be set by underlying layer. */
166 int not_easily_seekable
;
168 /* Filesystem-specific data. */
171 /* This is called when a sector is read. Used only for a disk device. */
172 grub_disk_read_hook_t read_hook
;
174 /* Caller-specific data passed to the read hook. */
175 void *read_hook_data
;
177 typedef struct grub_file
*grub_file_t
;
179 extern grub_disk_read_hook_t
EXPORT_VAR(grub_file_progress_hook
);
181 /* Filters with lower ID are executed first. */
182 typedef enum grub_file_filter_id
184 GRUB_FILE_FILTER_VERIFY
,
185 GRUB_FILE_FILTER_GZIO
,
186 GRUB_FILE_FILTER_XZIO
,
187 GRUB_FILE_FILTER_LZOPIO
,
188 GRUB_FILE_FILTER_MAX
,
189 GRUB_FILE_FILTER_COMPRESSION_FIRST
= GRUB_FILE_FILTER_GZIO
,
190 GRUB_FILE_FILTER_COMPRESSION_LAST
= GRUB_FILE_FILTER_LZOPIO
,
191 } grub_file_filter_id_t
;
193 typedef grub_file_t (*grub_file_filter_t
) (grub_file_t in
, enum grub_file_type type
);
195 extern grub_file_filter_t
EXPORT_VAR(grub_file_filters
)[GRUB_FILE_FILTER_MAX
];
198 grub_file_filter_register (grub_file_filter_id_t id
, grub_file_filter_t filter
)
200 grub_file_filters
[id
] = filter
;
204 grub_file_filter_unregister (grub_file_filter_id_t id
)
206 grub_file_filters
[id
] = 0;
209 /* Get a device name from NAME. */
210 char *EXPORT_FUNC(grub_file_get_device_name
) (const char *name
);
212 int EXPORT_FUNC(ventoy_check_file_exist
) (const char * fmt
, ...);
213 grub_file_t
EXPORT_FUNC(grub_file_open
) (const char *name
, enum grub_file_type type
);
214 grub_ssize_t
EXPORT_FUNC(grub_file_read
) (grub_file_t file
, void *buf
,
216 grub_off_t
EXPORT_FUNC(grub_file_seek
) (grub_file_t file
, grub_off_t offset
);
217 grub_err_t
EXPORT_FUNC(grub_file_close
) (grub_file_t file
);
219 int EXPORT_FUNC(grub_file_is_vlnk_suffix
)(const char *name
, int len
);
220 int EXPORT_FUNC(grub_file_add_vlnk
)(const char *src
, const char *dst
);
221 int EXPORT_FUNC(grub_file_vtoy_vlnk
)(const char *src
, const char *dst
);
222 const char * EXPORT_FUNC(grub_file_get_vlnk
)(const char *name
, int *vlnk
);
224 /* Return value of grub_file_size() in case file size is unknown. */
225 #define GRUB_FILE_SIZE_UNKNOWN 0xffffffffffffffffULL
227 static inline grub_off_t
228 grub_file_size (const grub_file_t file
)
233 static inline grub_off_t
234 grub_file_tell (const grub_file_t file
)
240 grub_file_seekable (const grub_file_t file
)
242 return !file
->not_easily_seekable
;
246 grub_file_offset_open (grub_file_t parent
, enum grub_file_type type
,
247 grub_off_t start
, grub_off_t size
);
249 grub_file_offset_close (grub_file_t file
);
251 #endif /* ! GRUB_FILE_HEADER */