1 /******************************************************************************
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
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.
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.
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/>.
21 #ifndef __VENTOY_DEF_H__
22 #define __VENTOY_DEF_H__
24 #define VTOY_MAX_DIR_DEPTH 32
26 #define VTOY_MAX_SCRIPT_BUF (4 * 1024 * 1024)
28 #define VTOY_PART_BUF_LEN (128 * 1024)
30 #define VTOY_FILT_MIN_FILE_SIZE 32768
32 #define VTOY_LINUX_SYSTEMD_MENU_MAX_BUF 16384
34 #define VTOY_SIZE_1GB 1073741824
35 #define VTOY_SIZE_1MB (1024 * 1024)
36 #define VTOY_SIZE_2MB (2 * 1024 * 1024)
37 #define VTOY_SIZE_4MB (4 * 1024 * 1024)
38 #define VTOY_SIZE_512KB (512 * 1024)
39 #define VTOY_SIZE_1KB 1024
40 #define VTOY_SIZE_32KB (32 * 1024)
41 #define VTOY_SIZE_128KB (128 * 1024)
43 #define JSON_SUCCESS 0
45 #define JSON_NOT_FOUND 2
47 #define WINDATA_FLAG_TEMPLATE 1
49 #define ulong unsigned long
50 #define ulonglong unsigned long long
52 #define vtoy_to_upper(c) (((char)(c) >= 'a' && (char)(c) <= 'z') ? ((char)(c) - 'a' + 'A') : (char)(c))
54 #define VENTOY_CMD_RETURN(err) grub_errno = (err); return (err)
55 #define VENTOY_FILE_TYPE (GRUB_FILE_TYPE_NO_DECOMPRESS | GRUB_FILE_TYPE_LINUX_INITRD)
57 #define ventoy_env_op1(op, a) grub_env_##op(a)
58 #define ventoy_env_op2(op, a, b) grub_env_##op((a), (b))
60 #define ventoy_get_env(key) ventoy_env_op1(get, key)
61 #define ventoy_set_env(key, val) ventoy_env_op2(set, key, val)
63 #define VTOY_WARNING "!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!"
65 #define VTOY_PLAT_I386_UEFI 0x49413332
66 #define VTOY_PLAT_ARM64_UEFI 0x41413634
67 #define VTOY_PLAT_X86_64_UEFI 0x55454649
68 #define VTOY_PLAT_X86_LEGACY 0x42494f53
69 #define VTOY_PLAT_MIPS_UEFI 0x4D495053
71 #define VTOY_COMM_CPIO "ventoy.cpio"
72 #if defined(__arm__) || defined(__aarch64__)
73 #define VTOY_ARCH_CPIO "ventoy_arm64.cpio"
74 #elif defined(__mips__)
75 #define VTOY_ARCH_CPIO "ventoy_mips64.cpio"
77 #define VTOY_ARCH_CPIO "ventoy_x86.cpio"
80 #define ventoy_varg_4(arg) arg[0], arg[1], arg[2], arg[3]
81 #define ventoy_varg_8(arg) arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7]
83 #define VTOY_PWD_CORRUPTED(err) \
85 grub_printf("\n\n Password corrupted, will reboot after 5 seconds.\n\n"); \
92 #define VTOY_APPEND_NEWBUF(buf) \
97 newbuf[pos++] = *__c;\
102 typedef enum VTOY_FILE_FLT
104 VTOY_FILE_FLT_ISO
= 0, /* .iso */
105 VTOY_FILE_FLT_WIM
, /* .wim */
106 VTOY_FILE_FLT_EFI
, /* .efi */
107 VTOY_FILE_FLT_IMG
, /* .img */
108 VTOY_FILE_FLT_VHD
, /* .vhd(x) */
109 VTOY_FILE_FLT_VTOY
, /* .vtoy */
114 #define FILE_FLT(type) (0 == g_vtoy_file_flt[VTOY_FILE_FLT_##type])
116 typedef struct ventoy_initrd_ctx
118 const char *path_prefix
;
119 const char *dir_prefix
;
122 typedef struct cmd_para
125 grub_extcmd_func_t func
;
126 grub_command_flags_t flags
;
127 const struct grub_arg_option
*parser
;
130 const char *description
;
135 #define ventoy_align_2k(value) ((value + 2047) / 2048 * 2048)
136 #define ventoy_align(value, align) (((value) + ((align) - 1)) & (~((align) - 1)))
139 typedef struct cpio_newc_header
159 #define cmd_raw_name ctxt->extcmd->cmd->name
160 #define check_free(p, func) if (p) { func(p); p = NULL; }
161 #define grub_check_free(p) if (p) { grub_free(p); p = NULL; }
163 typedef int (*grub_char_check_func
)(int c
);
164 #define ventoy_is_decimal(str) ventoy_string_check(str, grub_isdigit)
166 #define OFFSET_OF(TYPE, MEMBER) ((grub_size_t) &((TYPE *)0)->MEMBER)
169 typedef struct ventoy_patch_vhd
171 grub_uint8_t part_offset_or_guid
[16];
172 grub_uint32_t reserved1
;
173 grub_uint32_t part_type
;
174 grub_uint8_t disk_signature_or_guid
[16];
175 grub_uint8_t reserved2
[16];
176 grub_uint8_t vhd_file_path
[1];
180 // El Torito Boot Record Volume Descriptor
182 typedef struct eltorito_descriptor
186 grub_uint8_t version
;
187 grub_uint8_t system_id
[32];
188 grub_uint8_t reserved
[32];
189 grub_uint32_t sector
;
190 }eltorito_descriptor
;
192 typedef struct ventoy_iso9660_override
194 grub_uint32_t first_sector
;
195 grub_uint32_t first_sector_be
;
197 grub_uint32_t size_be
;
198 }ventoy_iso9660_override
;
200 typedef struct ventoy_udf_override
202 grub_uint32_t length
;
203 grub_uint32_t position
;
204 }ventoy_udf_override
;
206 typedef struct ventoy_iso9660_vd
214 grub_uint8_t res2
[8];
218 /* https://wiki.osdev.org/El-Torito */
219 typedef struct boot_info_table
221 grub_uint32_t bi_data0
;
222 grub_uint32_t bi_data1
;
223 grub_uint32_t bi_PrimaryVolumeDescriptor
;
224 grub_uint32_t bi_BootFileLocation
;
225 grub_uint32_t bi_BootFileLength
;
226 grub_uint32_t bi_Checksum
;
227 grub_uint8_t bi_Reserved
[40];
232 #define img_type_start 0
233 #define img_type_iso 0
234 #define img_type_wim 1
235 #define img_type_efi 2
236 #define img_type_img 3
237 #define img_type_vhd 4
238 #define img_type_vtoy 5
239 #define img_type_max 6
241 typedef struct img_info
251 const char *menu_prefix
;
255 int plugin_list_index
;
262 struct img_info
*next
;
263 struct img_info
*prev
;
266 typedef struct img_iterator_node
268 struct img_iterator_node
*next
;
277 int plugin_list_index
;
279 struct img_iterator_node
*parent
;
280 struct img_iterator_node
*firstchild
;
287 typedef struct initrd_info
291 grub_uint64_t offset
;
294 grub_uint8_t iso_type
; // 0: iso9660 1:udf
295 grub_uint32_t udf_start_block
;
297 grub_uint64_t override_offset
;
298 grub_uint32_t override_length
;
299 char override_data
[32];
301 struct initrd_info
*next
;
302 struct initrd_info
*prev
;
305 extern initrd_info
*g_initrd_img_list
;
306 extern initrd_info
*g_initrd_img_tail
;
307 extern int g_initrd_img_count
;
308 extern int g_valid_initrd_count
;
310 extern img_info
*g_ventoy_img_list
;
311 extern int g_ventoy_img_count
;
313 extern grub_uint8_t
*g_ventoy_cpio_buf
;
314 extern grub_uint32_t g_ventoy_cpio_size
;
315 extern cpio_newc_header
*g_ventoy_initrd_head
;
316 extern grub_uint8_t
*g_ventoy_runtime_buf
;
318 extern ventoy_guid g_ventoy_guid
;
320 extern ventoy_img_chunk_list g_img_chunk_list
;
321 extern ventoy_img_chunk_list g_wimiso_chunk_list
;
322 extern char *g_wimiso_path
;
323 extern grub_uint32_t g_wimiso_size
;
324 extern char g_arch_mode_suffix
[64];
325 extern const char *g_menu_prefix
[img_type_max
];
327 extern int g_ventoy_debug
;
328 void ventoy_debug(const char *fmt
, ...);
329 #define debug(fmt, args...) if (g_ventoy_debug) ventoy_debug("[VTOY]: "fmt, ##args)
331 #define vtoy_ssprintf(buf, pos, fmt, args...) \
332 pos += grub_snprintf(buf + pos, VTOY_MAX_SCRIPT_BUF - pos, fmt, ##args)
334 #define vtoy_len_ssprintf(buf, pos, len, fmt, args...) \
335 pos += grub_snprintf(buf + pos, len - pos, fmt, ##args)
337 #define browser_ssprintf(mbuf, fmt, args...) \
338 (mbuf)->pos += grub_snprintf((mbuf)->buf + (mbuf)->pos, (mbuf)->max - (mbuf)->pos, fmt, ##args)
340 #define vtoy_dummy_menuentry(buf, pos, len, title, class) \
341 vtoy_len_ssprintf(buf, pos, len, "menuentry \"%s\" --class=\"%s\" {\n echo \"\"\n}\n", title, class)
344 #define FLAG_HEADER_RESERVED 0x00000001
345 #define FLAG_HEADER_COMPRESSION 0x00000002
346 #define FLAG_HEADER_READONLY 0x00000004
347 #define FLAG_HEADER_SPANNED 0x00000008
348 #define FLAG_HEADER_RESOURCE_ONLY 0x00000010
349 #define FLAG_HEADER_METADATA_ONLY 0x00000020
350 #define FLAG_HEADER_WRITE_IN_PROGRESS 0x00000040
351 #define FLAG_HEADER_RP_FIX 0x00000080 // reparse point fixup
352 #define FLAG_HEADER_COMPRESS_RESERVED 0x00010000
353 #define FLAG_HEADER_COMPRESS_XPRESS 0x00020000
354 #define FLAG_HEADER_COMPRESS_LZX 0x00040000
355 #define FLAG_HEADER_COMPRESS_LZMS 0x00080000
357 #define RESHDR_FLAG_FREE 0x01
358 #define RESHDR_FLAG_METADATA 0x02
359 #define RESHDR_FLAG_COMPRESSED 0x04
360 #define RESHDR_FLAG_SPANNED 0x08
364 /* A WIM resource header */
365 typedef struct wim_resource_header
367 grub_uint64_t size_in_wim
:56; /* Compressed length */
368 grub_uint64_t flags
:8; /* flags */
369 grub_uint64_t offset
; /* Offset */
370 grub_uint64_t raw_size
; /* Uncompressed length */
371 }wim_resource_header
;
373 /* WIM resource header length mask */
374 #define WIM_RESHDR_ZLEN_MASK 0x00ffffffffffffffULL
376 /* WIM resource header flags */
377 typedef enum wim_resource_header_flags
379 WIM_RESHDR_METADATA
= ( 0x02ULL
<< 56 ), /* Resource contains metadata */
380 WIM_RESHDR_COMPRESSED
= ( 0x04ULL
<< 56 ), /* Resource is compressed */
381 WIM_RESHDR_PACKED_STREAMS
= ( 0x10ULL
<< 56 ), /* Resource is compressed using packed streams */
382 }wim_resource_header_flags
;
384 #define WIM_HEAD_SIGNATURE "MSWIM\0\0"
387 typedef struct wim_header
389 grub_uint8_t signature
[8]; /* Signature */
390 grub_uint32_t header_len
; /* Header length */
391 grub_uint32_t version
; /* Verson */
392 grub_uint32_t flags
; /* Flags */
393 grub_uint32_t chunk_len
; /* Chunk length */
394 grub_uint8_t guid
[16]; /* GUID */
395 grub_uint16_t part
; /* Part number */
396 grub_uint16_t parts
; /* Total number of parts */
397 grub_uint32_t images
; /* number of images */
398 wim_resource_header lookup
; /* Lookup table */
399 wim_resource_header xml
; /* XML data */
400 wim_resource_header metadata
; /* Boot metadata */
401 grub_uint32_t boot_index
; /* Boot index */
402 wim_resource_header integrity
; /* Integrity table */
403 grub_uint8_t reserved
[60]; /* Reserved */
406 /* WIM header flags */
407 typedef enum wim_header_flags
409 WIM_HDR_XPRESS
= 0x00020000, /* WIM uses Xpress compresson */
410 WIM_HDR_LZX
= 0x00040000, /* WIM uses LZX compression */
413 /* A WIM file hash */
414 typedef struct wim_hash
417 grub_uint8_t sha1
[20];
420 /* A WIM lookup table entry */
421 typedef struct wim_lookup_entry
423 wim_resource_header resource
; /* Resource header */
424 grub_uint16_t part
; /* Part number */
425 grub_uint32_t refcnt
; /* Reference count */
426 wim_hash hash
; /* Hash */
429 /* WIM chunk length */
430 #define WIM_CHUNK_LEN 32768
432 /* A WIM chunk buffer */
433 typedef struct wim_chunk_buffer
435 grub_uint8_t data
[WIM_CHUNK_LEN
]; /*Data */
439 typedef struct wim_security_header
441 grub_uint32_t len
; /* Length */
442 grub_uint32_t count
; /* Number of entries */
443 }wim_security_header
;
445 typedef struct wim_stream_entry
448 grub_uint64_t unused1
;
450 grub_uint16_t name_len
;
454 /* Directory entry */
455 typedef struct wim_directory_entry
457 grub_uint64_t len
; /* Length */
458 grub_uint32_t attributes
; /* Attributes */
459 grub_uint32_t security
; /* Security ID */
460 grub_uint64_t subdir
; /* Subdirectory offset */
461 grub_uint8_t reserved1
[16]; /* Reserved */
462 grub_uint64_t created
; /* Creation time */
463 grub_uint64_t accessed
; /* Last access time */
464 grub_uint64_t written
; /* Last written time */
465 wim_hash hash
; /* Hash */
466 grub_uint8_t reserved2
[12]; /* Reserved */
467 grub_uint16_t streams
; /* Streams */
468 grub_uint16_t short_name_len
; /* Short name length */
469 grub_uint16_t name_len
; /* Name length */
470 }wim_directory_entry
;
473 #define WIM_ATTR_NORMAL 0x00000080UL
475 /** No security information exists for this file */
476 #define WIM_NO_SECURITY 0xffffffffUL
478 typedef struct reg_vk
482 grub_uint16_t namesize
;
483 grub_uint32_t datasize
;
484 grub_uint32_t dataoffset
;
485 grub_uint32_t datatype
;
493 typedef struct wim_tail
495 grub_uint32_t wim_raw_size
;
496 grub_uint32_t wim_align_size
;
498 grub_uint8_t iso_type
;
499 grub_uint64_t file_offset
;
500 grub_uint32_t udf_start_block
;
501 grub_uint64_t fe_entry_size_offset
;
502 grub_uint64_t override_offset
;
503 grub_uint32_t override_len
;
504 grub_uint8_t override_data
[32];
506 wim_header wim_header
;
509 grub_uint32_t jump_exe_len
;
510 grub_uint8_t
*jump_bin_data
;
511 grub_uint32_t bin_raw_len
;
512 grub_uint32_t bin_align_len
;
513 grub_uint32_t windata_flag
;
515 grub_uint8_t
*new_meta_data
;
516 grub_uint32_t new_meta_len
;
517 grub_uint32_t new_meta_align_len
;
519 grub_uint8_t
*new_lookup_data
;
520 grub_uint32_t new_lookup_len
;
521 grub_uint32_t new_lookup_align_len
;
524 typedef struct wim_patch
531 wim_lookup_entry
*replace_look
;
535 struct wim_patch
*next
;
539 typedef enum _JSON_TYPE
541 JSON_TYPE_NUMBER
= 0,
551 typedef struct _VTOY_JSON
553 struct _VTOY_JSON
*pstPrev
;
554 struct _VTOY_JSON
*pstNext
;
555 struct _VTOY_JSON
*pstChild
;
557 JSON_TYPE enDataType
;
562 grub_uint64_t lValue
;
568 typedef struct _JSON_PARSE
572 grub_uint32_t uiBufSize
;
575 #define JSON_NEW_ITEM(pstJson, ret) \
577 (pstJson) = (VTOY_JSON *)grub_zalloc(sizeof(VTOY_JSON)); \
578 if (NULL == (pstJson)) \
580 json_debug("Failed to alloc memory for json.\n"); \
585 typedef int (*ventoy_plugin_entry_pf
)(VTOY_JSON
*json
, const char *isodisk
);
586 typedef int (*ventoy_plugin_check_pf
)(VTOY_JSON
*json
, const char *isodisk
);
588 typedef struct plugin_entry
591 ventoy_plugin_entry_pf entryfunc
;
592 ventoy_plugin_check_pf checkfunc
;
596 typedef struct replace_fs_dir
607 typedef struct chk_case_fs_dir
613 int ventoy_str_all_digit(const char *str
);
614 int ventoy_strcmp(const char *pattern
, const char *str
);
615 int ventoy_strncmp (const char *pattern
, const char *str
, grub_size_t n
);
616 void ventoy_fill_os_param(grub_file_t file
, ventoy_os_param
*param
);
617 grub_err_t
ventoy_cmd_isolinux_initrd_collect(grub_extcmd_context_t ctxt
, int argc
, char **args
);
618 grub_err_t
ventoy_cmd_grub_initrd_collect(grub_extcmd_context_t ctxt
, int argc
, char **args
);
619 grub_err_t
ventoy_cmd_specify_initrd_file(grub_extcmd_context_t ctxt
, int argc
, char **args
);
620 grub_err_t
ventoy_cmd_dump_initrd_list(grub_extcmd_context_t ctxt
, int argc
, char **args
);
621 grub_err_t
ventoy_cmd_clear_initrd_list(grub_extcmd_context_t ctxt
, int argc
, char **args
);
622 grub_uint32_t
ventoy_get_iso_boot_catlog(grub_file_t file
);
623 int ventoy_has_efi_eltorito(grub_file_t file
, grub_uint32_t sector
);
624 grub_err_t
ventoy_cmd_linux_chain_data(grub_extcmd_context_t ctxt
, int argc
, char **args
);
625 grub_err_t
ventoy_cmd_linux_systemd_menu(grub_extcmd_context_t ctxt
, int argc
, char **args
);
626 grub_err_t
ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt
, int argc
, char **args
);
627 grub_err_t
ventoy_cmd_initrd_count(grub_extcmd_context_t ctxt
, int argc
, char **args
);
628 grub_err_t
ventoy_cmd_valid_initrd_count(grub_extcmd_context_t ctxt
, int argc
, char **args
);
629 grub_err_t
ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt
, int argc
, char **args
);
630 grub_err_t
ventoy_cmd_append_ext_sector(grub_extcmd_context_t ctxt
, int argc
, char **args
);
631 grub_err_t
ventoy_cmd_skip_svd(grub_extcmd_context_t ctxt
, int argc
, char **args
);
632 grub_err_t
ventoy_cmd_cpio_busybox_64(grub_extcmd_context_t ctxt
, int argc
, char **args
);
633 grub_err_t
ventoy_cmd_trailer_cpio(grub_extcmd_context_t ctxt
, int argc
, char **args
);
634 int ventoy_cpio_newc_fill_head(void *buf
, int filesize
, const void *filedata
, const char *name
);
635 grub_file_t
ventoy_grub_file_open(enum grub_file_type type
, const char *fmt
, ...);
636 grub_uint64_t
ventoy_grub_get_file_size(const char *fmt
, ...);
637 int ventoy_is_dir_exist(const char *fmt
, ...);
638 int ventoy_fill_data(grub_uint32_t buflen
, char *buffer
);
639 grub_err_t
ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt
, int argc
, char **args
);
640 grub_err_t
ventoy_cmd_wimdows_reset(grub_extcmd_context_t ctxt
, int argc
, char **args
);
641 grub_err_t
ventoy_cmd_is_pe64(grub_extcmd_context_t ctxt
, int argc
, char **args
);
642 grub_err_t
ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt
, int argc
, char **args
);
643 grub_err_t
ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt
, int argc
, char **args
);
644 grub_err_t
ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt
, int argc
, char **args
);
645 grub_err_t
ventoy_cmd_wim_check_bootable(grub_extcmd_context_t ctxt
, int argc
, char **args
);
646 grub_err_t
ventoy_cmd_is_standard_winiso(grub_extcmd_context_t ctxt
, int argc
, char **args
);
647 grub_err_t
ventoy_cmd_dump_wim_patch(grub_extcmd_context_t ctxt
, int argc
, char **args
);
648 grub_err_t
ventoy_cmd_sel_wimboot(grub_extcmd_context_t ctxt
, int argc
, char **args
);
649 grub_err_t
ventoy_cmd_set_wim_prompt(grub_extcmd_context_t ctxt
, int argc
, char **args
);
650 grub_ssize_t
ventoy_load_file_with_prompt(grub_file_t file
, void *buf
, grub_ssize_t size
);
651 int ventoy_need_prompt_load_file(void);
653 VTOY_JSON
*vtoy_json_find_item
656 JSON_TYPE enDataType
,
659 int vtoy_json_parse_value
667 VTOY_JSON
* vtoy_json_create(void);
668 int vtoy_json_parse(VTOY_JSON
*pstJson
, const char *szJsonData
);
670 int vtoy_json_scan_parse
672 const VTOY_JSON
*pstJson
,
673 grub_uint32_t uiParseNum
,
674 JSON_PARSE
*pstJsonParse
677 int vtoy_json_scan_array
681 VTOY_JSON
**ppstArrayItem
684 int vtoy_json_scan_array_ex
688 VTOY_JSON
**ppstArrayItem
690 int vtoy_json_scan_object
694 VTOY_JSON
**ppstObjectItem
696 int vtoy_json_get_int
702 int vtoy_json_get_uint
706 grub_uint32_t
*puiValue
708 int vtoy_json_get_uint64
712 grub_uint64_t
*pui64Value
714 int vtoy_json_get_bool
718 grub_uint8_t
*pbValue
720 int vtoy_json_get_string
724 grub_uint32_t uiBufLen
,
727 const char * vtoy_json_get_string_ex(VTOY_JSON
*pstJson
, const char *szKey
);
728 int vtoy_json_destroy(VTOY_JSON
*pstJson
);
731 grub_uint32_t CalculateCrc32
734 grub_uint32_t Length
,
735 grub_uint32_t InitValue
738 static inline int ventoy_isspace (int c
)
740 return (c
== '\n' || c
== '\r' || c
== ' ' || c
== '\t');
743 static inline int ventoy_is_word_end(int c
)
745 return (c
== 0 || c
== ',' || ventoy_isspace(c
));
749 typedef struct ventoy_part_table
751 grub_uint8_t Active
; // 0x00 0x80
753 grub_uint8_t StartHead
;
754 grub_uint16_t StartSector
: 6;
755 grub_uint16_t StartCylinder
: 10;
759 grub_uint8_t EndHead
;
760 grub_uint16_t EndSector
: 6;
761 grub_uint16_t EndCylinder
: 10;
763 grub_uint32_t StartSectorId
;
764 grub_uint32_t SectorCount
;
767 typedef struct ventoy_mbr_head
769 grub_uint8_t BootCode
[446];
770 ventoy_part_table PartTbl
[4];
775 typedef struct ventoy_gpt_head
777 char Signature
[8]; /* EFI PART */
778 grub_uint8_t Version
[4];
779 grub_uint32_t Length
;
781 grub_uint8_t Reserved1
[4];
782 grub_uint64_t EfiStartLBA
;
783 grub_uint64_t EfiBackupLBA
;
784 grub_uint64_t PartAreaStartLBA
;
785 grub_uint64_t PartAreaEndLBA
;
786 grub_uint8_t DiskGuid
[16];
787 grub_uint64_t PartTblStartLBA
;
788 grub_uint32_t PartTblTotNum
;
789 grub_uint32_t PartTblEntryLen
;
790 grub_uint32_t PartTblCrc
;
791 grub_uint8_t Reserved2
[420];
794 typedef struct ventoy_gpt_part_tbl
796 grub_uint8_t PartType
[16];
797 grub_uint8_t PartGuid
[16];
798 grub_uint64_t StartLBA
;
799 grub_uint64_t LastLBA
;
801 grub_uint16_t Name
[36];
802 }ventoy_gpt_part_tbl
;
804 typedef struct ventoy_gpt_info
807 ventoy_gpt_head Head
;
808 ventoy_gpt_part_tbl PartTbl
[128];
811 typedef struct vhd_footer_t
813 char cookie
[8]; // Cookie
814 grub_uint32_t features
; // Features
815 grub_uint32_t ffversion
; // File format version
816 grub_uint32_t dataoffset
; // Data offset
817 grub_uint32_t timestamp
; // Timestamp
818 grub_uint32_t creatorapp
; // Creator application
819 grub_uint32_t creatorver
; // Creator version
820 grub_uint32_t creatorhos
; // Creator host OS
821 grub_uint32_t origsize
; // Original size
822 grub_uint32_t currsize
; // Current size
823 grub_uint32_t diskgeom
; // Disk geometry
824 grub_uint32_t disktype
; // Disk type
825 grub_uint32_t checksum
; // Checksum
826 grub_uint8_t uniqueid
[16]; // Unique ID
827 grub_uint8_t savedst
; // Saved state
830 #define VDI_IMAGE_FILE_INFO "<<< Oracle VM VirtualBox Disk Image >>>\n"
832 /** Image signature. */
833 #define VDI_IMAGE_SIGNATURE (0xbeda107f)
835 typedef struct VDIPREHEADER
837 /** Just text info about image type, for eyes only. */
839 /** The image signature (VDI_IMAGE_SIGNATURE). */
840 grub_uint32_t u32Signature
;
841 /** The image version (VDI_IMAGE_VERSION). */
842 grub_uint32_t u32Version
;
843 } VDIPREHEADER
, *PVDIPREHEADER
;
847 typedef struct ventoy_video_mode
850 grub_uint32_t height
;
856 typedef struct file_fullpath
862 typedef struct theme_list
865 struct theme_list
*next
;
868 #define auto_install_type_file 0
869 #define auto_install_type_parent 1
870 typedef struct install_template
880 file_fullpath
*templatepath
;
885 struct install_template
*next
;
888 typedef struct dudfile
900 file_fullpath
*dudpath
;
906 typedef struct persistence_config
915 file_fullpath
*backendpath
;
917 struct persistence_config
*next
;
920 #define vtoy_alias_image_file 0
921 #define vtoy_alias_directory 1
923 typedef struct menu_alias
930 struct menu_alias
*next
;
933 #define vtoy_tip_image_file 0
934 #define vtoy_tip_directory 1
935 typedef struct menu_tip
943 struct menu_tip
*next
;
947 #define vtoy_class_image_file 0
948 #define vtoy_class_directory 1
950 typedef struct menu_class
958 struct menu_class
*next
;
961 #define vtoy_custom_boot_image_file 0
962 #define vtoy_custom_boot_directory 1
964 typedef struct custom_boot
971 struct custom_boot
*next
;
974 #define vtoy_max_replace_file_size (1024 * 1024)
975 typedef struct conf_replace
983 struct conf_replace
*next
;
986 #define injection_type_file 0
987 #define injection_type_parent 1
988 typedef struct injection_config
995 struct injection_config
*next
;
998 typedef struct auto_memdisk
1003 struct auto_memdisk
*next
;
1006 typedef struct image_list
1011 struct image_list
*next
;
1014 #define VTOY_PASSWORD_NONE 0
1015 #define VTOY_PASSWORD_TXT 1
1016 #define VTOY_PASSWORD_MD5 2
1017 #define VTOY_PASSWORD_SALT_MD5 3
1019 typedef struct vtoy_password
1024 grub_uint8_t md5
[16];
1027 #define vtoy_menu_pwd_file 0
1028 #define vtoy_menu_pwd_parent 1
1030 typedef struct menu_password
1036 vtoy_password password
;
1038 struct menu_password
*next
;
1041 extern int g_ventoy_menu_esc
;
1042 extern int g_ventoy_suppress_esc
;
1043 extern int g_ventoy_suppress_esc_default
;
1044 extern int g_ventoy_last_entry
;
1045 extern int g_ventoy_memdisk_mode
;
1046 extern int g_ventoy_iso_raw
;
1047 extern int g_ventoy_grub2_mode
;
1048 extern int g_ventoy_wimboot_mode
;
1049 extern int g_ventoy_iso_uefi_drv
;
1050 extern int g_ventoy_case_insensitive
;
1051 extern int g_ventoy_fn_mutex
;
1052 extern grub_uint8_t g_ventoy_chain_type
;
1053 extern int g_vhdboot_enable
;
1055 #define VENTOY_IMG_WHITE_LIST 1
1056 #define VENTOY_IMG_BLACK_LIST 2
1057 extern int g_plugin_image_list
;
1059 extern ventoy_gpt_info
*g_ventoy_part_info
;
1060 extern int g_conf_replace_count
;
1061 extern grub_uint64_t g_conf_replace_offset
[VTOY_MAX_CONF_REPLACE
];
1062 extern grub_uint64_t g_svd_replace_offset
;
1063 extern conf_replace
*g_conf_replace_node
[VTOY_MAX_CONF_REPLACE
];
1064 extern grub_uint8_t
*g_conf_replace_new_buf
[VTOY_MAX_CONF_REPLACE
];
1065 extern int g_conf_replace_new_len
[VTOY_MAX_CONF_REPLACE
];
1066 extern int g_conf_replace_new_len_align
[VTOY_MAX_CONF_REPLACE
];
1067 extern int g_ventoy_disk_bios_id
;
1068 extern grub_uint64_t g_ventoy_disk_size
;
1069 extern grub_uint64_t g_ventoy_disk_part_size
[2];
1070 extern grub_uint32_t g_ventoy_plat_data
;
1072 #define ventoy_unix_fill_virt(new_data, new_len) \
1074 data_secs = (new_len + 2047) / 2048; \
1075 cur->mem_sector_start = sector; \
1076 cur->mem_sector_end = cur->mem_sector_start + data_secs; \
1077 cur->mem_sector_offset = offset; \
1078 cur->remap_sector_start = 0; \
1079 cur->remap_sector_end = 0; \
1080 cur->org_sector_start = 0; \
1081 grub_memcpy(override + offset, new_data, new_len); \
1083 sector += data_secs; \
1084 offset += new_len; \
1085 chain->virt_img_size_in_bytes += data_secs * 2048; \
1088 #define ventoy_syscall0(name) grub_##name()
1089 #define ventoy_syscall1(name, a) grub_##name(a)
1091 void ventoy_str_tolower(char *str
);
1092 void ventoy_str_toupper(char *str
);
1093 char * ventoy_get_line(char *start
);
1094 char *ventoy_str_last(char *str
, char ch
);
1095 int ventoy_cmp_img(img_info
*img1
, img_info
*img2
);
1096 void ventoy_swap_img(img_info
*img1
, img_info
*img2
);
1097 char * ventoy_plugin_get_cur_install_template(const char *isopath
, install_template
**cur
);
1098 install_template
* ventoy_plugin_find_install_template(const char *isopath
);
1099 persistence_config
* ventoy_plugin_find_persistent(const char *isopath
);
1100 grub_uint64_t
ventoy_get_vtoy_partsize(int part
);
1101 void ventoy_plugin_dump_injection(void);
1102 void ventoy_plugin_dump_auto_install(void);
1103 int ventoy_plugin_get_persistent_chunklist(const char *isopath
, int index
, ventoy_img_chunk_list
*chunk_list
);
1104 const char * ventoy_plugin_get_injection(const char *isopath
);
1105 const char * ventoy_plugin_get_menu_alias(int type
, const char *isopath
);
1106 const menu_tip
* ventoy_plugin_get_menu_tip(int type
, const char *isopath
);
1107 const char * ventoy_plugin_get_menu_class(int type
, const char *name
, const char *path
);
1108 int ventoy_plugin_check_memdisk(const char *isopath
);
1109 int ventoy_plugin_get_image_list_index(int type
, const char *name
);
1110 int ventoy_plugin_find_conf_replace(const char *iso
, conf_replace
*nodes
[VTOY_MAX_CONF_REPLACE
]);
1111 dud
* ventoy_plugin_find_dud(const char *iso
);
1112 int ventoy_plugin_load_dud(dud
*node
, const char *isopart
);
1113 int ventoy_get_block_list(grub_file_t file
, ventoy_img_chunk_list
*chunklist
, grub_disk_addr_t start
);
1114 int ventoy_check_block_list(grub_file_t file
, ventoy_img_chunk_list
*chunklist
, grub_disk_addr_t start
);
1115 void ventoy_plugin_dump_persistence(void);
1116 grub_err_t
ventoy_cmd_set_theme(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1117 grub_err_t
ventoy_cmd_set_theme_path(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1118 grub_err_t
ventoy_cmd_select_theme_cfg(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1119 grub_err_t
ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1120 grub_err_t
ventoy_cmd_check_password(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1121 grub_err_t
ventoy_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1122 grub_err_t
ventoy_cmd_collect_wim_patch(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1123 grub_err_t
ventoy_cmd_wim_patch_count(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1124 grub_err_t
ventoy_cmd_locate_wim_patch(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1125 grub_err_t
ventoy_cmd_sel_winpe_wim(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1126 grub_err_t
ventoy_cmd_unix_chain_data(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1127 int ventoy_get_disk_guid(const char *filename
, grub_uint8_t
*guid
, grub_uint8_t
*signature
);
1128 grub_err_t
ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1129 grub_err_t
ventoy_cmd_unix_check_vlnk(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1130 grub_err_t
ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1131 grub_err_t
ventoy_cmd_unix_replace_grub_conf(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1132 grub_err_t
ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1133 grub_err_t
ventoy_cmd_unix_ko_fillmap(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1134 grub_err_t
ventoy_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1135 grub_err_t
ventoy_cmd_unix_gzip_newko(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1136 grub_err_t
ventoy_cmd_unix_freebsd_ver(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1137 grub_err_t
ventoy_cmd_parse_freenas_ver(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1138 grub_err_t
ventoy_cmd_unix_freebsd_ver_elf(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1139 int ventoy_check_device_result(int ret
);
1140 int ventoy_check_device(grub_device_t dev
);
1141 void ventoy_debug_dump_guid(const char *prefix
, grub_uint8_t
*guid
);
1142 grub_err_t
ventoy_cmd_load_vhdboot(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1143 grub_err_t
ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1144 grub_err_t
ventoy_cmd_raw_chain_data(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1145 grub_err_t
ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1146 int ventoy_check_password(const vtoy_password
*pwd
, int retry
);
1147 int ventoy_plugin_add_custom_boot(const char *vcfgpath
);
1148 const char * ventoy_plugin_get_custom_boot(const char *isopath
);
1149 grub_err_t
ventoy_cmd_dump_custom_boot(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1150 int ventoy_gzip_compress(void *mem_in
, int mem_in_len
, void *mem_out
, int mem_out_len
);
1151 int ventoy_load_part_table(const char *diskname
);
1152 int ventoy_env_init(void);
1153 int ventoy_register_all_cmd(void);
1154 int ventoy_unregister_all_cmd(void);
1155 int ventoy_chain_file_size(const char *path
);
1156 int ventoy_chain_file_read(const char *path
, int offset
, int len
, void *buf
);
1158 #define VTOY_CMD_CHECK(a) if (33554432 != g_ventoy_disk_part_size[a]) ventoy_syscall0(exit)
1160 #define vtoy_theme_random_boot_second 0
1161 #define vtoy_theme_random_boot_day 1
1162 #define vtoy_theme_random_boot_month 2
1164 #define ventoy_env_export(env, name) \
1166 grub_env_set((env), (name));\
1167 grub_env_export(env);\
1170 #define ret_goto_end(a) ret = a; goto end;
1172 extern ventoy_grub_param
*g_grub_param
;
1175 #define VENTOY_UNIX_SEG_MAGIC0 0x11223344
1176 #define VENTOY_UNIX_SEG_MAGIC1 0x55667788
1177 #define VENTOY_UNIX_SEG_MAGIC2 0x99aabbcc
1178 #define VENTOY_UNIX_SEG_MAGIC3 0xddeeff00
1179 #define VENTOY_UNIX_MAX_SEGNUM 40960
1180 struct g_ventoy_seg
{
1181 grub_uint64_t seg_start_bytes
;
1182 grub_uint64_t seg_end_bytes
;
1185 struct g_ventoy_map
{
1186 grub_uint32_t magic1
[4];
1187 grub_uint32_t magic2
[4];
1188 grub_uint64_t segnum
;
1189 grub_uint64_t disksize
;
1190 grub_uint8_t diskuuid
[16];
1191 struct g_ventoy_seg seglist
[VENTOY_UNIX_MAX_SEGNUM
];
1192 grub_uint32_t magic3
[4];
1196 typedef struct ventoy_vlnk_part
1198 grub_uint32_t disksig
;
1199 grub_uint64_t partoffset
;
1205 struct ventoy_vlnk_part
*next
;
1209 typedef struct browser_mbuf
1216 typedef struct browser_node
1219 char menuentry
[1024];
1221 struct browser_node
*prev
;
1222 struct browser_node
*next
;
1225 typedef struct var_node
1230 struct var_node
*next
;
1233 typedef struct systemd_menu_ctx
1241 #define vtoy_check_goto_out(p) if (!p) goto out
1243 extern char *g_tree_script_buf
;
1244 extern int g_tree_script_pos
;
1245 extern int g_tree_script_pre
;
1246 extern int g_tree_view_menu_style
;
1247 extern int g_sort_case_sensitive
;
1248 extern int g_wimboot_enable
;
1249 extern int g_filt_dot_underscore_file
;
1250 extern int g_vtoy_file_flt
[VTOY_FILE_FLT_BUTT
];
1251 extern const char *g_menu_class
[img_type_max
];
1252 extern char g_iso_path
[256];
1253 int ventoy_add_vlnk_file(char *dir
, const char *name
);
1254 grub_err_t
ventoy_cmd_browser_dir(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1255 grub_err_t
ventoy_cmd_browser_disk(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1256 int ventoy_get_fs_type(const char *fs
);
1257 int ventoy_img_name_valid(const char *filename
, grub_size_t namelen
);
1258 void * ventoy_alloc_chain(grub_size_t size
);
1260 #endif /* __VENTOY_DEF_H__ */