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/>.
24 #define VENTOY_EFI_PART_ATTR 0x8000000000000000ULL
26 #define SIZE_1MB (1024 * 1024)
27 #define VENTOY_EFI_PART_SIZE (32 * SIZE_1MB)
29 #define check_free(p) if (p) free(p)
30 #define check_close(fd) if (fd >= 0) close(fd)
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
40 UINT32
VtoyCrc32(VOID
*Buffer
, UINT32 Length
);
42 #define COMPILE_ASSERT(expr) extern char __compile_assert[(expr) ? 1 : -1]
46 typedef struct PART_TABLE
51 UINT16 StartSector
: 6;
52 UINT16 StartCylinder
: 10;
58 UINT16 EndCylinder
: 10;
64 typedef struct MBR_HEAD
67 PART_TABLE PartTbl
[4];
80 typedef struct VTOY_GPT_HDR
82 CHAR Signature
[8]; /* EFI PART */
89 UINT64 PartAreaStartLBA
;
90 UINT64 PartAreaEndLBA
;
92 UINT64 PartTblStartLBA
;
94 UINT32 PartTblEntryLen
;
99 COMPILE_ASSERT(sizeof(VTOY_GPT_HDR
) == 512);
101 typedef struct VTOY_GPT_PART_TBL
110 COMPILE_ASSERT(sizeof(VTOY_GPT_PART_TBL
) == 128);
112 typedef struct VTOY_GPT_INFO
116 VTOY_GPT_PART_TBL PartTbl
[128];
119 typedef struct VTOY_BK_GPT_INFO
121 VTOY_GPT_PART_TBL PartTbl
[128];
125 COMPILE_ASSERT(sizeof(VTOY_GPT_INFO
) == 512 * 34);
126 COMPILE_ASSERT(sizeof(VTOY_BK_GPT_INFO
) == 512 * 33);
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
);
137 #endif /* __VTOYCLI_H__ */