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