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 #define MAX_DISK_NUM 256
25 #define SIZE_1MB 1048576
26 #define SIZE_1GB 1073741824
28 #define VTOYIMG_PART_START_BYTES (1024 * 1024)
29 #define VTOYIMG_PART_START_SECTOR 2048
31 #define VTOYEFI_PART_BYTES (32 * 1024 * 1024)
32 #define VTOYEFI_PART_SECTORS 65536
34 #define VTOY_LOG_FILE "log.txt"
39 typedef struct vtoy_guid
47 typedef struct PART_TABLE
49 uint8_t Active
; // 0x00 0x80
52 uint16_t StartSector
: 6;
53 uint16_t StartCylinder
: 10;
58 uint16_t EndSector
: 6;
59 uint16_t EndCylinder
: 10;
61 uint32_t StartSectorId
;
65 typedef struct MBR_HEAD
67 uint8_t BootCode
[446];
68 PART_TABLE PartTbl
[4];
73 typedef struct VTOY_GPT_HDR
75 char Signature
[8]; /* EFI PART */
81 uint64_t EfiBackupLBA
;
82 uint64_t PartAreaStartLBA
;
83 uint64_t PartAreaEndLBA
;
85 uint64_t PartTblStartLBA
;
86 uint32_t PartTblTotNum
;
87 uint32_t PartTblEntryLen
;
89 uint8_t Reserved2
[420];
92 typedef struct VTOY_GPT_PART_TBL
102 typedef struct VTOY_GPT_INFO
106 VTOY_GPT_PART_TBL PartTbl
[128];
111 #define MBR_PART_STYLE 0
112 #define GPT_PART_STYLE 1
114 typedef struct disk_ventoy_data
118 char ventoy_ver
[32]; // 1.0.33 ...
119 int secure_boot_flag
;
120 uint64_t preserved_space
;
122 uint64_t part2_start_sector
;
124 int partition_style
; // MBR_PART_STYLE/GPT_PART_STYLE
125 VTOY_GPT_INFO gptinfo
;
126 uint8_t rsvdata
[4096];
130 typedef struct ventoy_disk
132 char disk_name
[32]; // sda
133 char disk_path
[64]; // /dev/sda
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
140 char disk_model
[256]; // Sandisk/Kingston ...
141 char human_readable_size
[32];
147 uint64_t size_in_byte
;
149 disk_ventoy_data vtoydata
;
153 typedef struct ventoy_guid
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)
175 #define vlog(fmt, args...) ventoy_syslog(VLOG_LOG, fmt, ##args)
176 #define vdebug(fmt, args...) ventoy_syslog(VLOG_DEBUG, fmt, ##args)
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
);
183 static inline void * zalloc(size_t n
)
186 if (p
) memset(p
, 0, n
);
191 #endif /* __VENTOY_DEFINE_H__ */