]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
565344a22663fc128d156c329a07943605261827
[Ventoy.git] / GRUB2 / MOD_SRC / grub-2.04 / grub-core / ventoy / ventoy_def.h
1 /******************************************************************************
2 * ventoy_def.h
3 *
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #ifndef __VENTOY_DEF_H__
22 #define __VENTOY_DEF_H__
23
24 #define VTOY_MAX_SCRIPT_BUF (4 * 1024 * 1024)
25
26 #define VTOY_PART_BUF_LEN (128 * 1024)
27
28 #define VTOY_FILT_MIN_FILE_SIZE 32768
29
30 #define VTOY_SIZE_1GB 1073741824
31 #define VTOY_SIZE_1MB (1024 * 1024)
32 #define VTOY_SIZE_512KB (512 * 1024)
33 #define VTOY_SIZE_1KB 1024
34
35 #define JSON_SUCCESS 0
36 #define JSON_FAILED 1
37 #define JSON_NOT_FOUND 2
38
39 #define ulong unsigned long
40 #define ulonglong unsigned long long
41
42 #define vtoy_to_upper(c) (((char)(c) >= 'a' && (char)(c) <= 'z') ? ((char)(c) - 'a' + 'A') : (char)(c))
43
44 #define VENTOY_CMD_RETURN(err) grub_errno = (err); return (err)
45 #define VENTOY_FILE_TYPE (GRUB_FILE_TYPE_NO_DECOMPRESS | GRUB_FILE_TYPE_LINUX_INITRD)
46
47 #define ventoy_env_op1(op, a) grub_env_##op(a)
48 #define ventoy_env_op2(op, a, b) grub_env_##op((a), (b))
49
50 #define ventoy_get_env(key) ventoy_env_op1(get, key)
51 #define ventoy_set_env(key, val) ventoy_env_op2(set, key, val)
52
53 #define VTOY_WARNING "!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!"
54
55 #define VTOY_PLAT_I386_UEFI 0x49413332
56 #define VTOY_PLAT_ARM64_UEFI 0x41413634
57 #define VTOY_PLAT_X86_64_UEFI 0x55454649
58 #define VTOY_PLAT_X86_LEGACY 0x42494f53
59 #define VTOY_PLAT_MIPS_UEFI 0x4D495053
60
61 #define VTOY_COMM_CPIO "ventoy.cpio"
62 #if defined(__arm__) || defined(__aarch64__)
63 #define VTOY_ARCH_CPIO "ventoy_arm64.cpio"
64 #elif defined(__mips__)
65 #define VTOY_ARCH_CPIO "ventoy_mips64.cpio"
66 #else
67 #define VTOY_ARCH_CPIO "ventoy_x86.cpio"
68 #endif
69
70 #define VTOY_PWD_CORRUPTED(err) \
71 {\
72 grub_printf("\n\n Password corrupted, will reboot after 5 seconds.\n\n"); \
73 grub_refresh(); \
74 grub_sleep(5); \
75 grub_exit(); \
76 return (err);\
77 }
78
79 typedef struct ventoy_initrd_ctx
80 {
81 const char *path_prefix;
82 const char *dir_prefix;
83 }ventoy_initrd_ctx;
84
85 typedef struct cmd_para
86 {
87 const char *name;
88 grub_extcmd_func_t func;
89 grub_command_flags_t flags;
90 const struct grub_arg_option *parser;
91
92 const char *summary;
93 const char *description;
94
95 grub_extcmd_t cmd;
96 }cmd_para;
97
98 #define ventoy_align_2k(value) ((value + 2047) / 2048 * 2048)
99 #define ventoy_align(value, align) (((value) + ((align) - 1)) & (~((align) - 1)))
100
101 #pragma pack(1)
102 typedef struct cpio_newc_header
103 {
104 char c_magic[6];
105 char c_ino[8];
106 char c_mode[8];
107 char c_uid[8];
108 char c_gid[8];
109 char c_nlink[8];
110 char c_mtime[8];
111 char c_filesize[8];
112 char c_devmajor[8];
113 char c_devminor[8];
114 char c_rdevmajor[8];
115 char c_rdevminor[8];
116 char c_namesize[8];
117 char c_check[8];
118 }cpio_newc_header;
119 #pragma pack()
120
121
122 #define cmd_raw_name ctxt->extcmd->cmd->name
123 #define check_free(p, func) if (p) { func(p); p = NULL; }
124 #define grub_check_free(p) if (p) { grub_free(p); p = NULL; }
125
126 typedef int (*grub_char_check_func)(int c);
127 #define ventoy_is_decimal(str) ventoy_string_check(str, grub_isdigit)
128
129
130 #pragma pack(1)
131 typedef struct ventoy_patch_vhd
132 {
133 grub_uint8_t part_offset_or_guid[16];
134 grub_uint32_t reserved1;
135 grub_uint32_t part_type;
136 grub_uint8_t disk_signature_or_guid[16];
137 grub_uint8_t reserved2[16];
138 grub_uint8_t vhd_file_path[1];
139 }ventoy_patch_vhd;
140 #pragma pack()
141
142 // El Torito Boot Record Volume Descriptor
143 #pragma pack(1)
144 typedef struct eltorito_descriptor
145 {
146 grub_uint8_t type;
147 grub_uint8_t id[5];
148 grub_uint8_t version;
149 grub_uint8_t system_id[32];
150 grub_uint8_t reserved[32];
151 grub_uint32_t sector;
152 }eltorito_descriptor;
153
154 typedef struct ventoy_iso9660_override
155 {
156 grub_uint32_t first_sector;
157 grub_uint32_t first_sector_be;
158 grub_uint32_t size;
159 grub_uint32_t size_be;
160 }ventoy_iso9660_override;
161
162 typedef struct ventoy_udf_override
163 {
164 grub_uint32_t length;
165 grub_uint32_t position;
166 }ventoy_udf_override;
167
168 typedef struct ventoy_iso9660_vd
169 {
170 grub_uint8_t type;
171 grub_uint8_t id[5];
172 grub_uint8_t ver;
173 grub_uint8_t res;
174 char sys[32];
175 char vol[32];
176 grub_uint8_t res2[8];
177 grub_uint32_t space;
178 }ventoy_iso9660_vd;
179
180 #pragma pack()
181
182 #define img_type_iso 0
183 #define img_type_wim 1
184 #define img_type_efi 2
185 #define img_type_img 3
186 #define img_type_vhd 4
187 #define img_type_vtoy 5
188
189 typedef struct img_info
190 {
191 int pathlen;
192 char path[512];
193 char name[256];
194
195 const char *alias;
196 const char *class;
197 const char *menu_prefix;
198
199 int id;
200 int type;
201 int plugin_list_index;
202 grub_uint64_t size;
203 int select;
204 int unsupport;
205
206 void *parent;
207
208 struct img_info *next;
209 struct img_info *prev;
210 }img_info;
211
212 typedef struct img_iterator_node
213 {
214 struct img_iterator_node *next;
215 img_info **tail;
216 char dir[400];
217 int dirlen;
218 int level;
219 int isocnt;
220 int done;
221 int select;
222
223 int plugin_list_index;
224
225 struct img_iterator_node *parent;
226 struct img_iterator_node *firstchild;
227
228 void *firstiso;
229 }img_iterator_node;
230
231
232
233 typedef struct initrd_info
234 {
235 char name[256];
236
237 grub_uint64_t offset;
238 grub_uint64_t size;
239
240 grub_uint8_t iso_type; // 0: iso9660 1:udf
241 grub_uint32_t udf_start_block;
242
243 grub_uint64_t override_offset;
244 grub_uint32_t override_length;
245 char override_data[32];
246
247 struct initrd_info *next;
248 struct initrd_info *prev;
249 }initrd_info;
250
251 extern initrd_info *g_initrd_img_list;
252 extern initrd_info *g_initrd_img_tail;
253 extern int g_initrd_img_count;
254 extern int g_valid_initrd_count;
255
256 extern img_info *g_ventoy_img_list;
257 extern int g_ventoy_img_count;
258
259 extern grub_uint8_t *g_ventoy_cpio_buf;
260 extern grub_uint32_t g_ventoy_cpio_size;
261 extern cpio_newc_header *g_ventoy_initrd_head;
262 extern grub_uint8_t *g_ventoy_runtime_buf;
263
264 extern ventoy_guid g_ventoy_guid;
265
266 extern ventoy_img_chunk_list g_img_chunk_list;
267 extern ventoy_img_chunk_list g_wimiso_chunk_list;
268 extern char *g_wimiso_path;
269 extern char g_arch_mode_suffix[64];
270
271 extern int g_ventoy_debug;
272 void ventoy_debug(const char *fmt, ...);
273 #define debug(fmt, ...) if (g_ventoy_debug) ventoy_debug("[VTOY]: "fmt, __VA_ARGS__)
274
275 #define vtoy_ssprintf(buf, pos, fmt, ...) \
276 pos += grub_snprintf(buf + pos, VTOY_MAX_SCRIPT_BUF - pos, fmt, __VA_ARGS__)
277
278 #define FLAG_HEADER_RESERVED 0x00000001
279 #define FLAG_HEADER_COMPRESSION 0x00000002
280 #define FLAG_HEADER_READONLY 0x00000004
281 #define FLAG_HEADER_SPANNED 0x00000008
282 #define FLAG_HEADER_RESOURCE_ONLY 0x00000010
283 #define FLAG_HEADER_METADATA_ONLY 0x00000020
284 #define FLAG_HEADER_WRITE_IN_PROGRESS 0x00000040
285 #define FLAG_HEADER_RP_FIX 0x00000080 // reparse point fixup
286 #define FLAG_HEADER_COMPRESS_RESERVED 0x00010000
287 #define FLAG_HEADER_COMPRESS_XPRESS 0x00020000
288 #define FLAG_HEADER_COMPRESS_LZX 0x00040000
289 #define FLAG_HEADER_COMPRESS_LZMS 0x00080000
290
291 #define RESHDR_FLAG_FREE 0x01
292 #define RESHDR_FLAG_METADATA 0x02
293 #define RESHDR_FLAG_COMPRESSED 0x04
294 #define RESHDR_FLAG_SPANNED 0x08
295
296 #pragma pack(1)
297
298 /* A WIM resource header */
299 typedef struct wim_resource_header
300 {
301 grub_uint64_t size_in_wim:56; /* Compressed length */
302 grub_uint64_t flags:8; /* flags */
303 grub_uint64_t offset; /* Offset */
304 grub_uint64_t raw_size; /* Uncompressed length */
305 }wim_resource_header;
306
307 /* WIM resource header length mask */
308 #define WIM_RESHDR_ZLEN_MASK 0x00ffffffffffffffULL
309
310 /* WIM resource header flags */
311 typedef enum wim_resource_header_flags
312 {
313 WIM_RESHDR_METADATA = ( 0x02ULL << 56 ), /* Resource contains metadata */
314 WIM_RESHDR_COMPRESSED = ( 0x04ULL << 56 ), /* Resource is compressed */
315 WIM_RESHDR_PACKED_STREAMS = ( 0x10ULL << 56 ), /* Resource is compressed using packed streams */
316 }wim_resource_header_flags;
317
318 #define WIM_HEAD_SIGNATURE "MSWIM\0\0"
319
320 /* WIM header */
321 typedef struct wim_header
322 {
323 grub_uint8_t signature[8]; /* Signature */
324 grub_uint32_t header_len; /* Header length */
325 grub_uint32_t version; /* Verson */
326 grub_uint32_t flags; /* Flags */
327 grub_uint32_t chunk_len; /* Chunk length */
328 grub_uint8_t guid[16]; /* GUID */
329 grub_uint16_t part; /* Part number */
330 grub_uint16_t parts; /* Total number of parts */
331 grub_uint32_t images; /* number of images */
332 wim_resource_header lookup; /* Lookup table */
333 wim_resource_header xml; /* XML data */
334 wim_resource_header metadata; /* Boot metadata */
335 grub_uint32_t boot_index; /* Boot index */
336 wim_resource_header integrity; /* Integrity table */
337 grub_uint8_t reserved[60]; /* Reserved */
338 } wim_header;
339
340 /* WIM header flags */
341 typedef enum wim_header_flags
342 {
343 WIM_HDR_XPRESS = 0x00020000, /* WIM uses Xpress compresson */
344 WIM_HDR_LZX = 0x00040000, /* WIM uses LZX compression */
345 }wim_header_flags;
346
347 /* A WIM file hash */
348 typedef struct wim_hash
349 {
350 /* SHA-1 hash */
351 grub_uint8_t sha1[20];
352 }wim_hash;
353
354 /* A WIM lookup table entry */
355 typedef struct wim_lookup_entry
356 {
357 wim_resource_header resource; /* Resource header */
358 grub_uint16_t part; /* Part number */
359 grub_uint32_t refcnt; /* Reference count */
360 wim_hash hash; /* Hash */
361 }wim_lookup_entry;
362
363 /* WIM chunk length */
364 #define WIM_CHUNK_LEN 32768
365
366 /* A WIM chunk buffer */
367 typedef struct wim_chunk_buffer
368 {
369 grub_uint8_t data[WIM_CHUNK_LEN]; /*Data */
370 }wim_chunk_buffer;
371
372 /* Security data */
373 typedef struct wim_security_header
374 {
375 grub_uint32_t len; /* Length */
376 grub_uint32_t count; /* Number of entries */
377 }wim_security_header;
378
379 /* Directory entry */
380 typedef struct wim_directory_entry
381 {
382 grub_uint64_t len; /* Length */
383 grub_uint32_t attributes; /* Attributes */
384 grub_uint32_t security; /* Security ID */
385 grub_uint64_t subdir; /* Subdirectory offset */
386 grub_uint8_t reserved1[16]; /* Reserved */
387 grub_uint64_t created; /* Creation time */
388 grub_uint64_t accessed; /* Last access time */
389 grub_uint64_t written; /* Last written time */
390 wim_hash hash; /* Hash */
391 grub_uint8_t reserved2[12]; /* Reserved */
392 grub_uint16_t streams; /* Streams */
393 grub_uint16_t short_name_len; /* Short name length */
394 grub_uint16_t name_len; /* Name length */
395 }wim_directory_entry;
396
397 /** Normal file */
398 #define WIM_ATTR_NORMAL 0x00000080UL
399
400 /** No security information exists for this file */
401 #define WIM_NO_SECURITY 0xffffffffUL
402
403 #pragma pack()
404
405
406 typedef struct wim_tail
407 {
408 grub_uint32_t wim_raw_size;
409 grub_uint32_t wim_align_size;
410
411 grub_uint8_t iso_type;
412 grub_uint64_t file_offset;
413 grub_uint32_t udf_start_block;
414 grub_uint64_t fe_entry_size_offset;
415 grub_uint64_t override_offset;
416 grub_uint32_t override_len;
417 grub_uint8_t override_data[32];
418
419 wim_header wim_header;
420
421 wim_hash bin_hash;
422 grub_uint32_t jump_exe_len;
423 grub_uint8_t *jump_bin_data;
424 grub_uint32_t bin_raw_len;
425 grub_uint32_t bin_align_len;
426
427 grub_uint8_t *new_meta_data;
428 grub_uint32_t new_meta_len;
429 grub_uint32_t new_meta_align_len;
430
431 grub_uint8_t *new_lookup_data;
432 grub_uint32_t new_lookup_len;
433 grub_uint32_t new_lookup_align_len;
434 }wim_tail;
435
436 typedef struct wim_patch
437 {
438 int pathlen;
439 char path[256];
440
441 wim_hash old_hash;
442 wim_tail wim_data;
443 wim_lookup_entry *replace_look;
444
445 int valid;
446
447 struct wim_patch *next;
448 }wim_patch;
449
450
451 typedef enum _JSON_TYPE
452 {
453 JSON_TYPE_NUMBER = 0,
454 JSON_TYPE_STRING,
455 JSON_TYPE_BOOL,
456 JSON_TYPE_ARRAY,
457 JSON_TYPE_OBJECT,
458 JSON_TYPE_NULL,
459 JSON_TYPE_BUTT
460 }JSON_TYPE;
461
462
463 typedef struct _VTOY_JSON
464 {
465 struct _VTOY_JSON *pstPrev;
466 struct _VTOY_JSON *pstNext;
467 struct _VTOY_JSON *pstChild;
468
469 JSON_TYPE enDataType;
470 union
471 {
472 char *pcStrVal;
473 int iNumVal;
474 grub_uint64_t lValue;
475 }unData;
476
477 char *pcName;
478 }VTOY_JSON;
479
480 typedef struct _JSON_PARSE
481 {
482 char *pcKey;
483 void *pDataBuf;
484 grub_uint32_t uiBufSize;
485 }JSON_PARSE;
486
487 #define JSON_NEW_ITEM(pstJson, ret) \
488 { \
489 (pstJson) = (VTOY_JSON *)grub_zalloc(sizeof(VTOY_JSON)); \
490 if (NULL == (pstJson)) \
491 { \
492 json_debug("Failed to alloc memory for json.\n"); \
493 return (ret); \
494 } \
495 }
496
497 typedef int (*ventoy_plugin_entry_pf)(VTOY_JSON *json, const char *isodisk);
498 typedef int (*ventoy_plugin_check_pf)(VTOY_JSON *json, const char *isodisk);
499
500 typedef struct plugin_entry
501 {
502 const char *key;
503 ventoy_plugin_entry_pf entryfunc;
504 ventoy_plugin_check_pf checkfunc;
505 }plugin_entry;
506
507
508 void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param);
509 grub_err_t ventoy_cmd_isolinux_initrd_collect(grub_extcmd_context_t ctxt, int argc, char **args);
510 grub_err_t ventoy_cmd_grub_initrd_collect(grub_extcmd_context_t ctxt, int argc, char **args);
511 grub_err_t ventoy_cmd_specify_initrd_file(grub_extcmd_context_t ctxt, int argc, char **args);
512 grub_err_t ventoy_cmd_dump_initrd_list(grub_extcmd_context_t ctxt, int argc, char **args);
513 grub_err_t ventoy_cmd_clear_initrd_list(grub_extcmd_context_t ctxt, int argc, char **args);
514 grub_uint32_t ventoy_get_iso_boot_catlog(grub_file_t file);
515 int ventoy_has_efi_eltorito(grub_file_t file, grub_uint32_t sector);
516 grub_err_t ventoy_cmd_linux_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
517 grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc, char **args);
518 grub_err_t ventoy_cmd_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
519 grub_err_t ventoy_cmd_valid_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
520 grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args);
521 grub_err_t ventoy_cmd_skip_svd(grub_extcmd_context_t ctxt, int argc, char **args);
522 grub_err_t ventoy_cmd_cpio_busybox_64(grub_extcmd_context_t ctxt, int argc, char **args);
523 grub_err_t ventoy_cmd_trailer_cpio(grub_extcmd_context_t ctxt, int argc, char **args);
524 int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name);
525 grub_file_t ventoy_grub_file_open(enum grub_file_type type, const char *fmt, ...);
526 grub_uint64_t ventoy_grub_get_file_size(const char *fmt, ...);
527 int ventoy_is_file_exist(const char *fmt, ...);
528 int ventoy_is_dir_exist(const char *fmt, ...);
529 int ventoy_fill_data(grub_uint32_t buflen, char *buffer);
530 grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **args);
531 grub_err_t ventoy_cmd_wimdows_reset(grub_extcmd_context_t ctxt, int argc, char **args);
532 grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
533 grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
534 grub_err_t ventoy_cmd_wim_check_bootable(grub_extcmd_context_t ctxt, int argc, char **args);
535 grub_err_t ventoy_cmd_dump_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args);
536
537 VTOY_JSON *vtoy_json_find_item
538 (
539 VTOY_JSON *pstJson,
540 JSON_TYPE enDataType,
541 const char *szKey
542 );
543 int vtoy_json_parse_value
544 (
545 char *pcNewStart,
546 char *pcRawStart,
547 VTOY_JSON *pstJson,
548 const char *pcData,
549 const char **ppcEnd
550 );
551 VTOY_JSON * vtoy_json_create(void);
552 int vtoy_json_parse(VTOY_JSON *pstJson, const char *szJsonData);
553
554 int vtoy_json_scan_parse
555 (
556 const VTOY_JSON *pstJson,
557 grub_uint32_t uiParseNum,
558 JSON_PARSE *pstJsonParse
559 );
560
561 int vtoy_json_scan_array
562 (
563 VTOY_JSON *pstJson,
564 const char *szKey,
565 VTOY_JSON **ppstArrayItem
566 );
567
568 int vtoy_json_scan_array_ex
569 (
570 VTOY_JSON *pstJson,
571 const char *szKey,
572 VTOY_JSON **ppstArrayItem
573 );
574 int vtoy_json_scan_object
575 (
576 VTOY_JSON *pstJson,
577 const char *szKey,
578 VTOY_JSON **ppstObjectItem
579 );
580 int vtoy_json_get_int
581 (
582 VTOY_JSON *pstJson,
583 const char *szKey,
584 int *piValue
585 );
586 int vtoy_json_get_uint
587 (
588 VTOY_JSON *pstJson,
589 const char *szKey,
590 grub_uint32_t *puiValue
591 );
592 int vtoy_json_get_uint64
593 (
594 VTOY_JSON *pstJson,
595 const char *szKey,
596 grub_uint64_t *pui64Value
597 );
598 int vtoy_json_get_bool
599 (
600 VTOY_JSON *pstJson,
601 const char *szKey,
602 grub_uint8_t *pbValue
603 );
604 int vtoy_json_get_string
605 (
606 VTOY_JSON *pstJson,
607 const char *szKey,
608 grub_uint32_t uiBufLen,
609 char *pcBuf
610 );
611 const char * vtoy_json_get_string_ex(VTOY_JSON *pstJson, const char *szKey);
612 int vtoy_json_destroy(VTOY_JSON *pstJson);
613
614
615 grub_uint32_t CalculateCrc32
616 (
617 const void *Buffer,
618 grub_uint32_t Length,
619 grub_uint32_t InitValue
620 );
621
622 static inline int ventoy_isspace (int c)
623 {
624 return (c == '\n' || c == '\r' || c == ' ' || c == '\t');
625 }
626
627 static inline int ventoy_is_word_end(int c)
628 {
629 return (c == 0 || c == ',' || ventoy_isspace(c));
630 }
631
632 #pragma pack(1)
633 typedef struct ventoy_part_table
634 {
635 grub_uint8_t Active; // 0x00 0x80
636
637 grub_uint8_t StartHead;
638 grub_uint16_t StartSector : 6;
639 grub_uint16_t StartCylinder : 10;
640
641 grub_uint8_t FsFlag;
642
643 grub_uint8_t EndHead;
644 grub_uint16_t EndSector : 6;
645 grub_uint16_t EndCylinder : 10;
646
647 grub_uint32_t StartSectorId;
648 grub_uint32_t SectorCount;
649 }ventoy_part_table;
650
651 typedef struct ventoy_mbr_head
652 {
653 grub_uint8_t BootCode[446];
654 ventoy_part_table PartTbl[4];
655 grub_uint8_t Byte55;
656 grub_uint8_t ByteAA;
657 }ventoy_mbr_head;
658
659 typedef struct ventoy_gpt_head
660 {
661 char Signature[8]; /* EFI PART */
662 grub_uint8_t Version[4];
663 grub_uint32_t Length;
664 grub_uint32_t Crc;
665 grub_uint8_t Reserved1[4];
666 grub_uint64_t EfiStartLBA;
667 grub_uint64_t EfiBackupLBA;
668 grub_uint64_t PartAreaStartLBA;
669 grub_uint64_t PartAreaEndLBA;
670 grub_uint8_t DiskGuid[16];
671 grub_uint64_t PartTblStartLBA;
672 grub_uint32_t PartTblTotNum;
673 grub_uint32_t PartTblEntryLen;
674 grub_uint32_t PartTblCrc;
675 grub_uint8_t Reserved2[420];
676 }ventoy_gpt_head;
677
678 typedef struct ventoy_gpt_part_tbl
679 {
680 grub_uint8_t PartType[16];
681 grub_uint8_t PartGuid[16];
682 grub_uint64_t StartLBA;
683 grub_uint64_t LastLBA;
684 grub_uint64_t Attr;
685 grub_uint16_t Name[36];
686 }ventoy_gpt_part_tbl;
687
688 typedef struct ventoy_gpt_info
689 {
690 ventoy_mbr_head MBR;
691 ventoy_gpt_head Head;
692 ventoy_gpt_part_tbl PartTbl[128];
693 }ventoy_gpt_info;
694
695 typedef struct vhd_footer_t
696 {
697 char cookie[8]; // Cookie
698 grub_uint32_t features; // Features
699 grub_uint32_t ffversion; // File format version
700 grub_uint32_t dataoffset; // Data offset
701 grub_uint32_t timestamp; // Timestamp
702 grub_uint32_t creatorapp; // Creator application
703 grub_uint32_t creatorver; // Creator version
704 grub_uint32_t creatorhos; // Creator host OS
705 grub_uint32_t origsize; // Original size
706 grub_uint32_t currsize; // Current size
707 grub_uint32_t diskgeom; // Disk geometry
708 grub_uint32_t disktype; // Disk type
709 grub_uint32_t checksum; // Checksum
710 grub_uint8_t uniqueid[16]; // Unique ID
711 grub_uint8_t savedst; // Saved state
712 }vhd_footer_t;
713
714 #define VDI_IMAGE_FILE_INFO "<<< Oracle VM VirtualBox Disk Image >>>\n"
715
716 /** Image signature. */
717 #define VDI_IMAGE_SIGNATURE (0xbeda107f)
718
719 typedef struct VDIPREHEADER
720 {
721 /** Just text info about image type, for eyes only. */
722 char szFileInfo[64];
723 /** The image signature (VDI_IMAGE_SIGNATURE). */
724 grub_uint32_t u32Signature;
725 /** The image version (VDI_IMAGE_VERSION). */
726 grub_uint32_t u32Version;
727 } VDIPREHEADER, *PVDIPREHEADER;
728
729 #pragma pack()
730
731 typedef struct ventoy_video_mode
732 {
733 grub_uint32_t width;
734 grub_uint32_t height;
735 grub_uint32_t bpp;
736 }ventoy_video_mode;
737
738
739
740 typedef struct file_fullpath
741 {
742 char path[256];
743 }file_fullpath;
744
745 typedef struct install_template
746 {
747 int pathlen;
748 char isopath[256];
749
750 int autosel;
751 int cursel;
752 int templatenum;
753 file_fullpath *templatepath;
754
755 struct install_template *next;
756 }install_template;
757
758 typedef struct dudfile
759 {
760 int size;
761 char *buf;
762 }dudfile;
763
764 typedef struct dud
765 {
766 int pathlen;
767 char isopath[256];
768
769 int dudnum;
770 file_fullpath *dudpath;
771 dudfile *files;
772
773 struct dud *next;
774 }dud;
775
776 typedef struct persistence_config
777 {
778 int pathlen;
779 char isopath[256];
780
781 int autosel;
782 int cursel;
783 int backendnum;
784 file_fullpath *backendpath;
785
786 struct persistence_config *next;
787 }persistence_config;
788
789 #define vtoy_alias_image_file 0
790 #define vtoy_alias_directory 1
791
792 typedef struct menu_alias
793 {
794 int type;
795 int pathlen;
796 char isopath[256];
797 char alias[256];
798
799 struct menu_alias *next;
800 }menu_alias;
801
802 #define vtoy_class_image_file 0
803 #define vtoy_class_directory 1
804
805 typedef struct menu_class
806 {
807 int type;
808 int patlen;
809 char pattern[256];
810 char class[64];
811
812 struct menu_class *next;
813 }menu_class;
814
815 #define vtoy_custom_boot_image_file 0
816 #define vtoy_custom_boot_directory 1
817
818 typedef struct custom_boot
819 {
820 int type;
821 int pathlen;
822 char path[256];
823 char cfg[256];
824
825 struct custom_boot *next;
826 }custom_boot;
827
828 #define vtoy_max_replace_file_size (2 * 1024 * 1024)
829 typedef struct conf_replace
830 {
831 int pathlen;
832 char isopath[256];
833 char orgconf[256];
834 char newconf[256];
835
836 struct conf_replace *next;
837 }conf_replace;
838
839 typedef struct injection_config
840 {
841 int pathlen;
842 char isopath[256];
843 char archive[256];
844
845 struct injection_config *next;
846 }injection_config;
847
848 typedef struct auto_memdisk
849 {
850 int pathlen;
851 char isopath[256];
852
853 struct auto_memdisk *next;
854 }auto_memdisk;
855
856 typedef struct image_list
857 {
858 int pathlen;
859 char isopath[256];
860
861 struct image_list *next;
862 }image_list;
863
864 #define VTOY_PASSWORD_NONE 0
865 #define VTOY_PASSWORD_TXT 1
866 #define VTOY_PASSWORD_MD5 2
867 #define VTOY_PASSWORD_SALT_MD5 3
868
869 typedef struct vtoy_password
870 {
871 int type;
872 char text[128];
873 char salt[64];
874 grub_uint8_t md5[16];
875 }vtoy_password;
876
877 typedef struct menu_password
878 {
879 int pathlen;
880 char isopath[256];
881
882 vtoy_password password;
883
884 struct menu_password *next;
885 }menu_password;
886
887 extern int g_ventoy_menu_esc;
888 extern int g_ventoy_suppress_esc;
889 extern int g_ventoy_last_entry;
890 extern int g_ventoy_memdisk_mode;
891 extern int g_ventoy_iso_raw;
892 extern int g_ventoy_iso_uefi_drv;
893 extern int g_ventoy_case_insensitive;
894 extern grub_uint8_t g_ventoy_chain_type;
895 extern int g_vhdboot_enable;
896
897 #define VENTOY_IMG_WHITE_LIST 1
898 #define VENTOY_IMG_BLACK_LIST 2
899 extern int g_plugin_image_list;
900
901 extern ventoy_gpt_info *g_ventoy_part_info;
902 extern grub_uint64_t g_conf_replace_offset;
903 extern grub_uint64_t g_svd_replace_offset;
904 extern conf_replace *g_conf_replace_node;
905 extern grub_uint8_t *g_conf_replace_new_buf;
906 extern int g_conf_replace_new_len;
907 extern int g_conf_replace_new_len_align;
908 extern grub_uint64_t g_ventoy_disk_size;
909
910 #define ventoy_unix_fill_virt(new_data, new_len) \
911 { \
912 data_secs = (new_len + 2047) / 2048; \
913 cur->mem_sector_start = sector; \
914 cur->mem_sector_end = cur->mem_sector_start + data_secs; \
915 cur->mem_sector_offset = offset; \
916 cur->remap_sector_start = 0; \
917 cur->remap_sector_end = 0; \
918 cur->org_sector_start = 0; \
919 grub_memcpy(override + offset, new_data, new_len); \
920 cur++; \
921 sector += data_secs; \
922 offset += new_len; \
923 chain->virt_img_size_in_bytes += data_secs * 2048; \
924 }
925
926 char * ventoy_get_line(char *start);
927 int ventoy_cmp_img(img_info *img1, img_info *img2);
928 void ventoy_swap_img(img_info *img1, img_info *img2);
929 char * ventoy_plugin_get_cur_install_template(const char *isopath);
930 install_template * ventoy_plugin_find_install_template(const char *isopath);
931 persistence_config * ventoy_plugin_find_persistent(const char *isopath);
932 void ventoy_plugin_dump_injection(void);
933 void ventoy_plugin_dump_auto_install(void);
934 int ventoy_fill_windows_rtdata(void *buf, char *isopath);
935 int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, ventoy_img_chunk_list *chunk_list);
936 const char * ventoy_plugin_get_injection(const char *isopath);
937 const char * ventoy_plugin_get_menu_alias(int type, const char *isopath);
938 const char * ventoy_plugin_get_menu_class(int type, const char *name);
939 int ventoy_plugin_check_memdisk(const char *isopath);
940 int ventoy_plugin_get_image_list_index(int type, const char *name);
941 conf_replace * ventoy_plugin_find_conf_replace(const char *iso);
942 dud * ventoy_plugin_find_dud(const char *iso);
943 int ventoy_plugin_load_dud(dud *node, const char *isopart);
944 int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
945 int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
946 void ventoy_plugin_dump_persistence(void);
947 grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args);
948 grub_err_t ventoy_cmd_check_password(grub_extcmd_context_t ctxt, int argc, char **args);
949 grub_err_t ventoy_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt, int argc, char **args);
950 grub_err_t ventoy_cmd_collect_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args);
951 grub_err_t ventoy_cmd_wim_patch_count(grub_extcmd_context_t ctxt, int argc, char **args);
952 grub_err_t ventoy_cmd_locate_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args);
953 grub_err_t ventoy_cmd_unix_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
954 int ventoy_get_disk_guid(const char *filename, grub_uint8_t *guid, grub_uint8_t *signature);
955 grub_err_t ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **args);
956 grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, char **args);
957 grub_err_t ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char **args);
958 grub_err_t ventoy_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt, int argc, char **args);
959 grub_err_t ventoy_cmd_unix_gzip_newko(grub_extcmd_context_t ctxt, int argc, char **args);
960 grub_err_t ventoy_cmd_unix_freebsd_ver(grub_extcmd_context_t ctxt, int argc, char **args);
961 grub_err_t ventoy_cmd_parse_freenas_ver(grub_extcmd_context_t ctxt, int argc, char **args);
962 int ventoy_check_device_result(int ret);
963 int ventoy_check_device(grub_device_t dev);
964 void ventoy_debug_dump_guid(const char *prefix, grub_uint8_t *guid);
965 grub_err_t ventoy_cmd_load_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args);
966 grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args);
967 grub_err_t ventoy_cmd_raw_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
968 grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char **args);
969 int ventoy_check_password(const vtoy_password *pwd, int retry);
970 int ventoy_gzip_compress(void *mem_in, int mem_in_len, void *mem_out, int mem_out_len);
971 grub_uint64_t ventoy_get_part1_size(ventoy_gpt_info *gpt);
972 int ventoy_plugin_add_custom_boot(const char *vcfgpath);
973 const char * ventoy_plugin_get_custom_boot(const char *isopath);
974 grub_err_t ventoy_cmd_dump_custom_boot(grub_extcmd_context_t ctxt, int argc, char **args);
975
976 #endif /* __VENTOY_DEF_H__ */
977