]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - vtoycli/vtoycli.h
Adding root user check to ExtendPersistentImg (as in CreatePersistentImg) (#2633)
[Ventoy.git] / vtoycli / vtoycli.h
1 /******************************************************************************
2 * vtoycli.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
21 #ifndef __VTOYCLI_H__
22 #define __VTOYCLI_H__
23
24 #define VENTOY_EFI_PART_ATTR 0xC000000000000001ULL
25
26 #define SIZE_1MB (1024 * 1024)
27 #define VENTOY_EFI_PART_SIZE (32 * SIZE_1MB)
28
29 #define check_free(p) if (p) free(p)
30 #define check_close(fd) if (fd >= 0) close(fd)
31
32 #define VOID void
33 #define CHAR char
34 #define UINT64 unsigned long long
35 #define UINT32 unsigned int
36 #define UINT16 unsigned short
37 #define CHAR16 unsigned short
38 #define UINT8 unsigned char
39
40 UINT32 VtoyCrc32(VOID *Buffer, UINT32 Length);
41
42 #define COMPILE_ASSERT(expr) extern char __compile_assert[(expr) ? 1 : -1]
43
44 #pragma pack(1)
45
46 typedef struct PART_TABLE
47 {
48 UINT8 Active;
49
50 UINT8 StartHead;
51 UINT16 StartSector : 6;
52 UINT16 StartCylinder : 10;
53
54 UINT8 FsFlag;
55
56 UINT8 EndHead;
57 UINT16 EndSector : 6;
58 UINT16 EndCylinder : 10;
59
60 UINT32 StartSectorId;
61 UINT32 SectorCount;
62 }PART_TABLE;
63
64 typedef struct MBR_HEAD
65 {
66 UINT8 BootCode[446];
67 PART_TABLE PartTbl[4];
68 UINT8 Byte55;
69 UINT8 ByteAA;
70 }MBR_HEAD;
71
72 typedef struct GUID
73 {
74 UINT32 data1;
75 UINT16 data2;
76 UINT16 data3;
77 UINT8 data4[8];
78 }GUID;
79
80 typedef struct VTOY_GPT_HDR
81 {
82 CHAR Signature[8]; /* EFI PART */
83 UINT8 Version[4];
84 UINT32 Length;
85 UINT32 Crc;
86 UINT8 Reserved1[4];
87 UINT64 EfiStartLBA;
88 UINT64 EfiBackupLBA;
89 UINT64 PartAreaStartLBA;
90 UINT64 PartAreaEndLBA;
91 GUID DiskGuid;
92 UINT64 PartTblStartLBA;
93 UINT32 PartTblTotNum;
94 UINT32 PartTblEntryLen;
95 UINT32 PartTblCrc;
96 UINT8 Reserved2[420];
97 }VTOY_GPT_HDR;
98
99 COMPILE_ASSERT(sizeof(VTOY_GPT_HDR) == 512);
100
101 typedef struct VTOY_GPT_PART_TBL
102 {
103 GUID PartType;
104 GUID PartGuid;
105 UINT64 StartLBA;
106 UINT64 LastLBA;
107 UINT64 Attr;
108 CHAR16 Name[36];
109 }VTOY_GPT_PART_TBL;
110 COMPILE_ASSERT(sizeof(VTOY_GPT_PART_TBL) == 128);
111
112 typedef struct VTOY_GPT_INFO
113 {
114 MBR_HEAD MBR;
115 VTOY_GPT_HDR Head;
116 VTOY_GPT_PART_TBL PartTbl[128];
117 }VTOY_GPT_INFO;
118
119 typedef struct VTOY_BK_GPT_INFO
120 {
121 VTOY_GPT_PART_TBL PartTbl[128];
122 VTOY_GPT_HDR Head;
123 }VTOY_BK_GPT_INFO;
124
125 COMPILE_ASSERT(sizeof(VTOY_GPT_INFO) == 512 * 34);
126 COMPILE_ASSERT(sizeof(VTOY_BK_GPT_INFO) == 512 * 33);
127
128 #pragma pack()
129
130 UINT32 VtoyCrc32(VOID *Buffer, UINT32 Length);
131 int vtoygpt_main(int argc, char **argv);
132 int vtoyfat_main(int argc, char **argv);
133 int partresize_main(int argc, char **argv);
134 void ventoy_gen_preudo_uuid(void *uuid);
135 UINT64 get_disk_size_in_byte(const char *disk);
136
137 #endif /* __VTOYCLI_H__ */
138