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