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