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