]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - GRUB2/MOD_SRC/grub-2.04/include/grub/file.h
Update help information
[Ventoy.git] / GRUB2 / MOD_SRC / grub-2.04 / include / grub / file.h
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2007 Free Software Foundation, Inc.
4 *
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.
9 *
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.
14 *
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/>.
17 */
18
19 #ifndef GRUB_FILE_HEADER
20 #define GRUB_FILE_HEADER 1
21
22 #include <grub/types.h>
23 #include <grub/err.h>
24 #include <grub/device.h>
25 #include <grub/fs.h>
26 #include <grub/disk.h>
27
28 enum grub_file_type
29 {
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,
37 /* Linux initrd. */
38 GRUB_FILE_TYPE_LINUX_INITRD,
39
40 /* Multiboot kernel. */
41 GRUB_FILE_TYPE_MULTIBOOT_KERNEL,
42 /* Multiboot module. */
43 GRUB_FILE_TYPE_MULTIBOOT_MODULE,
44
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,
49
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,
56
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,
64
65 GRUB_FILE_TYPE_PLAN9_KERNEL,
66
67 GRUB_FILE_TYPE_NTLDR,
68 GRUB_FILE_TYPE_TRUECRYPT,
69 GRUB_FILE_TYPE_FREEDOS,
70 GRUB_FILE_TYPE_PXECHAINLOADER,
71 GRUB_FILE_TYPE_PCCHAINLOADER,
72
73 GRUB_FILE_TYPE_COREBOOT_CHAINLOADER,
74
75 GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE,
76
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,
89 /* Font file. */
90 GRUB_FILE_TYPE_FONT,
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. */
96 GRUB_FILE_TYPE_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. */
104 GRUB_FILE_TYPE_CAT,
105 GRUB_FILE_TYPE_HEXCAT,
106 /* One of pair of files we intend to compare. */
107 GRUB_FILE_TYPE_CMP,
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,
114 /* Picture file. */
115 GRUB_FILE_TYPE_PIXMAP,
116 /* *.lst shipped by GRUB. */
117 GRUB_FILE_TYPE_GRUB_MODULE_LIST,
118 /* config file. */
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,
125
126 GRUB_FILE_TYPE_LOADENV,
127 GRUB_FILE_TYPE_SAVEENV,
128
129 GRUB_FILE_TYPE_VERIFY_SIGNATURE,
130
131 GRUB_FILE_TYPE_MASK = 0xffff,
132
133 /* --skip-sig is specified. */
134 GRUB_FILE_TYPE_SKIP_SIGNATURE = 0x10000,
135 GRUB_FILE_TYPE_NO_DECOMPRESS = 0x20000
136 };
137
138 /* File description. */
139 struct grub_file
140 {
141 /* File name. */
142 char *name;
143
144 /* The underlying device. */
145 grub_device_t device;
146
147 /* The underlying filesystem. */
148 grub_fs_t fs;
149
150 /* The current offset. */
151 grub_off_t offset;
152 grub_off_t progress_offset;
153
154 /* Progress info. */
155 grub_uint64_t last_progress_time;
156 grub_off_t last_progress_offset;
157 grub_uint64_t estimated_speed;
158
159 /* The file size. */
160 grub_off_t size;
161
162 /* If file is not easily seekable. Should be set by underlying layer. */
163 int not_easily_seekable;
164
165 /* Filesystem-specific data. */
166 void *data;
167
168 /* This is called when a sector is read. Used only for a disk device. */
169 grub_disk_read_hook_t read_hook;
170
171 /* Caller-specific data passed to the read hook. */
172 void *read_hook_data;
173 };
174 typedef struct grub_file *grub_file_t;
175
176 extern grub_disk_read_hook_t EXPORT_VAR(grub_file_progress_hook);
177
178 /* Filters with lower ID are executed first. */
179 typedef enum grub_file_filter_id
180 {
181 GRUB_FILE_FILTER_VERIFY,
182 GRUB_FILE_FILTER_GZIO,
183 GRUB_FILE_FILTER_XZIO,
184 GRUB_FILE_FILTER_LZOPIO,
185 GRUB_FILE_FILTER_MAX,
186 GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO,
187 GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO,
188 } grub_file_filter_id_t;
189
190 typedef grub_file_t (*grub_file_filter_t) (grub_file_t in, enum grub_file_type type);
191
192 extern grub_file_filter_t EXPORT_VAR(grub_file_filters)[GRUB_FILE_FILTER_MAX];
193
194 static inline void
195 grub_file_filter_register (grub_file_filter_id_t id, grub_file_filter_t filter)
196 {
197 grub_file_filters[id] = filter;
198 }
199
200 static inline void
201 grub_file_filter_unregister (grub_file_filter_id_t id)
202 {
203 grub_file_filters[id] = 0;
204 }
205
206 /* Get a device name from NAME. */
207 char *EXPORT_FUNC(grub_file_get_device_name) (const char *name);
208
209 int EXPORT_FUNC(ventoy_check_file_exist) (const char * fmt, ...);
210 grub_file_t EXPORT_FUNC(grub_file_open) (const char *name, enum grub_file_type type);
211 grub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf,
212 grub_size_t len);
213 grub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset);
214 grub_err_t EXPORT_FUNC(grub_file_close) (grub_file_t file);
215
216 /* Return value of grub_file_size() in case file size is unknown. */
217 #define GRUB_FILE_SIZE_UNKNOWN 0xffffffffffffffffULL
218
219 static inline grub_off_t
220 grub_file_size (const grub_file_t file)
221 {
222 return file->size;
223 }
224
225 static inline grub_off_t
226 grub_file_tell (const grub_file_t file)
227 {
228 return file->offset;
229 }
230
231 static inline int
232 grub_file_seekable (const grub_file_t file)
233 {
234 return !file->not_easily_seekable;
235 }
236
237 grub_file_t
238 grub_file_offset_open (grub_file_t parent, enum grub_file_type type,
239 grub_off_t start, grub_off_t size);
240 void
241 grub_file_offset_close (grub_file_t file);
242
243 #endif /* ! GRUB_FILE_HEADER */