mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-08-27 16:01:14 +00:00
1. Add new options for Windows CLI mode.
2. Add tip message for 4k native disk.
This commit is contained in:
@@ -94,6 +94,8 @@ typedef enum STR_ID
|
||||
|
||||
STR_DONATE, //54
|
||||
|
||||
STR_4KN_UNSUPPORTED, //55
|
||||
|
||||
STR_ID_MAX
|
||||
}STR_ID;
|
||||
|
||||
|
@@ -139,7 +139,7 @@ static DWORD GetVentoyVolumeName(int PhyDrive, UINT64 StartSectorId, CHAR *NameB
|
||||
return Status;
|
||||
}
|
||||
|
||||
static int GetLettersBelongPhyDrive(int PhyDrive, char *DriveLetters, size_t Length)
|
||||
int GetLettersBelongPhyDrive(int PhyDrive, char *DriveLetters, size_t Length)
|
||||
{
|
||||
int n = 0;
|
||||
DWORD DataSize = 0;
|
||||
@@ -355,6 +355,7 @@ int GetAllPhysicalDriveInfo(PHY_DRIVE_INFO *pDriveList, DWORD *pDriveCount)
|
||||
STORAGE_PROPERTY_QUERY Query;
|
||||
STORAGE_DESCRIPTOR_HEADER DevDescHeader;
|
||||
STORAGE_DEVICE_DESCRIPTOR *pDevDesc;
|
||||
STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR diskAlignment;
|
||||
int PhyDriveId[VENTOY_MAX_PHY_DRIVE];
|
||||
|
||||
Count = GetPhysicalDriveCount();
|
||||
@@ -468,12 +469,35 @@ int GetAllPhysicalDriveInfo(PHY_DRIVE_INFO *pDriveList, DWORD *pDriveCount)
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
memset(&Query, 0, sizeof(STORAGE_PROPERTY_QUERY));
|
||||
Query.PropertyId = StorageAccessAlignmentProperty;
|
||||
Query.QueryType = PropertyStandardQuery;
|
||||
memset(&diskAlignment, 0, sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR));
|
||||
|
||||
bRet = DeviceIoControl(Handle,
|
||||
IOCTL_STORAGE_QUERY_PROPERTY,
|
||||
&Query,
|
||||
sizeof(STORAGE_PROPERTY_QUERY),
|
||||
&diskAlignment,
|
||||
sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR),
|
||||
&dwBytes,
|
||||
NULL);
|
||||
if (!bRet)
|
||||
{
|
||||
Log("DeviceIoControl3 error:%u dwBytes:%u", LASTERR, dwBytes);
|
||||
}
|
||||
|
||||
CurDrive->PhyDrive = i;
|
||||
CurDrive->SizeInBytes = LengthInfo.Length.QuadPart;
|
||||
CurDrive->DeviceType = pDevDesc->DeviceType;
|
||||
CurDrive->RemovableMedia = pDevDesc->RemovableMedia;
|
||||
CurDrive->BusType = pDevDesc->BusType;
|
||||
|
||||
CurDrive->BytesPerLogicalSector = diskAlignment.BytesPerLogicalSector;
|
||||
CurDrive->BytesPerPhysicalSector = diskAlignment.BytesPerPhysicalSector;
|
||||
|
||||
if (pDevDesc->VendorIdOffset)
|
||||
{
|
||||
safe_strcpy(CurDrive->VendorId, (char *)pDevDesc + pDevDesc->VendorIdOffset);
|
||||
@@ -508,9 +532,10 @@ int GetAllPhysicalDriveInfo(PHY_DRIVE_INFO *pDriveList, DWORD *pDriveCount)
|
||||
|
||||
for (i = 0, CurDrive = pDriveList; i < (int)DriveCount; i++, CurDrive++)
|
||||
{
|
||||
Log("PhyDrv:%d BusType:%-4s Removable:%u Size:%dGB(%llu) Name:%s %s",
|
||||
Log("PhyDrv:%d BusType:%-4s Removable:%u Size:%dGB(%llu) Sector:%u/%u Name:%s %s",
|
||||
CurDrive->PhyDrive, GetBusTypeString(CurDrive->BusType), CurDrive->RemovableMedia,
|
||||
GetHumanReadableGBSize(CurDrive->SizeInBytes), CurDrive->SizeInBytes,
|
||||
CurDrive->BytesPerLogicalSector, CurDrive->BytesPerPhysicalSector,
|
||||
CurDrive->VendorId, CurDrive->ProductId);
|
||||
}
|
||||
|
||||
@@ -2351,30 +2376,37 @@ int PartitionResizeForVentoy(PHY_DRIVE_INFO *pPhyDrive)
|
||||
|
||||
Sleep(2000);
|
||||
|
||||
//Refresh disk list
|
||||
PhyDrive = pPhyDrive->PhyDrive;
|
||||
if (g_CLI_Mode)
|
||||
{
|
||||
Log("### Ventoy non-destructive CLI installation successfully finished.");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Refresh disk list
|
||||
PhyDrive = pPhyDrive->PhyDrive;
|
||||
|
||||
Log("#### Now Refresh PhyDrive ####");
|
||||
Ventoy2DiskDestroy();
|
||||
Ventoy2DiskInit();
|
||||
|
||||
pPhyDrive = GetPhyDriveInfoByPhyDrive(PhyDrive);
|
||||
if (pPhyDrive)
|
||||
{
|
||||
if (pPhyDrive->VentoyVersion[0] == 0)
|
||||
{
|
||||
Log("After process the Ventoy version is still invalid");
|
||||
goto End;
|
||||
}
|
||||
Log("#### Now Refresh PhyDrive ####");
|
||||
Ventoy2DiskDestroy();
|
||||
Ventoy2DiskInit();
|
||||
|
||||
Log("### Ventoy non-destructive installation successfully finished <%s>", pPhyDrive->VentoyVersion);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("### Ventoy non-destructive installation successfully finished <not found>");
|
||||
}
|
||||
pPhyDrive = GetPhyDriveInfoByPhyDrive(PhyDrive);
|
||||
if (pPhyDrive)
|
||||
{
|
||||
if (pPhyDrive->VentoyVersion[0] == 0)
|
||||
{
|
||||
Log("After process the Ventoy version is still invalid");
|
||||
goto End;
|
||||
}
|
||||
|
||||
InitComboxCtrl(g_DialogHwnd, PhyDrive);
|
||||
Log("### Ventoy non-destructive installation successfully finished <%s>", pPhyDrive->VentoyVersion);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("### Ventoy non-destructive installation successfully finished <not found>");
|
||||
}
|
||||
|
||||
InitComboxCtrl(g_DialogHwnd, PhyDrive);
|
||||
}
|
||||
|
||||
rc = 0;
|
||||
|
||||
|
@@ -40,6 +40,56 @@ void TraceOut(const char *Fmt, ...)
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct LogBuf
|
||||
{
|
||||
int Len;
|
||||
char szBuf[1024];
|
||||
struct LogBuf* next;
|
||||
}LogBuf;
|
||||
|
||||
static BOOL g_LogCache = FALSE;
|
||||
static LogBuf* g_LogHead = NULL;
|
||||
static LogBuf* g_LogTail = NULL;
|
||||
|
||||
void LogCache(BOOL cache)
|
||||
{
|
||||
g_LogCache = cache;
|
||||
}
|
||||
|
||||
void LogFlush(void)
|
||||
{
|
||||
FILE* File = NULL;
|
||||
LogBuf* Node = NULL;
|
||||
LogBuf* Next = NULL;
|
||||
|
||||
if (g_CLI_Mode)
|
||||
{
|
||||
fopen_s(&File, VENTOY_CLI_LOG, "a+");
|
||||
}
|
||||
else
|
||||
{
|
||||
fopen_s(&File, VENTOY_FILE_LOG, "a+");
|
||||
}
|
||||
|
||||
if (File)
|
||||
{
|
||||
for (Node = g_LogHead; Node; Node = Node->next)
|
||||
{
|
||||
fwrite(Node->szBuf, 1, Node->Len, File);
|
||||
fwrite("\n", 1, 1, File);
|
||||
}
|
||||
fclose(File);
|
||||
}
|
||||
|
||||
for (Node = g_LogHead; Node; Node = Next)
|
||||
{
|
||||
Next = Node->next;
|
||||
free(Node);
|
||||
}
|
||||
|
||||
g_LogHead = g_LogTail = NULL;
|
||||
}
|
||||
|
||||
void Log(const char *Fmt, ...)
|
||||
{
|
||||
va_list Arg;
|
||||
@@ -59,6 +109,30 @@ void Log(const char *Fmt, ...)
|
||||
Len += vsnprintf_s(szBuf + Len, sizeof(szBuf)-Len - 1, sizeof(szBuf)-Len-1, Fmt, Arg);
|
||||
va_end(Arg);
|
||||
|
||||
if (g_LogCache)
|
||||
{
|
||||
LogBuf* Node = NULL;
|
||||
Node = malloc(sizeof(LogBuf));
|
||||
if (Node)
|
||||
{
|
||||
memcpy(Node->szBuf, szBuf, Len);
|
||||
Node->next = NULL;
|
||||
Node->Len = Len;
|
||||
|
||||
if (g_LogTail)
|
||||
{
|
||||
g_LogTail->next = Node;
|
||||
g_LogTail = Node;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_LogHead = g_LogTail = Node;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_CLI_Mode)
|
||||
{
|
||||
fopen_s(&File, VENTOY_CLI_LOG, "a+");
|
||||
|
@@ -176,6 +176,9 @@ typedef struct PHY_DRIVE_INFO
|
||||
CHAR SerialNumber[128];
|
||||
STORAGE_BUS_TYPE BusType;
|
||||
|
||||
DWORD BytesPerLogicalSector;
|
||||
DWORD BytesPerPhysicalSector;
|
||||
|
||||
CHAR DriveLetters[64];
|
||||
|
||||
int VentoyFsClusterSize;
|
||||
@@ -234,6 +237,8 @@ extern int g_FilterUSB;
|
||||
|
||||
void TraceOut(const char *Fmt, ...);
|
||||
void Log(const char *Fmt, ...);
|
||||
void LogCache(BOOL cache);
|
||||
void LogFlush(void);
|
||||
BOOL IsPathExist(BOOL Dir, const char *Fmt, ...);
|
||||
void DumpWindowsVersion(void);
|
||||
const CHAR* GetLocalVentoyVersion(void);
|
||||
@@ -370,6 +375,15 @@ BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD* pMBR, UINT64* Pa
|
||||
int GetVentoyFsNameInPhyDrive(PHY_DRIVE_INFO* CurDrive);
|
||||
void CLISetReserveSpace(int MB);
|
||||
void CLI_UpdatePercent(int Pos);
|
||||
int GetLettersBelongPhyDrive(int PhyDrive, char* DriveLetters, size_t Length);
|
||||
PHY_DRIVE_INFO* CLI_PhyDrvInfo(void);
|
||||
|
||||
#define UTF8_Log(fmt, wstr) \
|
||||
{\
|
||||
memset(TmpPathA, 0, sizeof(TmpPathA));\
|
||||
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, TmpPathA, sizeof(TmpPathA), NULL, NULL);\
|
||||
Log(fmt, TmpPathA);\
|
||||
}
|
||||
|
||||
#define VTSI_SUPPORT 1
|
||||
|
||||
|
Binary file not shown.
@@ -17,12 +17,16 @@ typedef struct CLI_CFG
|
||||
int PartStyle;
|
||||
int ReserveMB;
|
||||
BOOL USBCheck;
|
||||
BOOL NonDest;
|
||||
int fstype;
|
||||
}CLI_CFG;
|
||||
|
||||
BOOL g_CLI_Mode = FALSE;
|
||||
static int g_CLI_OP;
|
||||
static int g_CLI_PhyDrive;
|
||||
|
||||
static PHY_DRIVE_INFO* g_CLI_PhyDrvInfo = NULL;
|
||||
|
||||
static int CLI_GetPhyDriveInfo(int PhyDrive, PHY_DRIVE_INFO* pInfo)
|
||||
{
|
||||
BOOL bRet;
|
||||
@@ -33,6 +37,7 @@ static int CLI_GetPhyDriveInfo(int PhyDrive, PHY_DRIVE_INFO* pInfo)
|
||||
STORAGE_PROPERTY_QUERY Query;
|
||||
STORAGE_DESCRIPTOR_HEADER DevDescHeader;
|
||||
STORAGE_DEVICE_DESCRIPTOR* pDevDesc;
|
||||
STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR diskAlignment;
|
||||
|
||||
safe_sprintf(PhyDrivePath, "\\\\.\\PhysicalDrive%d", PhyDrive);
|
||||
Handle = CreateFileA(PhyDrivePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
@@ -103,12 +108,35 @@ static int CLI_GetPhyDriveInfo(int PhyDrive, PHY_DRIVE_INFO* pInfo)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
memset(&Query, 0, sizeof(STORAGE_PROPERTY_QUERY));
|
||||
Query.PropertyId = StorageAccessAlignmentProperty;
|
||||
Query.QueryType = PropertyStandardQuery;
|
||||
memset(&diskAlignment, 0, sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR));
|
||||
|
||||
bRet = DeviceIoControl(Handle,
|
||||
IOCTL_STORAGE_QUERY_PROPERTY,
|
||||
&Query,
|
||||
sizeof(STORAGE_PROPERTY_QUERY),
|
||||
&diskAlignment,
|
||||
sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR),
|
||||
&dwBytes,
|
||||
NULL);
|
||||
if (!bRet)
|
||||
{
|
||||
Log("DeviceIoControl3 error:%u dwBytes:%u", LASTERR, dwBytes);
|
||||
}
|
||||
|
||||
|
||||
pInfo->PhyDrive = PhyDrive;
|
||||
pInfo->SizeInBytes = LengthInfo.Length.QuadPart;
|
||||
pInfo->DeviceType = pDevDesc->DeviceType;
|
||||
pInfo->RemovableMedia = pDevDesc->RemovableMedia;
|
||||
pInfo->BusType = pDevDesc->BusType;
|
||||
|
||||
pInfo->BytesPerLogicalSector = diskAlignment.BytesPerLogicalSector;
|
||||
pInfo->BytesPerPhysicalSector = diskAlignment.BytesPerPhysicalSector;
|
||||
|
||||
if (pDevDesc->VendorIdOffset)
|
||||
{
|
||||
safe_strcpy(pInfo->VendorId, (char*)pDevDesc + pDevDesc->VendorIdOffset);
|
||||
@@ -143,12 +171,14 @@ static int CLI_GetPhyDriveInfo(int PhyDrive, PHY_DRIVE_INFO* pInfo)
|
||||
static int CLI_CheckParam(int argc, char** argv, PHY_DRIVE_INFO* pDrvInfo, CLI_CFG *pCfg)
|
||||
{
|
||||
int i;
|
||||
int fstype = VTOY_FS_EXFAT;
|
||||
int op = -1;
|
||||
char* opt = NULL;
|
||||
int PhyDrive = -1;
|
||||
int PartStyle = 0;
|
||||
int ReserveMB = 0;
|
||||
BOOL USBCheck = TRUE;
|
||||
BOOL NonDest = FALSE;
|
||||
MBR_HEAD MBR;
|
||||
UINT64 Part2GPTAttr = 0;
|
||||
UINT64 Part2StartSector = 0;
|
||||
@@ -176,6 +206,10 @@ static int CLI_CheckParam(int argc, char** argv, PHY_DRIVE_INFO* pDrvInfo, CLI_C
|
||||
{
|
||||
USBCheck = FALSE;
|
||||
}
|
||||
else if (_stricmp(opt, "/NonDest") == 0)
|
||||
{
|
||||
NonDest = TRUE;
|
||||
}
|
||||
else if (_strnicmp(opt, "/Drive:", 7) == 0)
|
||||
{
|
||||
Log("Get PhyDrive by logical drive %C:", opt[7]);
|
||||
@@ -189,6 +223,17 @@ static int CLI_CheckParam(int argc, char** argv, PHY_DRIVE_INFO* pDrvInfo, CLI_C
|
||||
{
|
||||
ReserveMB = (int)strtol(opt + 3, NULL, 10);
|
||||
}
|
||||
else if (_strnicmp(opt, "/FS:", 4) == 0)
|
||||
{
|
||||
if (_stricmp(opt + 4, "NTFS") == 0)
|
||||
{
|
||||
fstype = VTOY_FS_NTFS;
|
||||
}
|
||||
else if (_stricmp(opt + 4, "FAT32") == 0)
|
||||
{
|
||||
fstype = VTOY_FS_FAT32;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (op < 0 || PhyDrive < 0)
|
||||
@@ -197,10 +242,10 @@ static int CLI_CheckParam(int argc, char** argv, PHY_DRIVE_INFO* pDrvInfo, CLI_C
|
||||
return 1;
|
||||
}
|
||||
|
||||
Log("Ventoy CLI %s PhyDrive:%d %s SecureBoot:%d ReserveSpace:%dMB USBCheck:%u",
|
||||
Log("Ventoy CLI %s PhyDrive:%d %s SecureBoot:%d ReserveSpace:%dMB USBCheck:%u FS:%s NonDest:%d",
|
||||
op == 0 ? "install" : "update",
|
||||
PhyDrive, PartStyle ? "GPT" : "MBR",
|
||||
g_SecureBoot, ReserveMB, USBCheck
|
||||
g_SecureBoot, ReserveMB, USBCheck, GetVentoyFsFmtNameByTypeA(fstype), NonDest
|
||||
);
|
||||
|
||||
if (CLI_GetPhyDriveInfo(PhyDrive, pDrvInfo))
|
||||
@@ -231,14 +276,51 @@ static int CLI_CheckParam(int argc, char** argv, PHY_DRIVE_INFO* pDrvInfo, CLI_C
|
||||
}
|
||||
}
|
||||
|
||||
if (op == 0 && NonDest)
|
||||
{
|
||||
GetLettersBelongPhyDrive(PhyDrive, pDrvInfo->DriveLetters, sizeof(pDrvInfo->DriveLetters));
|
||||
}
|
||||
|
||||
pCfg->op = op;
|
||||
pCfg->PartStyle = PartStyle;
|
||||
pCfg->ReserveMB = ReserveMB;
|
||||
pCfg->USBCheck = USBCheck;
|
||||
pCfg->NonDest = NonDest;
|
||||
pCfg->fstype = fstype;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Ventoy_CLI_NonDestInstall(PHY_DRIVE_INFO* pDrvInfo, CLI_CFG* pCfg)
|
||||
{
|
||||
int rc;
|
||||
int TryId = 1;
|
||||
|
||||
Log("Ventoy_CLI_NonDestInstall start ...");
|
||||
|
||||
if (pDrvInfo->BytesPerLogicalSector == 4096 && pDrvInfo->BytesPerPhysicalSector == 4096)
|
||||
{
|
||||
Log("Ventoy does not support 4k native disk.");
|
||||
rc = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!PartResizePreCheck(NULL))
|
||||
{
|
||||
Log("#### Part Resize PreCheck Failed ####");
|
||||
rc = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = PartitionResizeForVentoy(pDrvInfo);
|
||||
|
||||
out:
|
||||
Log("Ventoy_CLI_NonDestInstall [%s]", rc == 0 ? "SUCCESS" : "FAILED");
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
static int Ventoy_CLI_Install(PHY_DRIVE_INFO* pDrvInfo, CLI_CFG *pCfg)
|
||||
{
|
||||
int rc;
|
||||
@@ -246,11 +328,20 @@ static int Ventoy_CLI_Install(PHY_DRIVE_INFO* pDrvInfo, CLI_CFG *pCfg)
|
||||
|
||||
Log("Ventoy_CLI_Install start ...");
|
||||
|
||||
if (pDrvInfo->BytesPerLogicalSector == 4096 && pDrvInfo->BytesPerPhysicalSector == 4096)
|
||||
{
|
||||
Log("Ventoy does not support 4k native disk.");
|
||||
rc = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (pCfg->ReserveMB > 0)
|
||||
{
|
||||
CLISetReserveSpace(pCfg->ReserveMB);
|
||||
}
|
||||
|
||||
SetVentoyFsType(pCfg->fstype);
|
||||
|
||||
rc = InstallVentoy2PhyDrive(pDrvInfo, pCfg->PartStyle, TryId++);
|
||||
if (rc)
|
||||
{
|
||||
@@ -274,6 +365,9 @@ static int Ventoy_CLI_Install(PHY_DRIVE_INFO* pDrvInfo, CLI_CFG *pCfg)
|
||||
}
|
||||
}
|
||||
|
||||
SetVentoyFsType(VTOY_FS_EXFAT);
|
||||
|
||||
out:
|
||||
Log("Ventoy_CLI_Install [%s]", rc == 0 ? "SUCCESS" : "FAILED");
|
||||
|
||||
return rc;
|
||||
@@ -351,6 +445,11 @@ static void CLI_WriteDoneFile(int ret)
|
||||
}
|
||||
}
|
||||
|
||||
PHY_DRIVE_INFO* CLI_PhyDrvInfo(void)
|
||||
{
|
||||
return g_CLI_PhyDrvInfo;
|
||||
}
|
||||
|
||||
/*
|
||||
* Ventoy2Disk.exe VTOYCLI { /I | /U } { /Drive:F: | /PhyDrive:1 } /GPT /NoSB /R:4096 /NoUSBCheck
|
||||
*
|
||||
@@ -364,7 +463,7 @@ int VentoyCLIMain(int argc, char** argv)
|
||||
DeleteFileA(VENTOY_CLI_PERCENT);
|
||||
DeleteFileA(VENTOY_CLI_DONE);
|
||||
|
||||
pDrvInfo = (PHY_DRIVE_INFO*)malloc(sizeof(PHY_DRIVE_INFO));
|
||||
g_CLI_PhyDrvInfo = pDrvInfo = (PHY_DRIVE_INFO*)malloc(sizeof(PHY_DRIVE_INFO));
|
||||
if (!pDrvInfo)
|
||||
{
|
||||
goto end;
|
||||
@@ -388,7 +487,16 @@ int VentoyCLIMain(int argc, char** argv)
|
||||
|
||||
if (CliCfg.op == 0)
|
||||
{
|
||||
ret = Ventoy_CLI_Install(pDrvInfo, &CliCfg);
|
||||
if (CliCfg.NonDest)
|
||||
{
|
||||
ret = Ventoy_CLI_NonDestInstall(pDrvInfo, &CliCfg);
|
||||
}
|
||||
else
|
||||
{
|
||||
AlertSuppressInit();
|
||||
SetAlertPromptHookEnable(TRUE);
|
||||
ret = Ventoy_CLI_Install(pDrvInfo, &CliCfg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user