]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IPXE/ipxe_mod_code/ipxe-3fe683e/src/include/ventoy.h
1.0.14 release
[Ventoy.git] / IPXE / ipxe_mod_code / ipxe-3fe683e / src / include / ventoy.h
1
2 #ifndef __VENTOY_VDISK_H__
3 #define __VENTOY_VDISK_H__
4
5 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
6
7 #define grub_uint64_t uint64_t
8 #define grub_uint32_t uint32_t
9 #define grub_uint16_t uint16_t
10 #define grub_uint8_t uint8_t
11
12 #define COMPILE_ASSERT(expr) extern char __compile_assert[(expr) ? 1 : -1]
13
14 #define VENTOY_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
15
16 #pragma pack(1)
17
18 typedef struct ventoy_guid
19 {
20 grub_uint32_t data1;
21 grub_uint16_t data2;
22 grub_uint16_t data3;
23 grub_uint8_t data4[8];
24 }ventoy_guid;
25
26 typedef struct ventoy_image_disk_region
27 {
28 grub_uint32_t image_sector_count; /* image sectors contained in this region */
29 grub_uint32_t image_start_sector; /* image sector start */
30 grub_uint64_t disk_start_sector; /* disk sector start */
31 }ventoy_image_disk_region;
32
33 typedef struct ventoy_image_location
34 {
35 ventoy_guid guid;
36
37 /* image sector size, currently this value is always 2048 */
38 grub_uint32_t image_sector_size;
39
40 /* disk sector size, normally the value is 512 */
41 grub_uint32_t disk_sector_size;
42
43 grub_uint32_t region_count;
44
45 /*
46 * disk region data
47 * If the image file has more than one fragments in disk,
48 * there will be more than one region data here.
49 *
50 */
51 ventoy_image_disk_region regions[1];
52
53 /* ventoy_image_disk_region regions[2~region_count-1] */
54 }ventoy_image_location;
55
56 typedef struct ventoy_os_param
57 {
58 ventoy_guid guid; // VENTOY_GUID
59 grub_uint8_t chksum; // checksum
60
61 grub_uint8_t vtoy_disk_guid[16];
62 grub_uint64_t vtoy_disk_size; // disk size in bytes
63 grub_uint16_t vtoy_disk_part_id; // begin with 1
64 grub_uint16_t vtoy_disk_part_type; // 0:exfat 1:ntfs other: reserved
65 char vtoy_img_path[384]; // It seems to be enough, utf-8 format
66 grub_uint64_t vtoy_img_size; // image file size in bytes
67
68 /*
69 * Ventoy will write a copy of ventoy_image_location data into runtime memory
70 * this is the physically address and length of that memory.
71 * Address 0 means no such data exist.
72 * Address will be aligned by 4KB.
73 *
74 */
75 grub_uint64_t vtoy_img_location_addr;
76 grub_uint32_t vtoy_img_location_len;
77
78 grub_uint64_t vtoy_reserved[4]; // Internal use by ventoy
79
80 grub_uint8_t reserved[31];
81 }ventoy_os_param;
82
83 typedef struct ventoy_iso9660_override
84 {
85 uint32_t first_sector;
86 uint32_t first_sector_be;
87 uint32_t size;
88 uint32_t size_be;
89 }ventoy_iso9660_override;
90
91 #pragma pack()
92
93 // compile assert to check that size of ventoy_os_param must be 512
94 COMPILE_ASSERT(sizeof(ventoy_os_param) == 512);
95
96
97
98
99
100
101
102 #pragma pack(4)
103
104 typedef struct ventoy_chain_head
105 {
106 ventoy_os_param os_param;
107
108 grub_uint32_t disk_drive;
109 grub_uint32_t drive_map;
110 grub_uint32_t disk_sector_size;
111
112 grub_uint64_t real_img_size_in_bytes;
113 grub_uint64_t virt_img_size_in_bytes;
114 grub_uint32_t boot_catalog;
115 grub_uint8_t boot_catalog_sector[2048];
116
117 grub_uint32_t img_chunk_offset;
118 grub_uint32_t img_chunk_num;
119
120 grub_uint32_t override_chunk_offset;
121 grub_uint32_t override_chunk_num;
122
123 grub_uint32_t virt_chunk_offset;
124 grub_uint32_t virt_chunk_num;
125 }ventoy_chain_head;
126
127
128 typedef struct ventoy_img_chunk
129 {
130 grub_uint32_t img_start_sector; //2KB
131 grub_uint32_t img_end_sector;
132
133 grub_uint64_t disk_start_sector; // in disk_sector_size
134 grub_uint64_t disk_end_sector;
135 }ventoy_img_chunk;
136
137
138 typedef struct ventoy_override_chunk
139 {
140 grub_uint64_t img_offset;
141 grub_uint32_t override_size;
142 grub_uint8_t override_data[512];
143 }ventoy_override_chunk;
144
145 typedef struct ventoy_virt_chunk
146 {
147 grub_uint32_t mem_sector_start;
148 grub_uint32_t mem_sector_end;
149 grub_uint32_t mem_sector_offset;
150 grub_uint32_t remap_sector_start;
151 grub_uint32_t remap_sector_end;
152 grub_uint32_t org_sector_start;
153 }ventoy_virt_chunk;
154
155
156 #pragma pack()
157
158
159 #define ventoy_debug_pause() \
160 {\
161 printf("\nPress Ctrl+C to continue......");\
162 sleep(3600);\
163 printf("\n");\
164 }
165
166 typedef struct ventoy_sector_flag
167 {
168 uint8_t flag; // 0:init 1:mem 2:remap
169 uint64_t remap_lba;
170 }ventoy_sector_flag;
171
172 #define VENTOY_BIOS_FAKE_DRIVE 0xFE
173 #define VENTOY_BOOT_FIXBIN_DRIVE 0xFD
174
175 extern int g_debug;
176 extern char *g_cmdline_copy;
177 extern void *g_initrd_addr;
178 extern size_t g_initrd_len;
179 extern uint32_t g_disk_sector_size;
180 unsigned int ventoy_int13_hook (ventoy_chain_head *chain);
181 int ventoy_int13_boot ( unsigned int drive, void *imginfo, const char *cmdline);
182 void * ventoy_get_runtime_addr(void);
183 int ventoy_boot_vdisk(void *data);
184
185
186 uint32_t CalculateCrc32
187 (
188 const void *Buffer,
189 uint32_t Length,
190 uint32_t InitValue
191 );
192
193 struct smbios3_entry {
194
195 uint8_t signature[5];
196
197 /** Checksum */
198 uint8_t checksum;
199
200 /** Length */
201 uint8_t len;
202
203 /** Major version */
204 uint8_t major;
205
206 /** Minor version */
207 uint8_t minor;
208
209 uint8_t docrev;
210
211 uint8_t revision;
212
213 uint8_t reserved;
214
215 uint32_t maxsize;
216
217 uint64_t address;
218 } __attribute__ (( packed ));
219
220
221 typedef struct isolinux_boot_info
222 {
223 uint32_t isolinux0;
224 uint32_t isolinux1;
225 uint32_t PvdLocation;
226 uint32_t BootFileLocation;
227 uint32_t BootFileLen;
228 uint32_t BootFileChecksum;
229 uint8_t Reserved[40];
230 }isolinux_boot_info;
231
232 //#undef DBGLVL
233 //#define DBGLVL 7
234
235 #endif /* __VENTOY_VDISK_H__ */
236