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
36 typedef struct vtoy_guid
44 typedef struct PART_TABLE
46 uint8_t Active
; // 0x00 0x80
49 uint16_t StartSector
: 6;
50 uint16_t StartCylinder
: 10;
55 uint16_t EndSector
: 6;
56 uint16_t EndCylinder
: 10;
58 uint32_t StartSectorId
;
62 typedef struct MBR_HEAD
64 uint8_t BootCode
[446];
65 PART_TABLE PartTbl
[4];
70 typedef struct VTOY_GPT_HDR
72 char Signature
[8]; /* EFI PART */
78 uint64_t EfiBackupLBA
;
79 uint64_t PartAreaStartLBA
;
80 uint64_t PartAreaEndLBA
;
82 uint64_t PartTblStartLBA
;
83 uint32_t PartTblTotNum
;
84 uint32_t PartTblEntryLen
;
86 uint8_t Reserved2
[420];
89 typedef struct VTOY_GPT_PART_TBL
99 typedef struct VTOY_GPT_INFO
103 VTOY_GPT_PART_TBL PartTbl
[128];
108 #define MBR_PART_STYLE 0
109 #define GPT_PART_STYLE 1
111 typedef struct disk_ventoy_data
115 char ventoy_ver
[32]; // 1.0.33 ...
116 int secure_boot_flag
;
117 uint64_t preserved_space
;
119 uint64_t part2_start_sector
;
121 int partition_style
; // MBR_PART_STYLE/GPT_PART_STYLE
122 VTOY_GPT_INFO gptinfo
;
123 uint8_t rsvdata
[4096];
127 typedef struct ventoy_disk
129 char disk_name
[32]; // sda
130 char disk_path
[64]; // /dev/sda
132 char part1_name
[32]; // sda1
133 char part1_path
[64]; // /dev/sda1
134 char part2_name
[32]; // sda2
135 char part2_path
[64]; // /dev/sda2
137 char disk_model
[256]; // Sandisk/Kingston ...
138 char human_readable_size
[32];
145 uint64_t size_in_byte
;
147 disk_ventoy_data vtoydata
;
151 typedef struct ventoy_guid
167 #define ulong unsigned long
168 #define _ll long long
169 #define _ull unsigned long long
170 #define strlcpy(dst, src) strncpy(dst, src, sizeof(dst) - 1)
171 #define scnprintf(dst, fmt, args...) snprintf(dst, sizeof(dst) - 1, 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 void ventoy_syslog(int level
, const char *Fmt
, ...);
177 void ventoy_set_loglevel(int level
);
178 uint32_t ventoy_crc32(void *Buffer
, uint32_t Length
);
181 static inline void * zalloc(size_t n
)
184 if (p
) memset(p
, 0, n
);
189 #endif /* __VENTOY_DEFINE_H__ */