]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - LinuxGUI/Ventoy2Disk/Core/ventoy_define.h
update languages.ini and license
[Ventoy.git] / LinuxGUI / Ventoy2Disk / Core / ventoy_define.h
1 /******************************************************************************
2 * ventoy_define.h
3 *
4 * Copyright (c) 2021, 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 #ifndef __VENTOY_DEFINE_H__
21 #define __VENTOY_DEFINE_H__
22
23 #define MAX_DISK_NUM 256
24
25 #define SIZE_1MB 1048576
26 #define SIZE_1GB 1073741824
27
28 #define VTOYIMG_PART_START_BYTES (1024 * 1024)
29 #define VTOYIMG_PART_START_SECTOR 2048
30
31 #define VTOYEFI_PART_BYTES (32 * 1024 * 1024)
32 #define VTOYEFI_PART_SECTORS 65536
33
34 #define VTOY_LOG_FILE "log.txt"
35
36
37 #pragma pack(1)
38
39 typedef struct vtoy_guid
40 {
41 uint32_t data1;
42 uint16_t data2;
43 uint16_t data3;
44 uint8_t data4[8];
45 }vtoy_guid;
46
47 typedef struct PART_TABLE
48 {
49 uint8_t Active; // 0x00 0x80
50
51 uint8_t StartHead;
52 uint16_t StartSector : 6;
53 uint16_t StartCylinder : 10;
54
55 uint8_t FsFlag;
56
57 uint8_t EndHead;
58 uint16_t EndSector : 6;
59 uint16_t EndCylinder : 10;
60
61 uint32_t StartSectorId;
62 uint32_t SectorCount;
63 }PART_TABLE;
64
65 typedef struct MBR_HEAD
66 {
67 uint8_t BootCode[446];
68 PART_TABLE PartTbl[4];
69 uint8_t Byte55;
70 uint8_t ByteAA;
71 }MBR_HEAD;
72
73 typedef struct VTOY_GPT_HDR
74 {
75 char Signature[8]; /* EFI PART */
76 uint8_t Version[4];
77 uint32_t Length;
78 uint32_t Crc;
79 uint8_t Reserved1[4];
80 uint64_t EfiStartLBA;
81 uint64_t EfiBackupLBA;
82 uint64_t PartAreaStartLBA;
83 uint64_t PartAreaEndLBA;
84 vtoy_guid DiskGuid;
85 uint64_t PartTblStartLBA;
86 uint32_t PartTblTotNum;
87 uint32_t PartTblEntryLen;
88 uint32_t PartTblCrc;
89 uint8_t Reserved2[420];
90 }VTOY_GPT_HDR;
91
92 typedef struct VTOY_GPT_PART_TBL
93 {
94 vtoy_guid PartType;
95 vtoy_guid PartGuid;
96 uint64_t StartLBA;
97 uint64_t LastLBA;
98 uint64_t Attr;
99 uint16_t Name[36];
100 }VTOY_GPT_PART_TBL;
101
102 typedef struct VTOY_GPT_INFO
103 {
104 MBR_HEAD MBR;
105 VTOY_GPT_HDR Head;
106 VTOY_GPT_PART_TBL PartTbl[128];
107 }VTOY_GPT_INFO;
108 #pragma pack()
109
110
111 #define MBR_PART_STYLE 0
112 #define GPT_PART_STYLE 1
113
114 typedef struct disk_ventoy_data
115 {
116 int ventoy_valid;
117
118 char ventoy_ver[32]; // 1.0.33 ...
119 int secure_boot_flag;
120 uint64_t preserved_space;
121
122 uint64_t part2_start_sector;
123
124 int partition_style; // MBR_PART_STYLE/GPT_PART_STYLE
125 VTOY_GPT_INFO gptinfo;
126 uint8_t rsvdata[4096];
127 }disk_ventoy_data;
128
129
130 typedef struct ventoy_disk
131 {
132 char disk_name[32]; // sda
133 char disk_path[64]; // /dev/sda
134
135 char part1_name[32]; // sda1
136 char part1_path[64]; // /dev/sda1
137 char part2_name[32]; // sda2
138 char part2_path[64]; // /dev/sda2
139
140 char disk_model[256]; // Sandisk/Kingston ...
141 char human_readable_size[32];
142
143 int major;
144 int minor;
145 int type;
146 int partstyle;
147 uint64_t size_in_byte;
148
149 disk_ventoy_data vtoydata;
150 }ventoy_disk;
151
152 #pragma pack(1)
153 typedef struct ventoy_guid
154 {
155 uint32_t data1;
156 uint16_t data2;
157 uint16_t data3;
158 uint8_t data4[8];
159 }ventoy_guid;
160 #pragma pack()
161
162 #ifndef O_BINARY
163 #define O_BINARY 0
164 #endif
165
166 #define VLOG_LOG 1
167 #define VLOG_DEBUG 2
168
169 #define ulong unsigned long
170 #define _ll long long
171 #define _ull unsigned long long
172 #define strlcpy(dst, src) strncpy(dst, src, sizeof(dst) - 1)
173 #define scnprintf(dst, fmt, args...) snprintf(dst, sizeof(dst) - 1, fmt, ##args)
174
175 #define vlog(fmt, args...) ventoy_syslog(VLOG_LOG, fmt, ##args)
176 #define vdebug(fmt, args...) ventoy_syslog(VLOG_DEBUG, fmt, ##args)
177
178 void ventoy_syslog(int level, const char *Fmt, ...);
179 void ventoy_set_loglevel(int level);
180 uint32_t ventoy_crc32(void *Buffer, uint32_t Length);
181
182
183 static inline void * zalloc(size_t n)
184 {
185 void *p = malloc(n);
186 if (p) memset(p, 0, n);
187 return p;
188 }
189
190
191 #endif /* __VENTOY_DEFINE_H__ */
192