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_SIZE_1GB 1073741824
33 #define VTOY_SIZE_1MB (1024 * 1024)
34 #define VTOY_SIZE_2MB (2 * 1024 * 1024)
35 #define VTOY_SIZE_4MB (4 * 1024 * 1024)
36 #define VTOY_SIZE_512KB (512 * 1024)
37 #define VTOY_SIZE_1KB 1024
38 #define VTOY_SIZE_32KB (32 * 1024)
40 #define JSON_SUCCESS 0
42 #define JSON_NOT_FOUND 2
44 #define ulong unsigned long
45 #define ulonglong unsigned long long
47 #define vtoy_to_upper(c) (((char)(c) >= 'a' && (char)(c) <= 'z') ? ((char)(c) - 'a' + 'A') : (char)(c))
49 #define VENTOY_CMD_RETURN(err) grub_errno = (err); return (err)
50 #define VENTOY_FILE_TYPE (GRUB_FILE_TYPE_NO_DECOMPRESS | GRUB_FILE_TYPE_LINUX_INITRD)
52 #define ventoy_env_op1(op, a) grub_env_##op(a)
53 #define ventoy_env_op2(op, a, b) grub_env_##op((a), (b))
55 #define ventoy_get_env(key) ventoy_env_op1(get, key)
56 #define ventoy_set_env(key, val) ventoy_env_op2(set, key, val)
58 #define VTOY_WARNING "!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!"
60 #define VTOY_PLAT_I386_UEFI 0x49413332
61 #define VTOY_PLAT_ARM64_UEFI 0x41413634
62 #define VTOY_PLAT_X86_64_UEFI 0x55454649
63 #define VTOY_PLAT_X86_LEGACY 0x42494f53
64 #define VTOY_PLAT_MIPS_UEFI 0x4D495053
66 #define VTOY_COMM_CPIO "ventoy.cpio"
67 #if defined(__arm__) || defined(__aarch64__)
68 #define VTOY_ARCH_CPIO "ventoy_arm64.cpio"
69 #elif defined(__mips__)
70 #define VTOY_ARCH_CPIO "ventoy_mips64.cpio"
72 #define VTOY_ARCH_CPIO "ventoy_x86.cpio"
75 #define ventoy_varg_4(arg) arg[0], arg[1], arg[2], arg[3]
76 #define ventoy_varg_8(arg) arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7]
78 #define VTOY_PWD_CORRUPTED(err) \
80 grub_printf("\n\n Password corrupted, will reboot after 5 seconds.\n\n"); \
87 typedef enum VTOY_FILE_FLT
89 VTOY_FILE_FLT_ISO
= 0, /* .iso */
90 VTOY_FILE_FLT_WIM
, /* .wim */
91 VTOY_FILE_FLT_EFI
, /* .efi */
92 VTOY_FILE_FLT_IMG
, /* .img */
93 VTOY_FILE_FLT_VHD
, /* .vhd(x) */
94 VTOY_FILE_FLT_VTOY
, /* .vtoy */
99 #define FILE_FLT(type) (0 == g_vtoy_file_flt[VTOY_FILE_FLT_##type])
101 typedef struct ventoy_initrd_ctx
103 const char *path_prefix
;
104 const char *dir_prefix
;
107 typedef struct cmd_para
110 grub_extcmd_func_t func
;
111 grub_command_flags_t flags
;
112 const struct grub_arg_option
*parser
;
115 const char *description
;
120 #define ventoy_align_2k(value) ((value + 2047) / 2048 * 2048)
121 #define ventoy_align(value, align) (((value) + ((align) - 1)) & (~((align) - 1)))
124 typedef struct cpio_newc_header
144 #define cmd_raw_name ctxt->extcmd->cmd->name
145 #define check_free(p, func) if (p) { func(p); p = NULL; }
146 #define grub_check_free(p) if (p) { grub_free(p); p = NULL; }
148 typedef int (*grub_char_check_func
)(int c
);
149 #define ventoy_is_decimal(str) ventoy_string_check(str, grub_isdigit)
151 #define OFFSET_OF(TYPE, MEMBER) ((grub_size_t) &((TYPE *)0)->MEMBER)
154 typedef struct ventoy_patch_vhd
156 grub_uint8_t part_offset_or_guid
[16];
157 grub_uint32_t reserved1
;
158 grub_uint32_t part_type
;
159 grub_uint8_t disk_signature_or_guid
[16];
160 grub_uint8_t reserved2
[16];
161 grub_uint8_t vhd_file_path
[1];
165 // El Torito Boot Record Volume Descriptor
167 typedef struct eltorito_descriptor
171 grub_uint8_t version
;
172 grub_uint8_t system_id
[32];
173 grub_uint8_t reserved
[32];
174 grub_uint32_t sector
;
175 }eltorito_descriptor
;
177 typedef struct ventoy_iso9660_override
179 grub_uint32_t first_sector
;
180 grub_uint32_t first_sector_be
;
182 grub_uint32_t size_be
;
183 }ventoy_iso9660_override
;
185 typedef struct ventoy_udf_override
187 grub_uint32_t length
;
188 grub_uint32_t position
;
189 }ventoy_udf_override
;
191 typedef struct ventoy_iso9660_vd
199 grub_uint8_t res2
[8];
203 /* https://wiki.osdev.org/El-Torito */
204 typedef struct boot_info_table
206 grub_uint32_t bi_data0
;
207 grub_uint32_t bi_data1
;
208 grub_uint32_t bi_PrimaryVolumeDescriptor
;
209 grub_uint32_t bi_BootFileLocation
;
210 grub_uint32_t bi_BootFileLength
;
211 grub_uint32_t bi_Checksum
;
212 grub_uint8_t bi_Reserved
[40];
217 #define img_type_start 0
218 #define img_type_iso 0
219 #define img_type_wim 1
220 #define img_type_efi 2
221 #define img_type_img 3
222 #define img_type_vhd 4
223 #define img_type_vtoy 5
224 #define img_type_max 6
226 typedef struct img_info
236 const char *menu_prefix
;
240 int plugin_list_index
;
247 struct img_info
*next
;
248 struct img_info
*prev
;
251 typedef struct img_iterator_node
253 struct img_iterator_node
*next
;
262 int plugin_list_index
;
264 struct img_iterator_node
*parent
;
265 struct img_iterator_node
*firstchild
;
272 typedef struct initrd_info
276 grub_uint64_t offset
;
279 grub_uint8_t iso_type
; // 0: iso9660 1:udf
280 grub_uint32_t udf_start_block
;
282 grub_uint64_t override_offset
;
283 grub_uint32_t override_length
;
284 char override_data
[32];
286 struct initrd_info
*next
;
287 struct initrd_info
*prev
;
290 extern initrd_info
*g_initrd_img_list
;
291 extern initrd_info
*g_initrd_img_tail
;
292 extern int g_initrd_img_count
;
293 extern int g_valid_initrd_count
;
295 extern img_info
*g_ventoy_img_list
;
296 extern int g_ventoy_img_count
;
298 extern grub_uint8_t
*g_ventoy_cpio_buf
;
299 extern grub_uint32_t g_ventoy_cpio_size
;
300 extern cpio_newc_header
*g_ventoy_initrd_head
;
301 extern grub_uint8_t
*g_ventoy_runtime_buf
;
303 extern ventoy_guid g_ventoy_guid
;
305 extern ventoy_img_chunk_list g_img_chunk_list
;
306 extern ventoy_img_chunk_list g_wimiso_chunk_list
;
307 extern char *g_wimiso_path
;
308 extern grub_uint32_t g_wimiso_size
;
309 extern char g_arch_mode_suffix
[64];
310 extern const char *g_menu_prefix
[img_type_max
];
312 extern int g_ventoy_debug
;
313 void ventoy_debug(const char *fmt
, ...);
314 #define debug(fmt, args...) if (g_ventoy_debug) ventoy_debug("[VTOY]: "fmt, ##args)
316 #define vtoy_ssprintf(buf, pos, fmt, ...) \
317 pos += grub_snprintf(buf + pos, VTOY_MAX_SCRIPT_BUF - pos, fmt, __VA_ARGS__)
319 #define browser_ssprintf(mbuf, fmt, args...) \
320 (mbuf)->pos += grub_snprintf((mbuf)->buf + (mbuf)->pos, (mbuf)->max - (mbuf)->pos, fmt, ##args)
322 #define FLAG_HEADER_RESERVED 0x00000001
323 #define FLAG_HEADER_COMPRESSION 0x00000002
324 #define FLAG_HEADER_READONLY 0x00000004
325 #define FLAG_HEADER_SPANNED 0x00000008
326 #define FLAG_HEADER_RESOURCE_ONLY 0x00000010
327 #define FLAG_HEADER_METADATA_ONLY 0x00000020
328 #define FLAG_HEADER_WRITE_IN_PROGRESS 0x00000040
329 #define FLAG_HEADER_RP_FIX 0x00000080 // reparse point fixup
330 #define FLAG_HEADER_COMPRESS_RESERVED 0x00010000
331 #define FLAG_HEADER_COMPRESS_XPRESS 0x00020000
332 #define FLAG_HEADER_COMPRESS_LZX 0x00040000
333 #define FLAG_HEADER_COMPRESS_LZMS 0x00080000
335 #define RESHDR_FLAG_FREE 0x01
336 #define RESHDR_FLAG_METADATA 0x02
337 #define RESHDR_FLAG_COMPRESSED 0x04
338 #define RESHDR_FLAG_SPANNED 0x08
342 /* A WIM resource header */
343 typedef struct wim_resource_header
345 grub_uint64_t size_in_wim
:56; /* Compressed length */
346 grub_uint64_t flags
:8; /* flags */
347 grub_uint64_t offset
; /* Offset */
348 grub_uint64_t raw_size
; /* Uncompressed length */
349 }wim_resource_header
;
351 /* WIM resource header length mask */
352 #define WIM_RESHDR_ZLEN_MASK 0x00ffffffffffffffULL
354 /* WIM resource header flags */
355 typedef enum wim_resource_header_flags
357 WIM_RESHDR_METADATA
= ( 0x02ULL
<< 56 ), /* Resource contains metadata */
358 WIM_RESHDR_COMPRESSED
= ( 0x04ULL
<< 56 ), /* Resource is compressed */
359 WIM_RESHDR_PACKED_STREAMS
= ( 0x10ULL
<< 56 ), /* Resource is compressed using packed streams */
360 }wim_resource_header_flags
;
362 #define WIM_HEAD_SIGNATURE "MSWIM\0\0"
365 typedef struct wim_header
367 grub_uint8_t signature
[8]; /* Signature */
368 grub_uint32_t header_len
; /* Header length */
369 grub_uint32_t version
; /* Verson */
370 grub_uint32_t flags
; /* Flags */
371 grub_uint32_t chunk_len
; /* Chunk length */
372 grub_uint8_t guid
[16]; /* GUID */
373 grub_uint16_t part
; /* Part number */
374 grub_uint16_t parts
; /* Total number of parts */
375 grub_uint32_t images
; /* number of images */
376 wim_resource_header lookup
; /* Lookup table */
377 wim_resource_header xml
; /* XML data */
378 wim_resource_header metadata
; /* Boot metadata */
379 grub_uint32_t boot_index
; /* Boot index */
380 wim_resource_header integrity
; /* Integrity table */
381 grub_uint8_t reserved
[60]; /* Reserved */
384 /* WIM header flags */
385 typedef enum wim_header_flags
387 WIM_HDR_XPRESS
= 0x00020000, /* WIM uses Xpress compresson */
388 WIM_HDR_LZX
= 0x00040000, /* WIM uses LZX compression */
391 /* A WIM file hash */
392 typedef struct wim_hash
395 grub_uint8_t sha1
[20];
398 /* A WIM lookup table entry */
399 typedef struct wim_lookup_entry
401 wim_resource_header resource
; /* Resource header */
402 grub_uint16_t part
; /* Part number */
403 grub_uint32_t refcnt
; /* Reference count */
404 wim_hash hash
; /* Hash */
407 /* WIM chunk length */
408 #define WIM_CHUNK_LEN 32768
410 /* A WIM chunk buffer */
411 typedef struct wim_chunk_buffer
413 grub_uint8_t data
[WIM_CHUNK_LEN
]; /*Data */
417 typedef struct wim_security_header
419 grub_uint32_t len
; /* Length */
420 grub_uint32_t count
; /* Number of entries */
421 }wim_security_header
;
423 typedef struct wim_stream_entry
426 grub_uint64_t unused1
;
428 grub_uint16_t name_len
;
432 /* Directory entry */
433 typedef struct wim_directory_entry
435 grub_uint64_t len
; /* Length */
436 grub_uint32_t attributes
; /* Attributes */
437 grub_uint32_t security
; /* Security ID */
438 grub_uint64_t subdir
; /* Subdirectory offset */
439 grub_uint8_t reserved1
[16]; /* Reserved */
440 grub_uint64_t created
; /* Creation time */
441 grub_uint64_t accessed
; /* Last access time */
442 grub_uint64_t written
; /* Last written time */
443 wim_hash hash
; /* Hash */
444 grub_uint8_t reserved2
[12]; /* Reserved */
445 grub_uint16_t streams
; /* Streams */
446 grub_uint16_t short_name_len
; /* Short name length */
447 grub_uint16_t name_len
; /* Name length */
448 }wim_directory_entry
;
451 #define WIM_ATTR_NORMAL 0x00000080UL
453 /** No security information exists for this file */
454 #define WIM_NO_SECURITY 0xffffffffUL
456 typedef struct reg_vk
460 grub_uint16_t namesize
;
461 grub_uint32_t datasize
;
462 grub_uint32_t dataoffset
;
463 grub_uint32_t datatype
;
471 typedef struct wim_tail
473 grub_uint32_t wim_raw_size
;
474 grub_uint32_t wim_align_size
;
476 grub_uint8_t iso_type
;
477 grub_uint64_t file_offset
;
478 grub_uint32_t udf_start_block
;
479 grub_uint64_t fe_entry_size_offset
;
480 grub_uint64_t override_offset
;
481 grub_uint32_t override_len
;
482 grub_uint8_t override_data
[32];
484 wim_header wim_header
;
487 grub_uint32_t jump_exe_len
;
488 grub_uint8_t
*jump_bin_data
;
489 grub_uint32_t bin_raw_len
;
490 grub_uint32_t bin_align_len
;
492 grub_uint8_t
*new_meta_data
;
493 grub_uint32_t new_meta_len
;
494 grub_uint32_t new_meta_align_len
;
496 grub_uint8_t
*new_lookup_data
;
497 grub_uint32_t new_lookup_len
;
498 grub_uint32_t new_lookup_align_len
;
501 typedef struct wim_patch
508 wim_lookup_entry
*replace_look
;
512 struct wim_patch
*next
;
516 typedef enum _JSON_TYPE
518 JSON_TYPE_NUMBER
= 0,
528 typedef struct _VTOY_JSON
530 struct _VTOY_JSON
*pstPrev
;
531 struct _VTOY_JSON
*pstNext
;
532 struct _VTOY_JSON
*pstChild
;
534 JSON_TYPE enDataType
;
539 grub_uint64_t lValue
;
545 typedef struct _JSON_PARSE
549 grub_uint32_t uiBufSize
;
552 #define JSON_NEW_ITEM(pstJson, ret) \
554 (pstJson) = (VTOY_JSON *)grub_zalloc(sizeof(VTOY_JSON)); \
555 if (NULL == (pstJson)) \
557 json_debug("Failed to alloc memory for json.\n"); \
562 typedef int (*ventoy_plugin_entry_pf
)(VTOY_JSON
*json
, const char *isodisk
);
563 typedef int (*ventoy_plugin_check_pf
)(VTOY_JSON
*json
, const char *isodisk
);
565 typedef struct plugin_entry
568 ventoy_plugin_entry_pf entryfunc
;
569 ventoy_plugin_check_pf checkfunc
;
573 typedef struct replace_fs_dir
584 typedef struct chk_case_fs_dir
590 int ventoy_strcmp(const char *pattern
, const char *str
);
591 int ventoy_strncmp (const char *pattern
, const char *str
, grub_size_t n
);
592 void ventoy_fill_os_param(grub_file_t file
, ventoy_os_param
*param
);
593 grub_err_t
ventoy_cmd_isolinux_initrd_collect(grub_extcmd_context_t ctxt
, int argc
, char **args
);
594 grub_err_t
ventoy_cmd_grub_initrd_collect(grub_extcmd_context_t ctxt
, int argc
, char **args
);
595 grub_err_t
ventoy_cmd_specify_initrd_file(grub_extcmd_context_t ctxt
, int argc
, char **args
);
596 grub_err_t
ventoy_cmd_dump_initrd_list(grub_extcmd_context_t ctxt
, int argc
, char **args
);
597 grub_err_t
ventoy_cmd_clear_initrd_list(grub_extcmd_context_t ctxt
, int argc
, char **args
);
598 grub_uint32_t
ventoy_get_iso_boot_catlog(grub_file_t file
);
599 int ventoy_has_efi_eltorito(grub_file_t file
, grub_uint32_t sector
);
600 grub_err_t
ventoy_cmd_linux_chain_data(grub_extcmd_context_t ctxt
, int argc
, char **args
);
601 grub_err_t
ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt
, int argc
, char **args
);
602 grub_err_t
ventoy_cmd_initrd_count(grub_extcmd_context_t ctxt
, int argc
, char **args
);
603 grub_err_t
ventoy_cmd_valid_initrd_count(grub_extcmd_context_t ctxt
, int argc
, char **args
);
604 grub_err_t
ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt
, int argc
, char **args
);
605 grub_err_t
ventoy_cmd_append_ext_sector(grub_extcmd_context_t ctxt
, int argc
, char **args
);
606 grub_err_t
ventoy_cmd_skip_svd(grub_extcmd_context_t ctxt
, int argc
, char **args
);
607 grub_err_t
ventoy_cmd_cpio_busybox_64(grub_extcmd_context_t ctxt
, int argc
, char **args
);
608 grub_err_t
ventoy_cmd_trailer_cpio(grub_extcmd_context_t ctxt
, int argc
, char **args
);
609 int ventoy_cpio_newc_fill_head(void *buf
, int filesize
, const void *filedata
, const char *name
);
610 grub_file_t
ventoy_grub_file_open(enum grub_file_type type
, const char *fmt
, ...);
611 grub_uint64_t
ventoy_grub_get_file_size(const char *fmt
, ...);
612 int ventoy_is_dir_exist(const char *fmt
, ...);
613 int ventoy_fill_data(grub_uint32_t buflen
, char *buffer
);
614 grub_err_t
ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt
, int argc
, char **args
);
615 grub_err_t
ventoy_cmd_wimdows_reset(grub_extcmd_context_t ctxt
, int argc
, char **args
);
616 grub_err_t
ventoy_cmd_is_pe64(grub_extcmd_context_t ctxt
, int argc
, char **args
);
617 grub_err_t
ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt
, int argc
, char **args
);
618 grub_err_t
ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt
, int argc
, char **args
);
619 grub_err_t
ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt
, int argc
, char **args
);
620 grub_err_t
ventoy_cmd_wim_check_bootable(grub_extcmd_context_t ctxt
, int argc
, char **args
);
621 grub_err_t
ventoy_cmd_dump_wim_patch(grub_extcmd_context_t ctxt
, int argc
, char **args
);
622 grub_err_t
ventoy_cmd_sel_wimboot(grub_extcmd_context_t ctxt
, int argc
, char **args
);
623 grub_err_t
ventoy_cmd_set_wim_prompt(grub_extcmd_context_t ctxt
, int argc
, char **args
);
624 grub_ssize_t
ventoy_load_file_with_prompt(grub_file_t file
, void *buf
, grub_ssize_t size
);
625 int ventoy_need_prompt_load_file(void);
627 VTOY_JSON
*vtoy_json_find_item
630 JSON_TYPE enDataType
,
633 int vtoy_json_parse_value
641 VTOY_JSON
* vtoy_json_create(void);
642 int vtoy_json_parse(VTOY_JSON
*pstJson
, const char *szJsonData
);
644 int vtoy_json_scan_parse
646 const VTOY_JSON
*pstJson
,
647 grub_uint32_t uiParseNum
,
648 JSON_PARSE
*pstJsonParse
651 int vtoy_json_scan_array
655 VTOY_JSON
**ppstArrayItem
658 int vtoy_json_scan_array_ex
662 VTOY_JSON
**ppstArrayItem
664 int vtoy_json_scan_object
668 VTOY_JSON
**ppstObjectItem
670 int vtoy_json_get_int
676 int vtoy_json_get_uint
680 grub_uint32_t
*puiValue
682 int vtoy_json_get_uint64
686 grub_uint64_t
*pui64Value
688 int vtoy_json_get_bool
692 grub_uint8_t
*pbValue
694 int vtoy_json_get_string
698 grub_uint32_t uiBufLen
,
701 const char * vtoy_json_get_string_ex(VTOY_JSON
*pstJson
, const char *szKey
);
702 int vtoy_json_destroy(VTOY_JSON
*pstJson
);
705 grub_uint32_t CalculateCrc32
708 grub_uint32_t Length
,
709 grub_uint32_t InitValue
712 static inline int ventoy_isspace (int c
)
714 return (c
== '\n' || c
== '\r' || c
== ' ' || c
== '\t');
717 static inline int ventoy_is_word_end(int c
)
719 return (c
== 0 || c
== ',' || ventoy_isspace(c
));
723 typedef struct ventoy_part_table
725 grub_uint8_t Active
; // 0x00 0x80
727 grub_uint8_t StartHead
;
728 grub_uint16_t StartSector
: 6;
729 grub_uint16_t StartCylinder
: 10;
733 grub_uint8_t EndHead
;
734 grub_uint16_t EndSector
: 6;
735 grub_uint16_t EndCylinder
: 10;
737 grub_uint32_t StartSectorId
;
738 grub_uint32_t SectorCount
;
741 typedef struct ventoy_mbr_head
743 grub_uint8_t BootCode
[446];
744 ventoy_part_table PartTbl
[4];
749 typedef struct ventoy_gpt_head
751 char Signature
[8]; /* EFI PART */
752 grub_uint8_t Version
[4];
753 grub_uint32_t Length
;
755 grub_uint8_t Reserved1
[4];
756 grub_uint64_t EfiStartLBA
;
757 grub_uint64_t EfiBackupLBA
;
758 grub_uint64_t PartAreaStartLBA
;
759 grub_uint64_t PartAreaEndLBA
;
760 grub_uint8_t DiskGuid
[16];
761 grub_uint64_t PartTblStartLBA
;
762 grub_uint32_t PartTblTotNum
;
763 grub_uint32_t PartTblEntryLen
;
764 grub_uint32_t PartTblCrc
;
765 grub_uint8_t Reserved2
[420];
768 typedef struct ventoy_gpt_part_tbl
770 grub_uint8_t PartType
[16];
771 grub_uint8_t PartGuid
[16];
772 grub_uint64_t StartLBA
;
773 grub_uint64_t LastLBA
;
775 grub_uint16_t Name
[36];
776 }ventoy_gpt_part_tbl
;
778 typedef struct ventoy_gpt_info
781 ventoy_gpt_head Head
;
782 ventoy_gpt_part_tbl PartTbl
[128];
785 typedef struct vhd_footer_t
787 char cookie
[8]; // Cookie
788 grub_uint32_t features
; // Features
789 grub_uint32_t ffversion
; // File format version
790 grub_uint32_t dataoffset
; // Data offset
791 grub_uint32_t timestamp
; // Timestamp
792 grub_uint32_t creatorapp
; // Creator application
793 grub_uint32_t creatorver
; // Creator version
794 grub_uint32_t creatorhos
; // Creator host OS
795 grub_uint32_t origsize
; // Original size
796 grub_uint32_t currsize
; // Current size
797 grub_uint32_t diskgeom
; // Disk geometry
798 grub_uint32_t disktype
; // Disk type
799 grub_uint32_t checksum
; // Checksum
800 grub_uint8_t uniqueid
[16]; // Unique ID
801 grub_uint8_t savedst
; // Saved state
804 #define VDI_IMAGE_FILE_INFO "<<< Oracle VM VirtualBox Disk Image >>>\n"
806 /** Image signature. */
807 #define VDI_IMAGE_SIGNATURE (0xbeda107f)
809 typedef struct VDIPREHEADER
811 /** Just text info about image type, for eyes only. */
813 /** The image signature (VDI_IMAGE_SIGNATURE). */
814 grub_uint32_t u32Signature
;
815 /** The image version (VDI_IMAGE_VERSION). */
816 grub_uint32_t u32Version
;
817 } VDIPREHEADER
, *PVDIPREHEADER
;
821 typedef struct ventoy_video_mode
824 grub_uint32_t height
;
830 typedef struct file_fullpath
836 typedef struct theme_list
839 struct theme_list
*next
;
842 #define auto_install_type_file 0
843 #define auto_install_type_parent 1
844 typedef struct install_template
854 file_fullpath
*templatepath
;
856 struct install_template
*next
;
859 typedef struct dudfile
871 file_fullpath
*dudpath
;
877 typedef struct persistence_config
886 file_fullpath
*backendpath
;
888 struct persistence_config
*next
;
891 #define vtoy_alias_image_file 0
892 #define vtoy_alias_directory 1
894 typedef struct menu_alias
901 struct menu_alias
*next
;
904 #define vtoy_tip_image_file 0
905 #define vtoy_tip_directory 1
906 typedef struct menu_tip
914 struct menu_tip
*next
;
918 #define vtoy_class_image_file 0
919 #define vtoy_class_directory 1
921 typedef struct menu_class
929 struct menu_class
*next
;
932 #define vtoy_custom_boot_image_file 0
933 #define vtoy_custom_boot_directory 1
935 typedef struct custom_boot
942 struct custom_boot
*next
;
945 #define vtoy_max_replace_file_size (2 * 1024 * 1024)
946 typedef struct conf_replace
954 struct conf_replace
*next
;
957 #define injection_type_file 0
958 #define injection_type_parent 1
959 typedef struct injection_config
966 struct injection_config
*next
;
969 typedef struct auto_memdisk
974 struct auto_memdisk
*next
;
977 typedef struct image_list
982 struct image_list
*next
;
985 #define VTOY_PASSWORD_NONE 0
986 #define VTOY_PASSWORD_TXT 1
987 #define VTOY_PASSWORD_MD5 2
988 #define VTOY_PASSWORD_SALT_MD5 3
990 typedef struct vtoy_password
995 grub_uint8_t md5
[16];
998 #define vtoy_menu_pwd_file 0
999 #define vtoy_menu_pwd_parent 1
1001 typedef struct menu_password
1007 vtoy_password password
;
1009 struct menu_password
*next
;
1012 extern int g_ventoy_menu_esc
;
1013 extern int g_ventoy_suppress_esc
;
1014 extern int g_ventoy_suppress_esc_default
;
1015 extern int g_ventoy_last_entry
;
1016 extern int g_ventoy_memdisk_mode
;
1017 extern int g_ventoy_iso_raw
;
1018 extern int g_ventoy_grub2_mode
;
1019 extern int g_ventoy_wimboot_mode
;
1020 extern int g_ventoy_iso_uefi_drv
;
1021 extern int g_ventoy_case_insensitive
;
1022 extern grub_uint8_t g_ventoy_chain_type
;
1023 extern int g_vhdboot_enable
;
1025 #define VENTOY_IMG_WHITE_LIST 1
1026 #define VENTOY_IMG_BLACK_LIST 2
1027 extern int g_plugin_image_list
;
1029 extern ventoy_gpt_info
*g_ventoy_part_info
;
1030 extern grub_uint64_t g_conf_replace_offset
;
1031 extern grub_uint64_t g_svd_replace_offset
;
1032 extern conf_replace
*g_conf_replace_node
;
1033 extern grub_uint8_t
*g_conf_replace_new_buf
;
1034 extern int g_conf_replace_new_len
;
1035 extern int g_conf_replace_new_len_align
;
1036 extern grub_uint64_t g_ventoy_disk_size
;
1037 extern grub_uint64_t g_ventoy_disk_part_size
[2];
1038 extern grub_uint32_t g_ventoy_plat_data
;
1040 #define ventoy_unix_fill_virt(new_data, new_len) \
1042 data_secs = (new_len + 2047) / 2048; \
1043 cur->mem_sector_start = sector; \
1044 cur->mem_sector_end = cur->mem_sector_start + data_secs; \
1045 cur->mem_sector_offset = offset; \
1046 cur->remap_sector_start = 0; \
1047 cur->remap_sector_end = 0; \
1048 cur->org_sector_start = 0; \
1049 grub_memcpy(override + offset, new_data, new_len); \
1051 sector += data_secs; \
1052 offset += new_len; \
1053 chain->virt_img_size_in_bytes += data_secs * 2048; \
1056 #define ventoy_syscall0(name) grub_##name()
1057 #define ventoy_syscall1(name, a) grub_##name(a)
1059 void ventoy_str_tolower(char *str
);
1060 void ventoy_str_toupper(char *str
);
1061 char * ventoy_get_line(char *start
);
1062 int ventoy_cmp_img(img_info
*img1
, img_info
*img2
);
1063 void ventoy_swap_img(img_info
*img1
, img_info
*img2
);
1064 char * ventoy_plugin_get_cur_install_template(const char *isopath
);
1065 install_template
* ventoy_plugin_find_install_template(const char *isopath
);
1066 persistence_config
* ventoy_plugin_find_persistent(const char *isopath
);
1067 grub_uint64_t
ventoy_get_vtoy_partsize(int part
);
1068 void ventoy_plugin_dump_injection(void);
1069 void ventoy_plugin_dump_auto_install(void);
1070 int ventoy_fill_windows_rtdata(void *buf
, char *isopath
);
1071 int ventoy_plugin_get_persistent_chunklist(const char *isopath
, int index
, ventoy_img_chunk_list
*chunk_list
);
1072 const char * ventoy_plugin_get_injection(const char *isopath
);
1073 const char * ventoy_plugin_get_menu_alias(int type
, const char *isopath
);
1074 const menu_tip
* ventoy_plugin_get_menu_tip(int type
, const char *isopath
);
1075 const char * ventoy_plugin_get_menu_class(int type
, const char *name
, const char *path
);
1076 int ventoy_plugin_check_memdisk(const char *isopath
);
1077 int ventoy_plugin_get_image_list_index(int type
, const char *name
);
1078 conf_replace
* ventoy_plugin_find_conf_replace(const char *iso
);
1079 dud
* ventoy_plugin_find_dud(const char *iso
);
1080 int ventoy_plugin_load_dud(dud
*node
, const char *isopart
);
1081 int ventoy_get_block_list(grub_file_t file
, ventoy_img_chunk_list
*chunklist
, grub_disk_addr_t start
);
1082 int ventoy_check_block_list(grub_file_t file
, ventoy_img_chunk_list
*chunklist
, grub_disk_addr_t start
);
1083 void ventoy_plugin_dump_persistence(void);
1084 grub_err_t
ventoy_cmd_set_theme(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1085 grub_err_t
ventoy_cmd_set_theme_path(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1086 grub_err_t
ventoy_cmd_select_theme_cfg(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1087 grub_err_t
ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1088 grub_err_t
ventoy_cmd_check_password(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1089 grub_err_t
ventoy_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1090 grub_err_t
ventoy_cmd_collect_wim_patch(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1091 grub_err_t
ventoy_cmd_wim_patch_count(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1092 grub_err_t
ventoy_cmd_locate_wim_patch(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1093 grub_err_t
ventoy_cmd_unix_chain_data(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1094 int ventoy_get_disk_guid(const char *filename
, grub_uint8_t
*guid
, grub_uint8_t
*signature
);
1095 grub_err_t
ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1096 grub_err_t
ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1097 grub_err_t
ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1098 grub_err_t
ventoy_cmd_unix_ko_fillmap(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1099 grub_err_t
ventoy_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1100 grub_err_t
ventoy_cmd_unix_gzip_newko(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1101 grub_err_t
ventoy_cmd_unix_freebsd_ver(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1102 grub_err_t
ventoy_cmd_parse_freenas_ver(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1103 grub_err_t
ventoy_cmd_unix_freebsd_ver_elf(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1104 int ventoy_check_device_result(int ret
);
1105 int ventoy_check_device(grub_device_t dev
);
1106 void ventoy_debug_dump_guid(const char *prefix
, grub_uint8_t
*guid
);
1107 grub_err_t
ventoy_cmd_load_vhdboot(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1108 grub_err_t
ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1109 grub_err_t
ventoy_cmd_raw_chain_data(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1110 grub_err_t
ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1111 int ventoy_check_password(const vtoy_password
*pwd
, int retry
);
1112 int ventoy_plugin_add_custom_boot(const char *vcfgpath
);
1113 const char * ventoy_plugin_get_custom_boot(const char *isopath
);
1114 grub_err_t
ventoy_cmd_dump_custom_boot(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1115 int ventoy_gzip_compress(void *mem_in
, int mem_in_len
, void *mem_out
, int mem_out_len
);
1116 int ventoy_load_part_table(const char *diskname
);
1117 int ventoy_env_init(void);
1118 int ventoy_register_all_cmd(void);
1119 int ventoy_unregister_all_cmd(void);
1120 int ventoy_chain_file_size(const char *path
);
1121 int ventoy_chain_file_read(const char *path
, int offset
, int len
, void *buf
);
1123 #define VTOY_CMD_CHECK(a) if (33554432 != g_ventoy_disk_part_size[a]) ventoy_syscall0(exit)
1125 #define vtoy_theme_random_boot_second 0
1126 #define vtoy_theme_random_boot_day 1
1127 #define vtoy_theme_random_boot_month 2
1129 #define ventoy_env_export(env, name) \
1131 grub_env_set((env), (name));\
1132 grub_env_export(env);\
1135 #define ret_goto_end(a) ret = a; goto end;
1137 extern ventoy_grub_param
*g_grub_param
;
1140 #define VENTOY_UNIX_SEG_MAGIC0 0x11223344
1141 #define VENTOY_UNIX_SEG_MAGIC1 0x55667788
1142 #define VENTOY_UNIX_SEG_MAGIC2 0x99aabbcc
1143 #define VENTOY_UNIX_SEG_MAGIC3 0xddeeff00
1144 #define VENTOY_UNIX_MAX_SEGNUM 40960
1145 struct g_ventoy_seg
{
1146 grub_uint64_t seg_start_bytes
;
1147 grub_uint64_t seg_end_bytes
;
1150 struct g_ventoy_map
{
1151 grub_uint32_t magic1
[4];
1152 grub_uint32_t magic2
[4];
1153 grub_uint64_t segnum
;
1154 grub_uint64_t disksize
;
1155 grub_uint8_t diskuuid
[16];
1156 struct g_ventoy_seg seglist
[VENTOY_UNIX_MAX_SEGNUM
];
1157 grub_uint32_t magic3
[4];
1161 typedef struct ventoy_vlnk_part
1163 grub_uint32_t disksig
;
1164 grub_uint64_t partoffset
;
1170 struct ventoy_vlnk_part
*next
;
1174 typedef struct browser_mbuf
1181 typedef struct browser_node
1184 char menuentry
[1024];
1186 struct browser_node
*prev
;
1187 struct browser_node
*next
;
1190 extern char *g_tree_script_buf
;
1191 extern int g_tree_script_pos
;
1192 extern int g_tree_script_pre
;
1193 extern int g_tree_view_menu_style
;
1194 extern int g_sort_case_sensitive
;
1195 extern int g_wimboot_enable
;
1196 extern int g_filt_dot_underscore_file
;
1197 extern int g_vtoy_file_flt
[VTOY_FILE_FLT_BUTT
];
1198 extern const char *g_menu_class
[img_type_max
];
1199 extern char g_iso_path
[256];
1200 int ventoy_add_vlnk_file(char *dir
, const char *name
);
1201 grub_err_t
ventoy_cmd_browser_dir(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1202 grub_err_t
ventoy_cmd_browser_disk(grub_extcmd_context_t ctxt
, int argc
, char **args
);
1203 int ventoy_get_fs_type(const char *fs
);
1204 int ventoy_img_name_valid(const char *filename
, grub_size_t namelen
);
1206 #endif /* __VENTOY_DEF_H__ */