]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Plugson/src/Core/ventoy_define.h
Disable Fn/L/Ctrl hotkeys when selecting auto install script or perssitence file.
[Ventoy.git] / Plugson / src / 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 #if defined(_MSC_VER) || defined(WIN32)
24 #include <windows.h>
25 #include <stdint.h>
26 #else
27 #include <stdint.h>
28 #include <stdarg.h>
29 #include <errno.h>
30 #include <string.h>
31 #include <unistd.h>
32 #include <pthread.h>
33 #include <time.h>
34 #include <linux/limits.h>
35 #endif
36
37 #define LOG_FILE "VentoyPlugson.log"
38
39 #define SIZE_1MB 1048576
40 #define SIZE_1GB 1073741824
41 #define JSON_BUF_MAX (8 * SIZE_1MB)
42 #define TAR_BUF_MAX (8 * SIZE_1MB)
43
44 #define VTOYIMG_PART_START_BYTES (1024 * 1024)
45 #define VTOYIMG_PART_START_SECTOR 2048
46
47 #define VTOYEFI_PART_BYTES (32 * 1024 * 1024)
48 #define VTOYEFI_PART_SECTORS 65536
49
50
51 #pragma pack(1)
52
53 typedef struct vtoy_guid
54 {
55 uint32_t data1;
56 uint16_t data2;
57 uint16_t data3;
58 uint8_t data4[8];
59 }vtoy_guid;
60
61 typedef struct PART_TABLE
62 {
63 uint8_t Active; // 0x00 0x80
64
65 uint8_t StartHead;
66 uint16_t StartSector : 6;
67 uint16_t StartCylinder : 10;
68
69 uint8_t FsFlag;
70
71 uint8_t EndHead;
72 uint16_t EndSector : 6;
73 uint16_t EndCylinder : 10;
74
75 uint32_t StartSectorId;
76 uint32_t SectorCount;
77 }PART_TABLE;
78
79 typedef struct MBR_HEAD
80 {
81 uint8_t BootCode[446];
82 PART_TABLE PartTbl[4];
83 uint8_t Byte55;
84 uint8_t ByteAA;
85 }MBR_HEAD;
86
87 typedef struct VTOY_GPT_HDR
88 {
89 char Signature[8]; /* EFI PART */
90 uint8_t Version[4];
91 uint32_t Length;
92 uint32_t Crc;
93 uint8_t Reserved1[4];
94 uint64_t EfiStartLBA;
95 uint64_t EfiBackupLBA;
96 uint64_t PartAreaStartLBA;
97 uint64_t PartAreaEndLBA;
98 vtoy_guid DiskGuid;
99 uint64_t PartTblStartLBA;
100 uint32_t PartTblTotNum;
101 uint32_t PartTblEntryLen;
102 uint32_t PartTblCrc;
103 uint8_t Reserved2[420];
104 }VTOY_GPT_HDR;
105
106 typedef struct VTOY_GPT_PART_TBL
107 {
108 vtoy_guid PartType;
109 vtoy_guid PartGuid;
110 uint64_t StartLBA;
111 uint64_t LastLBA;
112 uint64_t Attr;
113 uint16_t Name[36];
114 }VTOY_GPT_PART_TBL;
115
116 typedef struct VTOY_GPT_INFO
117 {
118 MBR_HEAD MBR;
119 VTOY_GPT_HDR Head;
120 VTOY_GPT_PART_TBL PartTbl[128];
121 }VTOY_GPT_INFO;
122 #pragma pack()
123
124
125 #define MBR_PART_STYLE 0
126 #define GPT_PART_STYLE 1
127
128 #pragma pack(1)
129 typedef struct ventoy_guid
130 {
131 uint32_t data1;
132 uint16_t data2;
133 uint16_t data3;
134 uint8_t data4[8];
135 }ventoy_guid;
136 #pragma pack()
137
138 #ifndef O_BINARY
139 #define O_BINARY 0
140 #endif
141
142 #define VLOG_LOG 1
143 #define VLOG_DEBUG 2
144
145 #define ulong unsigned long
146 #define _ll long long
147 #define _ull unsigned long long
148
149 #if defined(_MSC_VER) || defined(WIN32)
150 #define strlcpy(dst, src) strcpy_s(dst, sizeof(dst), src)
151 #define scnprintf(dst, len, fmt, ...) sprintf_s(dst, len, fmt, ##__VA_ARGS__)
152
153 #define vlog(fmt, ...) ventoy_syslog(VLOG_LOG, fmt, ##__VA_ARGS__)
154 #define vdebug(fmt, ...) ventoy_syslog(VLOG_DEBUG, fmt, ##__VA_ARGS__)
155
156 #define localtime_r(a,b) localtime_s(b,a)
157
158 #define LASTERR GetLastError()
159
160 #define CHECK_CLOSE_HANDLE(Handle) \
161 {\
162 if (Handle != INVALID_HANDLE_VALUE) \
163 {\
164 CloseHandle(Handle); \
165 Handle = INVALID_HANDLE_VALUE; \
166 }\
167 }
168
169 #else
170 #define strlcpy(dst, src) strncpy(dst, src, sizeof(dst) - 1)
171 #define scnprintf(dst, len, fmt, args...) snprintf(dst, len, fmt, ##args)
172
173 #define vlog(fmt, args...) ventoy_syslog(VLOG_LOG, fmt, ##args)
174 #define vdebug(fmt, args...) ventoy_syslog(VLOG_DEBUG, fmt, ##args)
175
176 #define MAX_PATH PATH_MAX
177
178 #endif
179
180 #define CHECK_FREE(p) \
181 {\
182 if (p)\
183 {\
184 free(p); \
185 (p) = NULL; \
186 }\
187 }
188
189 void ventoy_syslog(int level, const char *Fmt, ...);
190 void ventoy_set_loglevel(int level);
191 uint32_t ventoy_crc32(void *Buffer, uint32_t Length);
192
193
194 #if defined(_MSC_VER) || defined(WIN32)
195 static __inline void * zalloc(size_t n)
196 #else
197 static inline void * zalloc(size_t n)
198 #endif
199 {
200 void *p = malloc(n);
201 if (p) memset(p, 0, n);
202 return p;
203 }
204
205
206 #endif /* __VENTOY_DEFINE_H__ */
207