]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - GRUB2/MOD_SRC/grub-2.04/include/grub/file.h
1.1.07 release
[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 GRUB_FILE_TYPE_NO_VLNK = 0x40000,
137 };
138
139 /* File description. */
140 struct grub_file
141 {
142 /* File name. */
143 char *name;
144
145 int vlnk;
146
147 /* The underlying device. */
148 grub_device_t device;
149
150 /* The underlying filesystem. */
151 grub_fs_t fs;
152
153 /* The current offset. */
154 grub_off_t offset;
155 grub_off_t progress_offset;
156
157 /* Progress info. */
158 grub_uint64_t last_progress_time;
159 grub_off_t last_progress_offset;
160 grub_uint64_t estimated_speed;
161
162 /* The file size. */
163 grub_off_t size;
164
165 /* If file is not easily seekable. Should be set by underlying layer. */
166 int not_easily_seekable;
167
168 /* Filesystem-specific data. */
169 void *data;
170
171 /* This is called when a sector is read. Used only for a disk device. */
172 grub_disk_read_hook_t read_hook;
173
174 /* Caller-specific data passed to the read hook. */
175 void *read_hook_data;
176 };
177 typedef struct grub_file *grub_file_t;
178
179 extern grub_disk_read_hook_t EXPORT_VAR(grub_file_progress_hook);
180
181 /* Filters with lower ID are executed first. */
182 typedef enum grub_file_filter_id
183 {
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;
192
193 typedef grub_file_t (*grub_file_filter_t) (grub_file_t in, enum grub_file_type type);
194
195 extern grub_file_filter_t EXPORT_VAR(grub_file_filters)[GRUB_FILE_FILTER_MAX];
196
197 static inline void
198 grub_file_filter_register (grub_file_filter_id_t id, grub_file_filter_t filter)
199 {
200 grub_file_filters[id] = filter;
201 }
202
203 static inline void
204 grub_file_filter_unregister (grub_file_filter_id_t id)
205 {
206 grub_file_filters[id] = 0;
207 }
208
209 /* Get a device name from NAME. */
210 char *EXPORT_FUNC(grub_file_get_device_name) (const char *name);
211
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,
215 grub_size_t len);
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);
218
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);
223
224 /* Return value of grub_file_size() in case file size is unknown. */
225 #define GRUB_FILE_SIZE_UNKNOWN 0xffffffffffffffffULL
226
227 static inline grub_off_t
228 grub_file_size (const grub_file_t file)
229 {
230 return file->size;
231 }
232
233 static inline grub_off_t
234 grub_file_tell (const grub_file_t file)
235 {
236 return file->offset;
237 }
238
239 static inline int
240 grub_file_seekable (const grub_file_t file)
241 {
242 return !file->not_easily_seekable;
243 }
244
245 grub_file_t
246 grub_file_offset_open (grub_file_t parent, enum grub_file_type type,
247 grub_off_t start, grub_off_t size);
248 void
249 grub_file_offset_close (grub_file_t file);
250
251 #endif /* ! GRUB_FILE_HEADER */