1 /******************************************************************************
4 * Copyright (c) 2021, 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/>.
20 #ifndef __VENTOY_DEFINE_H__
21 #define __VENTOY_DEFINE_H__
23 #if defined(_MSC_VER) || defined(WIN32)
34 #include <linux/limits.h>
37 #define LOG_FILE "VentoyPlugson.log"
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)
44 #define VTOYIMG_PART_START_BYTES (1024 * 1024)
45 #define VTOYIMG_PART_START_SECTOR 2048
47 #define VTOYEFI_PART_BYTES (32 * 1024 * 1024)
48 #define VTOYEFI_PART_SECTORS 65536
53 typedef struct vtoy_guid
61 typedef struct PART_TABLE
63 uint8_t Active
; // 0x00 0x80
66 uint16_t StartSector
: 6;
67 uint16_t StartCylinder
: 10;
72 uint16_t EndSector
: 6;
73 uint16_t EndCylinder
: 10;
75 uint32_t StartSectorId
;
79 typedef struct MBR_HEAD
81 uint8_t BootCode
[446];
82 PART_TABLE PartTbl
[4];
87 typedef struct VTOY_GPT_HDR
89 char Signature
[8]; /* EFI PART */
95 uint64_t EfiBackupLBA
;
96 uint64_t PartAreaStartLBA
;
97 uint64_t PartAreaEndLBA
;
99 uint64_t PartTblStartLBA
;
100 uint32_t PartTblTotNum
;
101 uint32_t PartTblEntryLen
;
103 uint8_t Reserved2
[420];
106 typedef struct VTOY_GPT_PART_TBL
116 typedef struct VTOY_GPT_INFO
120 VTOY_GPT_PART_TBL PartTbl
[128];
125 #define MBR_PART_STYLE 0
126 #define GPT_PART_STYLE 1
129 typedef struct ventoy_guid
145 #define ulong unsigned long
146 #define _ll long long
147 #define _ull unsigned long long
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__)
153 #define vlog(fmt, ...) ventoy_syslog(VLOG_LOG, fmt, ##__VA_ARGS__)
154 #define vdebug(fmt, ...) ventoy_syslog(VLOG_DEBUG, fmt, ##__VA_ARGS__)
156 #define localtime_r(a,b) localtime_s(b,a)
158 #define LASTERR GetLastError()
160 #define CHECK_CLOSE_HANDLE(Handle) \
162 if (Handle != INVALID_HANDLE_VALUE) \
164 CloseHandle(Handle); \
165 Handle = INVALID_HANDLE_VALUE; \
170 #define strlcpy(dst, src) strncpy(dst, src, sizeof(dst) - 1)
171 #define scnprintf(dst, len, fmt, args...) snprintf(dst, len, fmt, ##args)
173 #define vlog(fmt, args...) ventoy_syslog(VLOG_LOG, fmt, ##args)
174 #define vdebug(fmt, args...) ventoy_syslog(VLOG_DEBUG, fmt, ##args)
176 #define MAX_PATH PATH_MAX
180 #define CHECK_FREE(p) \
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
);
194 #if defined(_MSC_VER) || defined(WIN32)
195 static __inline
void * zalloc(size_t n
)
197 static inline void * zalloc(size_t n
)
201 if (p
) memset(p
, 0, n
);
206 #endif /* __VENTOY_DEFINE_H__ */