]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - GRUB2/MOD_SRC/grub-2.04/include/grub/ventoy.h
Update vtoytool
[Ventoy.git] / GRUB2 / MOD_SRC / grub-2.04 / include / grub / ventoy.h
1 /******************************************************************************
2 * ventoy.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_H__
22 #define __VENTOY_H__
23
24 #define COMPILE_ASSERT(a, expr) extern char __compile_assert##a[(expr) ? 1 : -1]
25
26 #define VENTOY_COMPATIBLE_STR "VENTOY COMPATIBLE"
27 #define VENTOY_COMPATIBLE_STR_LEN 17
28
29 #define VENTOY_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
30
31 typedef enum ventoy_fs_type
32 {
33 ventoy_fs_exfat = 0, /* 0: exfat */
34 ventoy_fs_ntfs, /* 1: NTFS */
35 ventoy_fs_ext, /* 2: ext2/ext3/ext4 */
36 ventoy_fs_xfs, /* 3: XFS */
37 ventoy_fs_udf, /* 4: UDF */
38 ventoy_fs_fat, /* 5: FAT */
39
40 ventoy_fs_max
41 }ventoy_fs_type;
42
43 typedef enum ventoy_chain_type
44 {
45 ventoy_chain_linux = 0, /* 0: linux */
46 ventoy_chain_windows, /* 1: windows */
47 ventoy_chain_wim, /* 2: wim */
48
49 ventoy_chain_max
50 }ventoy_chain_type;
51
52 #pragma pack(1)
53
54 typedef struct ventoy_guid
55 {
56 grub_uint32_t data1;
57 grub_uint16_t data2;
58 grub_uint16_t data3;
59 grub_uint8_t data4[8];
60 }ventoy_guid;
61
62
63 typedef struct ventoy_image_disk_region
64 {
65 grub_uint32_t image_sector_count; /* image sectors contained in this region (in 2048) */
66 grub_uint32_t image_start_sector; /* image sector start (in 2048) */
67 grub_uint64_t disk_start_sector; /* disk sector start (in 512) */
68 }ventoy_image_disk_region;
69
70 typedef struct ventoy_image_location
71 {
72 ventoy_guid guid;
73
74 /* image sector size, 2048/512 */
75 grub_uint32_t image_sector_size;
76
77 /* disk sector size, normally the value is 512 */
78 grub_uint32_t disk_sector_size;
79
80 grub_uint32_t region_count;
81
82 /*
83 * disk region data (region_count)
84 * If the image file has more than one fragments in disk,
85 * there will be more than one region data here.
86 *
87 */
88 ventoy_image_disk_region regions[1];
89
90 /* ventoy_image_disk_region regions[2~region_count-1] */
91 }ventoy_image_location;
92
93
94 typedef struct ventoy_os_param
95 {
96 ventoy_guid guid; // VENTOY_GUID
97 grub_uint8_t chksum; // checksum
98
99 grub_uint8_t vtoy_disk_guid[16];
100 grub_uint64_t vtoy_disk_size; // disk size in bytes
101 grub_uint16_t vtoy_disk_part_id; // begin with 1
102 grub_uint16_t vtoy_disk_part_type; // 0:exfat 1:ntfs other: reserved
103 char vtoy_img_path[384]; // It seems to be enough, utf-8 format
104 grub_uint64_t vtoy_img_size; // image file size in bytes
105
106 /*
107 * Ventoy will write a copy of ventoy_image_location data into runtime memory
108 * this is the physically address and length of that memory.
109 * Address 0 means no such data exist.
110 * Address will be aligned by 4KB.
111 *
112 */
113 grub_uint64_t vtoy_img_location_addr;
114 grub_uint32_t vtoy_img_location_len;
115
116 /*
117 * These 32 bytes are reserved by ventoy.
118 *
119 * vtoy_reserved[0]: vtoy_break_level
120 * vtoy_reserved[1]: vtoy_debug_level
121 * vtoy_reserved[2]: vtoy_chain_type 0:Linux 1:Windows 2:wimfile
122 * vtoy_reserved[3]: vtoy_iso_format 0:iso9660 1:udf
123 * vtoy_reserved[4]: vtoy_windows_cd_prompt
124 * vtoy_reserved[5]: vtoy_linux_remount
125 * vtoy_reserved[6]: vtoy_vlnk
126 * vtoy_reserved[7~10]: vtoy_disk_sig[4] used for vlnk
127 *
128 */
129 grub_uint8_t vtoy_reserved[32]; // Internal use by ventoy
130
131 grub_uint8_t vtoy_disk_signature[4];
132
133 grub_uint8_t reserved[27];
134 }ventoy_os_param;
135
136
137 typedef struct ventoy_windows_data
138 {
139 char auto_install_script[384];
140 char injection_archive[384];
141 grub_uint8_t windows11_bypass_check;
142
143 grub_uint32_t auto_install_len;
144
145 grub_uint8_t windows11_bypass_nro;
146
147 grub_uint8_t reserved[255 - 5];
148
149 /* auto_intall file buf */
150 /* ...... + auto_install_len */
151 }ventoy_windows_data;
152
153
154 typedef struct ventoy_secure_data
155 {
156 grub_uint8_t magic1[16]; /* VENTOY_GUID */
157 grub_uint8_t diskuuid[16];
158 grub_uint8_t Checksum[16];
159 grub_uint8_t adminSHA256[32];
160 grub_uint8_t reserved[4000];
161 grub_uint8_t magic2[16]; /* VENTOY_GUID */
162 }ventoy_secure_data;
163
164
165 typedef struct ventoy_vlnk
166 {
167 ventoy_guid guid; // VENTOY_GUID
168 grub_uint32_t crc32; // crc32
169 grub_uint32_t disk_signature;
170 grub_uint64_t part_offset; // in bytes
171 char filepath[384];
172 grub_uint8_t reserved[96];
173 }ventoy_vlnk;
174
175 #pragma pack()
176
177 // compile assert check : sizeof(ventoy_os_param) must be 512
178 COMPILE_ASSERT(1,sizeof(ventoy_os_param) == 512);
179 COMPILE_ASSERT(2,sizeof(ventoy_secure_data) == 4096);
180 COMPILE_ASSERT(3,sizeof(ventoy_vlnk) == 512);
181
182
183
184
185
186
187
188 #pragma pack(4)
189
190 typedef struct ventoy_chain_head
191 {
192 ventoy_os_param os_param;
193
194 grub_uint32_t disk_drive;
195 grub_uint32_t drive_map;
196 grub_uint32_t disk_sector_size;
197
198 grub_uint64_t real_img_size_in_bytes;
199 grub_uint64_t virt_img_size_in_bytes;
200 grub_uint32_t boot_catalog;
201 grub_uint8_t boot_catalog_sector[2048];
202
203 grub_uint32_t img_chunk_offset;
204 grub_uint32_t img_chunk_num;
205
206 grub_uint32_t override_chunk_offset;
207 grub_uint32_t override_chunk_num;
208
209 grub_uint32_t virt_chunk_offset;
210 grub_uint32_t virt_chunk_num;
211 }ventoy_chain_head;
212
213 typedef struct ventoy_image_desc
214 {
215 grub_uint64_t disk_size;
216 grub_uint64_t part1_size;
217 grub_uint8_t disk_uuid[16];
218 grub_uint8_t disk_signature[4];
219 grub_uint32_t img_chunk_count;
220 /* ventoy_img_chunk list */
221 }ventoy_image_desc;
222
223
224
225 typedef struct ventoy_img_chunk
226 {
227 grub_uint32_t img_start_sector; // sector size: 2KB
228 grub_uint32_t img_end_sector; // included
229
230 grub_uint64_t disk_start_sector; // in disk_sector_size
231 grub_uint64_t disk_end_sector; // included
232 }ventoy_img_chunk;
233
234
235 typedef struct ventoy_override_chunk
236 {
237 grub_uint64_t img_offset;
238 grub_uint32_t override_size;
239 grub_uint8_t override_data[512];
240 }ventoy_override_chunk;
241
242 typedef struct ventoy_virt_chunk
243 {
244 grub_uint32_t mem_sector_start;
245 grub_uint32_t mem_sector_end;
246 grub_uint32_t mem_sector_offset;
247 grub_uint32_t remap_sector_start;
248 grub_uint32_t remap_sector_end;
249 grub_uint32_t org_sector_start;
250 }ventoy_virt_chunk;
251
252 #define DEFAULT_CHUNK_NUM 1024
253 typedef struct ventoy_img_chunk_list
254 {
255 grub_uint32_t max_chunk;
256 grub_uint32_t cur_chunk;
257 ventoy_img_chunk *chunk;
258 }ventoy_img_chunk_list;
259
260
261 #pragma pack()
262
263 #define ventoy_filt_register grub_file_filter_register
264
265 #pragma pack(1)
266
267 #define VTOY_MAX_CONF_REPLACE 2
268 #define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF
269 #define GRUB_IMG_REPLACE_MAGIC 0x1259BEEF
270
271 typedef const char * (*grub_env_get_pf)(const char *name);
272 typedef int (*grub_env_set_pf)(const char *name, const char *val);
273 typedef int (*grub_env_printf_pf)(const char *fmt, ...);
274
275 typedef struct ventoy_grub_param_file_replace
276 {
277 grub_uint32_t magic;
278 char old_file_name[4][256];
279 grub_uint32_t old_name_cnt;
280 grub_uint32_t new_file_virtual_id;
281 }ventoy_grub_param_file_replace;
282
283 typedef struct ventoy_grub_param
284 {
285 grub_env_get_pf grub_env_get;
286 grub_env_set_pf grub_env_set;
287 ventoy_grub_param_file_replace file_replace;
288 ventoy_grub_param_file_replace img_replace[VTOY_MAX_CONF_REPLACE];
289 grub_env_printf_pf grub_env_printf;
290 }ventoy_grub_param;
291
292 #pragma pack()
293
294 int grub_ext_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list);
295 int grub_fat_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list);
296 void grub_iso9660_set_nojoliet(int nojoliet);
297 int grub_iso9660_is_joliet(void);
298 grub_uint64_t grub_iso9660_get_last_read_pos(grub_file_t file);
299 grub_uint64_t grub_iso9660_get_last_file_dirent_pos(grub_file_t file);
300 grub_uint64_t grub_udf_get_file_offset(grub_file_t file);
301 grub_uint64_t grub_udf_get_last_pd_size_offset(void);
302 grub_uint64_t grub_udf_get_last_file_attr_offset
303 (
304 grub_file_t file,
305 grub_uint32_t *startBlock,
306 grub_uint64_t *fe_entry_size_offset
307 );
308 int ventoy_is_efi_os(void);
309 void ventoy_memfile_env_set(const char *prefix, const void *buf, unsigned long long len);
310
311 #endif /* __VENTOY_H__ */
312