]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Ventoy2Disk/Ventoy2Disk/Ventoy2Disk.h
1 /******************************************************************************
4 * Copyright (c) 2020, 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 __VENTOY2DISK_H__
22 #define __VENTOY2DISK_H__
26 #define SIZE_1MB (1024 * 1024)
27 #define VENTOY_EFI_PART_SIZE (32 * SIZE_1MB)
28 #define VENTOY_PART1_START_SECTOR 2048
30 #define VENTOY_FILE_BOOT_IMG "boot\\boot.img"
31 #define VENTOY_FILE_STG1_IMG "boot\\core.img.xz"
32 #define VENTOY_FILE_DISK_IMG "ventoy\\ventoy.disk.img.xz"
33 #define VENTOY_FILE_LOG "log.txt"
34 #define VENTOY_FILE_VERSION "ventoy\\version"
36 #define DRIVE_ACCESS_TIMEOUT 15000 // How long we should retry drive access (in ms)
37 #define DRIVE_ACCESS_RETRIES 150 // How many times we should retry
39 #define IsFileExist(Fmt, ...) IsPathExist(FALSE, Fmt, __VA_ARGS__)
40 #define IsDirExist(Fmt, ...) IsPathExist(TRUE, Fmt, __VA_ARGS__)
42 #define safe_sprintf(dst, fmt, ...) sprintf_s(dst, sizeof(dst), fmt, __VA_ARGS__)
43 #define safe_strcpy(dst, src) strcpy_s(dst, sizeof(dst), src)
45 #define CHECK_CLOSE_HANDLE(Handle) \
47 if (Handle != INVALID_HANDLE_VALUE) \
49 CloseHandle(Handle); \
50 Handle = INVALID_HANDLE_VALUE; \
54 #define LASTERR GetLastError()
57 typedef struct PART_TABLE
59 UINT8 Active
; // 0x00 0x80
62 UINT16 StartSector
: 6;
63 UINT16 StartCylinder
: 10;
69 UINT16 EndCylinder
: 10;
75 typedef struct MBR_HEAD
78 PART_TABLE PartTbl
[4];
84 #define VENTOY_MAX_PHY_DRIVE 128
86 typedef struct PHY_DRIVE_INFO
96 CHAR SerialNumber
[128];
97 STORAGE_BUS_TYPE BusType
;
100 CHAR VentoyVersion
[32];
104 typedef enum PROGRESS_POINT
111 PT_LOCK_VOLUME
= PT_FORMAT_PART1
,
114 PT_WRITE_VENTOY_START
,
115 PT_WRITE_VENTOY_FINISH
= PT_WRITE_VENTOY_START
+ 32,
124 #define PROGRESS_BAR_SET_POS(pos) SetProgressBarPos(pos)
126 extern PHY_DRIVE_INFO
*g_PhyDriveList
;
127 extern DWORD g_PhyDriveCount
;
128 extern int g_ForceOperation
;
129 extern HWND g_ProgressBarHwnd
;
131 void Log(const char *Fmt
, ...);
132 BOOL
IsPathExist(BOOL Dir
, const char *Fmt
, ...);
133 void DumpWindowsVersion(void);
134 const CHAR
* GetLocalVentoyVersion(void);
135 const CHAR
* ParseVentoyVersionFromString(CHAR
*Buf
);
136 CHAR
GetFirstUnusedDriveLetter(void);
137 const CHAR
* GetBusTypeString(STORAGE_BUS_TYPE Type
);
138 int VentoyGetLocalBootImg(MBR_HEAD
*pMBR
);
139 int GetHumanReadableGBSize(UINT64 SizeBytes
);
140 void TrimString(CHAR
*String
);
141 int VentoyFillMBR(UINT64 DiskSizeBytes
, MBR_HEAD
*pMBR
);
142 BOOL
IsVentoyLogicalDrive(CHAR DriveLetter
);
143 int GetRegDwordValue(HKEY Key
, LPCSTR SubKey
, LPCSTR ValueName
, DWORD
*pValue
);
144 int GetPhysicalDriveCount(void);
145 int GetAllPhysicalDriveInfo(PHY_DRIVE_INFO
*pDriveList
, DWORD
*pDriveCount
);
146 int GetPhyDriveByLogicalDrive(int DriveLetter
);
147 int GetVentoyVerInPhyDrive(const PHY_DRIVE_INFO
*pDriveInfo
, MBR_HEAD
*pMBR
, CHAR
*VerBuf
, size_t BufLen
);
148 int Ventoy2DiskInit(void);
149 int Ventoy2DiskDestroy(void);
150 PHY_DRIVE_INFO
* GetPhyDriveInfoById(int Id
);
151 int ParseCmdLineOption(LPSTR lpCmdLine
);
152 int InstallVentoy2PhyDrive(PHY_DRIVE_INFO
*pPhyDrive
);
153 int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO
*pPhyDrive
);
154 void SetProgressBarPos(int Pos
);
155 int ReadWholeFileToBuf(const CHAR
*FileName
, int ExtLen
, void **Bufer
, int *BufLen
);
156 int INIT
unxz(unsigned char *in
, int in_size
,
157 int(*fill
)(void *dest
, unsigned int size
),
158 int(*flush
)(void *src
, unsigned int size
),
159 unsigned char *out
, int *in_used
,
160 void(*error
)(char *x
));
161 void disk_io_set_param(HANDLE Handle
, UINT64 SectorCount
);
162 INT_PTR CALLBACK
PartDialogProc(HWND hWnd
, UINT Message
, WPARAM wParam
, LPARAM lParam
);
163 int GetReservedSpaceInMB(void);
164 int FindProcessOccupyDisk(HANDLE hDrive
, PHY_DRIVE_INFO
*pPhyDrive
);
165 int VentoyFillLocation(UINT64 DiskSizeInBytes
, UINT32 StartSectorId
, UINT32 SectorCount
, PART_TABLE
*Table
);
166 int ClearVentoyFromPhyDrive(HWND hWnd
, PHY_DRIVE_INFO
*pPhyDrive
, char *pDrvLetter
);
168 #define SET_FILE_POS(pos) \
169 liCurrentPosition.QuadPart = pos; \
170 SetFilePointerEx(hDrive, liCurrentPosition, &liCurrentPosition, FILE_BEGIN)\