1 /******************************************************************************
4 * Copyright (c) 2022, 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/>.
21 #ifndef __VTOYTOOL_H__
22 #define __VTOYTOOL_H__
24 #define IS_DIGIT(x) ((x) >= '0' && (x) <= '9')
28 typedef unsigned long long uint64_t;
30 typedef unsigned int uint32_t;
31 typedef unsigned short uint16_t;
32 typedef unsigned char uint8_t;
35 #define VENTOY_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
37 typedef enum ventoy_fs_type
39 ventoy_fs_exfat
= 0, /* 0: exfat */
40 ventoy_fs_ntfs
, /* 1: NTFS */
41 ventoy_fs_ext
, /* 2: ext2/ext3/ext4 */
42 ventoy_fs_xfs
, /* 3: XFS */
43 ventoy_fs_udf
, /* 4: UDF */
44 ventoy_fs_fat
, /* 5: FAT */
51 typedef struct ventoy_guid
60 typedef struct ventoy_image_disk_region
62 uint32_t image_sector_count
; /* image sectors contained in this region */
63 uint32_t image_start_sector
; /* image sector start */
64 uint64_t disk_start_sector
; /* disk sector start */
65 }ventoy_image_disk_region
;
67 typedef struct ventoy_image_location
71 /* image sector size, currently this value is always 2048 */
72 uint32_t image_sector_size
;
74 /* disk sector size, normally the value is 512 */
75 uint32_t disk_sector_size
;
77 uint32_t region_count
;
81 * If the image file has more than one fragments in disk,
82 * there will be more than one region data here.
83 * You can calculate the region count by
85 ventoy_image_disk_region regions
[1];
87 /* ventoy_image_disk_region regions[2~region_count-1] */
88 }ventoy_image_location
;
90 typedef struct ventoy_os_param
92 ventoy_guid guid
; // VENTOY_GUID
93 uint8_t chksum
; // checksum
95 uint8_t vtoy_disk_guid
[16];
96 uint64_t vtoy_disk_size
; // disk size in bytes
97 uint16_t vtoy_disk_part_id
; // begin with 1
98 uint16_t vtoy_disk_part_type
; // 0:exfat 1:ntfs other: reserved
99 char vtoy_img_path
[384]; // It seems to be enough, utf-8 format
100 uint64_t vtoy_img_size
; // image file size in bytes
103 * Ventoy will write a copy of ventoy_image_location data into runtime memory
104 * this is the physically address and length of that memory.
105 * Address 0 means no such data exist.
106 * Address will be aligned by 4KB.
109 uint64_t vtoy_img_location_addr
;
110 uint32_t vtoy_img_location_len
;
112 uint8_t vtoy_reserved
[32]; // Internal use by ventoy
114 uint8_t vtoy_disk_signature
[4];
116 uint8_t reserved
[27];
121 int vtoy_find_disk_by_guid(ventoy_os_param
*param
, char *diskname
);