mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-08-27 16:01:14 +00:00
Ventoy2Disk update:
1. Add UDF filesytem option. 2. Add Cluster Size option. 3. Support FAT32 for disk bigger than 32GB. 4. Fix the format fail issue. 5. Add a tip bubble with cluster size when mouse hover on the file system type string. 6. The secure boot lock character can not show in early Windows, change it to a yellow icon.
This commit is contained in:
@@ -109,17 +109,175 @@ BOOL DISK_ShrinkVolume(int DriveIndex, const char* VolumeGuid, CHAR DriveLetter,
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL DISK_FormatVolume(char DriveLetter, int fs)
|
||||
|
||||
|
||||
// Output command
|
||||
typedef struct
|
||||
{
|
||||
DWORD Lines;
|
||||
PCHAR Output;
|
||||
} TEXTOUTPUT, * PTEXTOUTPUT;
|
||||
|
||||
// Callback command types
|
||||
typedef enum
|
||||
{
|
||||
PROGRESS,
|
||||
DONEWITHSTRUCTURE,
|
||||
UNKNOWN2,
|
||||
UNKNOWN3,
|
||||
UNKNOWN4,
|
||||
UNKNOWN5,
|
||||
INSUFFICIENTRIGHTS,
|
||||
UNKNOWN7,
|
||||
UNKNOWN8,
|
||||
UNKNOWN9,
|
||||
UNKNOWNA,
|
||||
DONE,
|
||||
UNKNOWNC,
|
||||
UNKNOWND,
|
||||
OUTPUT,
|
||||
STRUCTUREPROGRESS
|
||||
} CALLBACKCOMMAND;
|
||||
|
||||
// FMIFS callback definition
|
||||
typedef BOOLEAN(__stdcall* PFMIFSCALLBACK)(CALLBACKCOMMAND Command, DWORD SubAction, PVOID ActionInfo);
|
||||
|
||||
|
||||
// Chkdsk command in FMIFS
|
||||
typedef VOID(__stdcall* PCHKDSK)(PWCHAR DriveRoot,
|
||||
PWCHAR Format,
|
||||
BOOL CorrectErrors,
|
||||
BOOL Verbose,
|
||||
BOOL CheckOnlyIfDirty,
|
||||
BOOL ScanDrive,
|
||||
PVOID Unused2,
|
||||
PVOID Unused3,
|
||||
PFMIFSCALLBACK Callback);
|
||||
|
||||
|
||||
// media flags
|
||||
#define FMIFS_HARDDISK 0xC
|
||||
#define FMIFS_FLOPPY 0x8
|
||||
// Format command in FMIFS
|
||||
typedef VOID(__stdcall* PFORMATEX)(PWCHAR DriveRoot,
|
||||
DWORD MediaFlag,
|
||||
PWCHAR Format,
|
||||
PWCHAR Label,
|
||||
BOOL QuickFormat,
|
||||
DWORD ClusterSize,
|
||||
PFMIFSCALLBACK Callback);
|
||||
|
||||
|
||||
// FormatExCallback
|
||||
static int g_dll_format_error = 0;
|
||||
BOOLEAN __stdcall FormatExCallback(CALLBACKCOMMAND Command, DWORD Modifier, PVOID Argument)
|
||||
{
|
||||
PDWORD percent;
|
||||
PBOOLEAN status;
|
||||
|
||||
switch (Command)
|
||||
{
|
||||
case PROGRESS:
|
||||
percent = (PDWORD)Argument;
|
||||
Log("Format percent: %d \n", *percent);
|
||||
break;
|
||||
|
||||
case OUTPUT:
|
||||
break;
|
||||
|
||||
case DONE:
|
||||
status = (PBOOLEAN)Argument;
|
||||
if (*status == FALSE)
|
||||
{
|
||||
g_dll_format_error = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOL DLL_FormatVolume(char DriveLetter, int fs, DWORD ClusterSize)
|
||||
{
|
||||
PWCHAR Label = L"Ventoy";
|
||||
PWCHAR Format = NULL;
|
||||
WCHAR RootDirectory[MAX_PATH] = { 0 };
|
||||
HMODULE ifsModule;
|
||||
PFORMATEX FormatEx;
|
||||
|
||||
ifsModule = LoadLibraryA("fmifs.dll");
|
||||
if (NULL == ifsModule)
|
||||
{
|
||||
Log("LoadLibrary fmifs.dll failed %u", LASTERR);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Log("Find ifsModule");
|
||||
|
||||
FormatEx = (PFORMATEX)GetProcAddress(ifsModule, "FormatEx");
|
||||
if (FormatEx == NULL)
|
||||
{
|
||||
Log("Failed to get FormatEx handler\n");
|
||||
return FALSE;
|
||||
}
|
||||
Log("Find FormatEx=%p", FormatEx);
|
||||
|
||||
RootDirectory[0] = DriveLetter;
|
||||
RootDirectory[1] = L':';
|
||||
RootDirectory[2] = L'\\';
|
||||
RootDirectory[3] = (WCHAR)0;
|
||||
|
||||
DWORD media;
|
||||
DWORD driveType;
|
||||
driveType = GetDriveTypeW(RootDirectory);
|
||||
if (driveType != DRIVE_FIXED)
|
||||
media = FMIFS_FLOPPY;
|
||||
if (driveType == DRIVE_FIXED)
|
||||
media = FMIFS_HARDDISK;
|
||||
|
||||
Format = GetVentoyFsFmtNameByTypeW(fs);
|
||||
|
||||
g_dll_format_error = 0;
|
||||
|
||||
Log("Call FormatEx Function for %C: %s ClusterSize=%u(%uKB)", DriveLetter, GetVentoyFsFmtNameByTypeA(fs), ClusterSize, ClusterSize / 1024);
|
||||
FormatEx(RootDirectory, media, Format, Label, TRUE, ClusterSize, FormatExCallback);
|
||||
FreeLibrary(ifsModule);
|
||||
|
||||
if (g_dll_format_error)
|
||||
{
|
||||
Log("Format failed by DLL");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Log("Format success by DLL");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOL DISK_FormatVolume(char DriveLetter, int fs, UINT64 VolumeSize)
|
||||
{
|
||||
DWORD ClusterSize = 0;
|
||||
BOOL ret = FALSE;
|
||||
|
||||
//ret = VDS_FormatVolume(DriveLetter, fs);
|
||||
ClusterSize = (DWORD)GetClusterSize();
|
||||
Log("DISK_FormatVolume %C:\\ %s VolumeSize=%llu ClusterSize=%u(%uKB)",
|
||||
DriveLetter, GetVentoyFsNameByType(fs), (ULONGLONG)VolumeSize, ClusterSize, ClusterSize/1024);
|
||||
|
||||
ret = DLL_FormatVolume(DriveLetter, fs, ClusterSize);
|
||||
if (!ret)
|
||||
{
|
||||
//ret = DSPT_FormatVolume(DriveLetter, fs);
|
||||
ret = VDS_FormatVolume(DriveLetter, fs, ClusterSize);
|
||||
if (!ret)
|
||||
{
|
||||
ret = PSHELL_FormatVolume(DriveLetter, fs);
|
||||
ret = DSPT_FormatVolume(DriveLetter, fs, ClusterSize);
|
||||
if (!ret)
|
||||
{
|
||||
ret = PSHELL_FormatVolume(DriveLetter, fs, ClusterSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -30,6 +30,7 @@ typedef struct VDS_PARA
|
||||
ULONG NameLen;
|
||||
ULONGLONG Offset;
|
||||
CHAR DriveLetter;
|
||||
DWORD ClusterSize;
|
||||
}VDS_PARA;
|
||||
|
||||
//DISK API
|
||||
@@ -39,7 +40,7 @@ BOOL DISK_ChangeVtoyEFIAttr(int DriveIndex, UINT64 Offset, UINT64 Attr);
|
||||
BOOL DISK_ChangeVtoyEFI2ESP(int DriveIndex, UINT64 Offset);
|
||||
BOOL DISK_ChangeVtoyEFI2Basic(int DriveIndex, UINT64 Offset);
|
||||
BOOL DISK_ShrinkVolume(int DriveIndex, const char* VolumeGuid, CHAR DriveLetter, UINT64 OldBytes, UINT64 ReduceBytes);
|
||||
BOOL DISK_FormatVolume(char DriveLetter, int fs);
|
||||
BOOL DISK_FormatVolume(char DriveLetter, int fs, UINT64 VolumeSize);
|
||||
|
||||
|
||||
//VDS com
|
||||
@@ -51,11 +52,11 @@ BOOL VDS_ChangeVtoyEFI2ESP(int DriveIndex, UINT64 Offset);
|
||||
BOOL VDS_ChangeVtoyEFI2Basic(int DriveIndex, UINT64 Offset);
|
||||
BOOL VDS_ShrinkVolume(int DriveIndex, const char* VolumeGuid, CHAR DriveLetter, UINT64 OldBytes, UINT64 ReduceBytes);
|
||||
BOOL VDS_IsLastAvaliable(void);
|
||||
BOOL VDS_FormatVolume(char DriveLetter, int fs);
|
||||
BOOL VDS_FormatVolume(char DriveLetter, int fs, DWORD ClusterSize);
|
||||
|
||||
//diskpart.exe
|
||||
BOOL DSPT_CleanDisk(int DriveIndex);
|
||||
BOOL DSPT_FormatVolume(char DriveLetter, int fs);
|
||||
BOOL DSPT_FormatVolume(char DriveLetter, int fs, DWORD ClusterSize);
|
||||
|
||||
//powershell.exe
|
||||
BOOL PSHELL_CleanDisk(int DriveIndex);
|
||||
@@ -63,7 +64,7 @@ BOOL PSHELL_DeleteVtoyEFIPartition(int DriveIndex, UINT64 EfiPartOffset);
|
||||
BOOL PSHELL_ChangeVtoyEFI2ESP(int DriveIndex, UINT64 Offset);
|
||||
BOOL PSHELL_ChangeVtoyEFI2Basic(int DriveIndex, UINT64 Offset);
|
||||
BOOL PSHELL_ShrinkVolume(int DriveIndex, const char* VolumeGuid, CHAR DriveLetter, UINT64 OldBytes, UINT64 ReduceBytes);
|
||||
BOOL PSHELL_FormatVolume(char DriveLetter, int fs);
|
||||
BOOL PSHELL_FormatVolume(char DriveLetter, int fs, DWORD ClusterSize);
|
||||
|
||||
//
|
||||
// Internel define
|
||||
|
@@ -86,7 +86,7 @@ BOOL DSPT_CleanDisk(int DriveIndex)
|
||||
return DSPT_CommProc(CmdBuf);
|
||||
}
|
||||
|
||||
BOOL DSPT_FormatVolume(char DriveLetter, int fs)
|
||||
BOOL DSPT_FormatVolume(char DriveLetter, int fs, DWORD ClusterSize)
|
||||
{
|
||||
const char* fsname = NULL;
|
||||
CHAR CmdBuf[256];
|
||||
@@ -98,15 +98,18 @@ BOOL DSPT_FormatVolume(char DriveLetter, int fs)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (fs == 1)
|
||||
fsname = GetVentoyFsFmtNameByTypeA(fs);
|
||||
|
||||
if (ClusterSize > 0)
|
||||
{
|
||||
fsname = "NTFS";
|
||||
sprintf_s(CmdBuf, sizeof(CmdBuf), "select volume %C:\r\nformat FS=%s LABEL=Ventoy UNIT=%u QUICK OVERRIDE\r\n", DriveLetter, fsname, ClusterSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
fsname = "FAT32";
|
||||
sprintf_s(CmdBuf, sizeof(CmdBuf), "select volume %C:\r\nformat FS=%s LABEL=Ventoy QUICK OVERRIDE\r\n", DriveLetter, fsname);
|
||||
}
|
||||
|
||||
Log("Diskpart cmd:<%s>", CmdBuf);
|
||||
|
||||
sprintf_s(CmdBuf, sizeof(CmdBuf), "select volume %C:\r\nformat FS=%s LABEL=Ventoy QUICK OVERRIDE\r\n", DriveLetter, fsname);
|
||||
return DSPT_CommProc(CmdBuf);
|
||||
}
|
||||
|
@@ -1417,19 +1417,20 @@ BOOL VDS_ShrinkVolume(int DriveIndex, const char* VolumeGuid, CHAR DriveLetter,
|
||||
|
||||
STATIC BOOL VDS_CallBack_FormatVolume(void* pInterface, VDS_DISK_PROP* pDiskProp, UINT64 data)
|
||||
{
|
||||
int fs;
|
||||
HRESULT hr, hr2;
|
||||
ULONG completed;
|
||||
IVdsAsync* pAsync;
|
||||
IVdsVolumeMF3* pVolume = (IVdsVolumeMF3*)pInterface;
|
||||
WCHAR* pFs = NULL;
|
||||
WCHAR FsNTFS[32] = L"NTFS";
|
||||
WCHAR FsFAT32[32] = L"FAT32";
|
||||
VDS_PARA* VdsPara = (VDS_PARA*)data;
|
||||
|
||||
pFs = (VdsPara->Attr == 1) ? FsNTFS : FsFAT32;
|
||||
Log("VDS_CallBack_FormatVolume (%C:) (%llu) ...", VdsPara->DriveLetter, (ULONGLONG)VdsPara->Attr);
|
||||
fs = (int)VdsPara->Attr;
|
||||
pFs = GetVentoyFsFmtNameByTypeW(fs);
|
||||
|
||||
Log("VDS_CallBack_FormatVolume (%C:) (%s) ClusterSize:%u ...", VdsPara->DriveLetter, GetVentoyFsFmtNameByTypeA(fs), VdsPara->ClusterSize);
|
||||
|
||||
hr = IVdsVolumeMF3_FormatEx2(pVolume, pFs, 0, 0, L"Ventoy", VDS_FSOF_FORCE | VDS_FSOF_QUICK, &pAsync);
|
||||
hr = IVdsVolumeMF3_FormatEx2(pVolume, pFs, 0, VdsPara->ClusterSize, L"Ventoy", VDS_FSOF_FORCE | VDS_FSOF_QUICK, &pAsync);
|
||||
while (SUCCEEDED(hr))
|
||||
{
|
||||
hr = IVdsAsync_QueryStatus(pAsync, &hr2, &completed);
|
||||
@@ -1465,7 +1466,7 @@ STATIC BOOL VDS_CallBack_FormatVolume(void* pInterface, VDS_DISK_PROP* pDiskProp
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
BOOL VDS_FormatVolume(char DriveLetter, int fs)
|
||||
BOOL VDS_FormatVolume(char DriveLetter, int fs, DWORD ClusterSize)
|
||||
{
|
||||
int i;
|
||||
BOOL ret = FALSE;
|
||||
@@ -1495,6 +1496,7 @@ BOOL VDS_FormatVolume(char DriveLetter, int fs)
|
||||
|
||||
Para.Attr = fs;
|
||||
Para.DriveLetter = DriveLetter;
|
||||
Para.ClusterSize = ClusterSize;
|
||||
|
||||
ret = VDS_VolumeCommProc(INTF_VOLUME_MF3, wGuid, VDS_CallBack_FormatVolume, (UINT64)&Para);
|
||||
Log("VDS_FormatVolume %C: <%s> ret:%d (%s)", DriveLetter, VolumeGuid, ret, ret ? "SUCCESS" : "FAIL");
|
||||
|
@@ -256,25 +256,27 @@ BOOL PSHELL_ShrinkVolume(int DriveIndex, const char* VolumeGuid, CHAR DriveLette
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL PSHELL_FormatVolume(char DriveLetter, int fs)
|
||||
BOOL PSHELL_FormatVolume(char DriveLetter, int fs, DWORD ClusterSize)
|
||||
{
|
||||
BOOL ret;
|
||||
const char* fsname = NULL;
|
||||
CHAR CmdBuf[512];
|
||||
|
||||
if (fs == 1)
|
||||
fsname = GetVentoyFsFmtNameByTypeA(fs);
|
||||
|
||||
if (ClusterSize > 0)
|
||||
{
|
||||
fsname = "NTFS";
|
||||
sprintf_s(CmdBuf, sizeof(CmdBuf),
|
||||
"format-volume -DriveLetter %C -FileSystem %s -AllocationUnitSize %u -Force -NewFileSystemLabel Ventoy",
|
||||
DriveLetter, fsname, ClusterSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
fsname = "FAT32";
|
||||
sprintf_s(CmdBuf, sizeof(CmdBuf),
|
||||
"format-volume -DriveLetter %C -FileSystem %s -Force -NewFileSystemLabel Ventoy",
|
||||
DriveLetter, fsname);
|
||||
}
|
||||
|
||||
sprintf_s(CmdBuf, sizeof(CmdBuf),
|
||||
"format-volume -DriveLetter %C -FileSystem %s -Force -NewFileSystemLabel Ventoy",
|
||||
DriveLetter, fsname);
|
||||
|
||||
ret = PSHELL_CommProc(CmdBuf);
|
||||
Log("PSHELL_FormatVolume %C: ret:%d (%s)", DriveLetter, ret, ret ? "SUCCESS" : "FAIL");
|
||||
return ret;
|
||||
|
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include <Windows.h>
|
||||
#include <versionhelpers.h>
|
||||
#include "Ventoy2Disk.h"
|
||||
#include "Language.h"
|
||||
|
||||
@@ -33,13 +34,3 @@ const TCHAR * GetString(enum STR_ID ID)
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
static const UINT16 g_unicode_icon[UNICODE_BUTT][3] =
|
||||
{
|
||||
{ 0xD83D, 0xDD12, 0x0000 },
|
||||
};
|
||||
|
||||
const UINT16 * GetUnicodeIcon(icon)
|
||||
{
|
||||
return g_unicode_icon[icon];
|
||||
}
|
||||
|
@@ -88,6 +88,10 @@ typedef enum STR_ID
|
||||
|
||||
STR_PART_VENTOY_FS, //50
|
||||
|
||||
STR_PART_FS, //51
|
||||
STR_PART_CLUSTER, //52
|
||||
STR_PART_CLUSTER_DEFAULT, //53
|
||||
|
||||
STR_ID_MAX
|
||||
}STR_ID;
|
||||
|
||||
@@ -151,13 +155,4 @@ const TCHAR * GetString(enum STR_ID ID);
|
||||
|
||||
#define _G(a) GetString(a)
|
||||
|
||||
typedef enum UNICODE_ICON
|
||||
{
|
||||
UNICODE_LOCK = 0,
|
||||
UNICODE_BUTT
|
||||
}UNICODE_ICON;
|
||||
|
||||
const UINT16 * GetUnicodeIcon(icon);
|
||||
#define _UICON(i) GetUnicodeIcon(i)
|
||||
|
||||
#endif
|
||||
|
Binary file not shown.
@@ -1106,6 +1106,79 @@ static int WriteGrubStage1ToPhyDrive(HANDLE hDrive, int PartStyle)
|
||||
}
|
||||
|
||||
|
||||
static int FormatPart1LargeFAT32(UINT64 DiskSizeBytes, int CluserSize)
|
||||
{
|
||||
MKFS_PARM Option;
|
||||
FRESULT Ret;
|
||||
FATFS FS;
|
||||
|
||||
Option.fmt = FM_FAT32;
|
||||
Option.n_fat = 1;
|
||||
Option.align = 8;
|
||||
Option.n_root = 1;
|
||||
|
||||
if (CluserSize == 0)
|
||||
{
|
||||
// < 32GB select 32KB as cluster size
|
||||
// > 32GB select 128KB as cluster size
|
||||
if (DiskSizeBytes / 1024 / 1024 / 1024 <= 32)
|
||||
{
|
||||
Option.au_size = 32768;
|
||||
}
|
||||
else
|
||||
{
|
||||
Option.au_size = 131072;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Option.au_size = CluserSize;
|
||||
}
|
||||
|
||||
Log("Formatting Part1 large FAT32 ClusterSize:%u(%uKB) ...", CluserSize, CluserSize / 1024);
|
||||
|
||||
disk_io_reset_write_error();
|
||||
|
||||
Ret = f_mkfs(TEXT("0:"), &Option, 0, 8 * 1024 * 1024);
|
||||
if (FR_OK == Ret)
|
||||
{
|
||||
if (disk_io_is_write_error())
|
||||
{
|
||||
Log("Formatting Part1 large FAT32 failed, write error.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Log("Formatting Part1 large FAT32 success, now set label");
|
||||
|
||||
Ret = f_mount(&FS, TEXT("0:"), 1);
|
||||
if (FR_OK == Ret)
|
||||
{
|
||||
Log("f_mount SUCCESS");
|
||||
Ret = f_setlabel(TEXT("0:Ventoy"));
|
||||
if (FR_OK == Ret)
|
||||
{
|
||||
Log("f_setlabel SUCCESS");
|
||||
Ret = f_unmount(TEXT("0:"));
|
||||
Log("f_unmount %d %s", Ret, (FR_OK == Ret) ? "SUCCESS" : "FAILED");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("f_setlabel failed %d", Ret);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("f_mount failed %d", Ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Formatting Part1 large FAT32 failed");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int FormatPart1exFAT(UINT64 DiskSizeBytes)
|
||||
{
|
||||
@@ -1636,6 +1709,7 @@ int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int PartStyle, int TryId)
|
||||
UINT64 Part1StartSector = 0;
|
||||
UINT64 Part1SectorCount = 0;
|
||||
UINT64 Part2StartSector = 0;
|
||||
BOOL LargeFAT32 = FALSE;
|
||||
|
||||
Log("#####################################################");
|
||||
Log("InstallVentoy2PhyDrive try%d %s PhyDrive%d <<%s %s %dGB>>", TryId,
|
||||
@@ -1737,13 +1811,28 @@ int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int PartStyle, int TryId)
|
||||
Sleep(1000 * 5);
|
||||
}
|
||||
|
||||
Log("Formatting part1 exFAT ...");
|
||||
if (0 != FormatPart1exFAT(pPhyDrive->SizeInBytes))
|
||||
if (GetVentoyFsType() == VTOY_FS_FAT32 && (Part1SectorCount * 512 >= FAT32_MAX_LIMIT))
|
||||
{
|
||||
Log("FormatPart1exFAT failed.");
|
||||
rc = 1;
|
||||
goto End;
|
||||
Log("Formatting part1 large FAT32 ...");
|
||||
LargeFAT32 = TRUE;
|
||||
if (0 != FormatPart1LargeFAT32(pPhyDrive->SizeInBytes, GetClusterSize()))
|
||||
{
|
||||
Log("FormatPart1LargeFAT32 failed.");
|
||||
rc = 1;
|
||||
goto End;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Formatting part1 exFAT ...");
|
||||
if (0 != FormatPart1exFAT(pPhyDrive->SizeInBytes))
|
||||
{
|
||||
Log("FormatPart1exFAT failed.");
|
||||
rc = 1;
|
||||
goto End;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PROGRESS_BAR_SET_POS(PT_FORMAT_PART2);
|
||||
Log("Writing part2 FAT img ...");
|
||||
@@ -1867,21 +1956,34 @@ End:
|
||||
}
|
||||
}
|
||||
|
||||
if (GetVentoyFsType() > 0)
|
||||
if (state)
|
||||
{
|
||||
if (state)
|
||||
if (LargeFAT32)
|
||||
{
|
||||
Log("Reformat %C:\\ to %s", MountDrive, GetVentoyFsName());
|
||||
DISK_FormatVolume(MountDrive, GetVentoyFsType());
|
||||
Log("No need to reformat for large FAT32");
|
||||
pPhyDrive->VentoyFsClusterSize = GetVolumeClusterSize(MountDrive);
|
||||
}
|
||||
else if (DISK_FormatVolume(MountDrive, GetVentoyFsType(), Part1SectorCount * 512))
|
||||
{
|
||||
Log("Reformat %C:\\ to %s SUCCESS", MountDrive, GetVentoyFsName());
|
||||
pPhyDrive->VentoyFsClusterSize = GetVolumeClusterSize(MountDrive);
|
||||
|
||||
if ((GetVentoyFsType() != VTOY_FS_UDF) && (pPhyDrive->VentoyFsClusterSize < 2048))
|
||||
{
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
Log("### Invalid cluster size %d ###", pPhyDrive->VentoyFsClusterSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Can not reformat %s to %s", DriveName, GetVentoyFsName());
|
||||
Log("Reformat %C:\\ to %s FAILED", MountDrive, GetVentoyFsName());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("No need to reformat ventoy partition");
|
||||
Log("Can not reformat %s to %s", DriveName, GetVentoyFsName());
|
||||
}
|
||||
|
||||
Log("OK\n");
|
||||
|
Binary file not shown.
@@ -251,10 +251,34 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD *pMBR, UIN
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int GetVolumeClusterSize(char Drive)
|
||||
{
|
||||
CHAR Volume[32] = { 0 };
|
||||
DWORD SectorsPerCluster = 0;
|
||||
DWORD BytesPerSector = 0;
|
||||
DWORD NumberOfFreeClusters = 0;
|
||||
DWORD TotalNumberOfClusters = 0;
|
||||
|
||||
sprintf_s(Volume, sizeof(Volume), "%C:\\", Drive);
|
||||
|
||||
if (GetDiskFreeSpaceA(Volume, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters))
|
||||
{
|
||||
Log("GetVolumeClusterSize %s SUCCESS %u %u %u", Volume, SectorsPerCluster, BytesPerSector, SectorsPerCluster * BytesPerSector);
|
||||
return (int)(SectorsPerCluster * BytesPerSector);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("GetVolumeClusterSize %s failed err:%u", Volume, LASTERR);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int GetVentoyFsNameInPhyDrive(PHY_DRIVE_INFO* CurDrive)
|
||||
{
|
||||
int i = 0;
|
||||
UINT64 Offset;
|
||||
|
||||
CHAR Volume[128] = { 0 };
|
||||
CHAR FsName[MAX_PATH] = { 0 };
|
||||
|
||||
@@ -276,6 +300,8 @@ static int GetVentoyFsNameInPhyDrive(PHY_DRIVE_INFO* CurDrive)
|
||||
|
||||
if (Volume[0])
|
||||
{
|
||||
CurDrive->VentoyFsClusterSize = GetVolumeClusterSize(Volume[0]);
|
||||
|
||||
if (GetVolumeInformationA(Volume, NULL, 0, NULL, NULL, NULL, FsName, MAX_PATH))
|
||||
{
|
||||
if (_stricmp(FsName, "exFAT") == 0)
|
||||
|
@@ -23,7 +23,20 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef enum VTOY_FS
|
||||
{
|
||||
VTOY_FS_EXFAT = 0,
|
||||
VTOY_FS_NTFS,
|
||||
VTOY_FS_FAT32,
|
||||
VTOY_FS_UDF,
|
||||
VTOY_FS_BUTT
|
||||
}VTOY_FS;
|
||||
|
||||
#define FAT32_MAX_LIMIT (32 * 1073741824ULL)
|
||||
|
||||
#define SIZE_1KB (1024)
|
||||
#define SIZE_1GB (1024 * 1024 * 1024)
|
||||
#define SIZE_1TB (1024ULL * 1024ULL * 1024ULL * 1024ULL)
|
||||
#define SIZE_1MB (1024 * 1024)
|
||||
#define SIZE_2MB (2048 * 1024)
|
||||
#define VENTOY_EFI_PART_SIZE (32 * SIZE_1MB)
|
||||
@@ -160,6 +173,7 @@ typedef struct PHY_DRIVE_INFO
|
||||
|
||||
CHAR DriveLetters[64];
|
||||
|
||||
int VentoyFsClusterSize;
|
||||
CHAR VentoyFsType[16];
|
||||
CHAR VentoyVersion[32];
|
||||
|
||||
@@ -251,6 +265,7 @@ int INIT unxz(unsigned char *in, int in_size,
|
||||
unsigned char *out, int *in_used,
|
||||
void(*error)(char *x));
|
||||
void disk_io_set_param(HANDLE Handle, UINT64 SectorCount);
|
||||
int GetVolumeClusterSize(char Drive);
|
||||
|
||||
extern BOOL g_InputYes;
|
||||
INT_PTR CALLBACK YesDialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
|
||||
@@ -259,7 +274,14 @@ int GetReservedSpaceInMB(void);
|
||||
int IsPartNeed4KBAlign(void);
|
||||
int GetVentoyFsType(void);
|
||||
void SetVentoyFsType(int fs);
|
||||
int GetClusterSize(void);
|
||||
void SetClusterSize(int ClusterSize);
|
||||
WCHAR* GetClusterSizeTip(void);
|
||||
void FormatClusterSizeTip(int Size, WCHAR* pBuf, size_t len);
|
||||
const char* GetVentoyFsName(void);
|
||||
const char* GetVentoyFsNameByType(int fs);
|
||||
CHAR* GetVentoyFsFmtNameByTypeA(int fs);
|
||||
WCHAR* GetVentoyFsFmtNameByTypeW(int fs);
|
||||
int FindProcessOccupyDisk(HANDLE hDrive, PHY_DRIVE_INFO *pPhyDrive);
|
||||
int VentoyFillMBRLocation(UINT64 DiskSizeInBytes, UINT32 StartSectorId, UINT32 SectorCount, PART_TABLE *Table);
|
||||
int ClearVentoyFromPhyDrive(HWND hWnd, PHY_DRIVE_INFO *pPhyDrive, char *pDrvLetter);
|
||||
@@ -270,8 +292,6 @@ BOOL PartResizePreCheck(PHY_DRIVE_INFO** ppPhyDrive);
|
||||
liCurrentPosition.QuadPart = pos; \
|
||||
SetFilePointerEx(hDrive, liCurrentPosition, &liCurrentPosition, FILE_BEGIN)\
|
||||
|
||||
#define SECURE_ICON_STRING _UICON(UNICODE_LOCK)
|
||||
|
||||
extern int g_WriteImage;
|
||||
|
||||
#define VTSI_IMG_MAGIC 0x0000594F544E4556ULL // "VENTOY\0\0"
|
||||
|
Binary file not shown.
@@ -400,6 +400,7 @@
|
||||
<Image Include="res\icon2.ico" />
|
||||
<Image Include="Res\refresh.ico" />
|
||||
<Image Include="Res\secure.ico" />
|
||||
<Image Include="Res\secure2.ico" />
|
||||
<Image Include="Res\ventoy.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
@@ -180,5 +180,8 @@
|
||||
<Image Include="Res\secure.ico">
|
||||
<Filter>资源文件</Filter>
|
||||
</Image>
|
||||
<Image Include="Res\secure2.ico">
|
||||
<Filter>资源文件</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
</Project>
|
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user