int PartStyle;\r
int ReserveMB;\r
BOOL USBCheck;\r
+ BOOL NonDest;\r
+ int fstype;\r
}CLI_CFG;\r
\r
BOOL g_CLI_Mode = FALSE;\r
static int g_CLI_OP;\r
static int g_CLI_PhyDrive;\r
\r
+static PHY_DRIVE_INFO* g_CLI_PhyDrvInfo = NULL;\r
+\r
static int CLI_GetPhyDriveInfo(int PhyDrive, PHY_DRIVE_INFO* pInfo)\r
{\r
BOOL bRet;\r
STORAGE_PROPERTY_QUERY Query;\r
STORAGE_DESCRIPTOR_HEADER DevDescHeader;\r
STORAGE_DEVICE_DESCRIPTOR* pDevDesc;\r
+ STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR diskAlignment;\r
\r
safe_sprintf(PhyDrivePath, "\\\\.\\PhysicalDrive%d", PhyDrive);\r
Handle = CreateFileA(PhyDrivePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);\r
return 1;\r
}\r
\r
+\r
+ memset(&Query, 0, sizeof(STORAGE_PROPERTY_QUERY));\r
+ Query.PropertyId = StorageAccessAlignmentProperty;\r
+ Query.QueryType = PropertyStandardQuery;\r
+ memset(&diskAlignment, 0, sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR));\r
+\r
+ bRet = DeviceIoControl(Handle,\r
+ IOCTL_STORAGE_QUERY_PROPERTY,\r
+ &Query,\r
+ sizeof(STORAGE_PROPERTY_QUERY),\r
+ &diskAlignment,\r
+ sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR),\r
+ &dwBytes,\r
+ NULL);\r
+ if (!bRet)\r
+ {\r
+ Log("DeviceIoControl3 error:%u dwBytes:%u", LASTERR, dwBytes);\r
+ }\r
+\r
+\r
pInfo->PhyDrive = PhyDrive;\r
pInfo->SizeInBytes = LengthInfo.Length.QuadPart;\r
pInfo->DeviceType = pDevDesc->DeviceType;\r
pInfo->RemovableMedia = pDevDesc->RemovableMedia;\r
pInfo->BusType = pDevDesc->BusType;\r
\r
+ pInfo->BytesPerLogicalSector = diskAlignment.BytesPerLogicalSector;\r
+ pInfo->BytesPerPhysicalSector = diskAlignment.BytesPerPhysicalSector;\r
+\r
if (pDevDesc->VendorIdOffset)\r
{\r
safe_strcpy(pInfo->VendorId, (char*)pDevDesc + pDevDesc->VendorIdOffset);\r
static int CLI_CheckParam(int argc, char** argv, PHY_DRIVE_INFO* pDrvInfo, CLI_CFG *pCfg)\r
{\r
int i;\r
+ int fstype = VTOY_FS_EXFAT;\r
int op = -1;\r
char* opt = NULL;\r
int PhyDrive = -1;\r
int PartStyle = 0;\r
int ReserveMB = 0;\r
BOOL USBCheck = TRUE;\r
+ BOOL NonDest = FALSE;\r
MBR_HEAD MBR;\r
UINT64 Part2GPTAttr = 0;\r
UINT64 Part2StartSector = 0;\r
{\r
USBCheck = FALSE;\r
}\r
+ else if (_stricmp(opt, "/NonDest") == 0)\r
+ {\r
+ NonDest = TRUE;\r
+ }\r
else if (_strnicmp(opt, "/Drive:", 7) == 0)\r
{\r
Log("Get PhyDrive by logical drive %C:", opt[7]);\r
{\r
ReserveMB = (int)strtol(opt + 3, NULL, 10);\r
}\r
+ else if (_strnicmp(opt, "/FS:", 4) == 0)\r
+ {\r
+ if (_stricmp(opt + 4, "NTFS") == 0)\r
+ {\r
+ fstype = VTOY_FS_NTFS;\r
+ }\r
+ else if (_stricmp(opt + 4, "FAT32") == 0)\r
+ {\r
+ fstype = VTOY_FS_FAT32;\r
+ }\r
+ }\r
}\r
\r
if (op < 0 || PhyDrive < 0)\r
return 1;\r
}\r
\r
- Log("Ventoy CLI %s PhyDrive:%d %s SecureBoot:%d ReserveSpace:%dMB USBCheck:%u",\r
+ Log("Ventoy CLI %s PhyDrive:%d %s SecureBoot:%d ReserveSpace:%dMB USBCheck:%u FS:%s NonDest:%d",\r
op == 0 ? "install" : "update",\r
PhyDrive, PartStyle ? "GPT" : "MBR",\r
- g_SecureBoot, ReserveMB, USBCheck\r
+ g_SecureBoot, ReserveMB, USBCheck, GetVentoyFsFmtNameByTypeA(fstype), NonDest\r
);\r
\r
if (CLI_GetPhyDriveInfo(PhyDrive, pDrvInfo))\r
}\r
}\r
\r
+ if (op == 0 && NonDest)\r
+ {\r
+ GetLettersBelongPhyDrive(PhyDrive, pDrvInfo->DriveLetters, sizeof(pDrvInfo->DriveLetters));\r
+ }\r
+\r
pCfg->op = op;\r
pCfg->PartStyle = PartStyle;\r
pCfg->ReserveMB = ReserveMB;\r
pCfg->USBCheck = USBCheck;\r
+ pCfg->NonDest = NonDest;\r
+ pCfg->fstype = fstype;\r
\r
return 0;\r
}\r
\r
+static int Ventoy_CLI_NonDestInstall(PHY_DRIVE_INFO* pDrvInfo, CLI_CFG* pCfg)\r
+{\r
+ int rc;\r
+ int TryId = 1;\r
+\r
+ Log("Ventoy_CLI_NonDestInstall start ...");\r
+\r
+ if (pDrvInfo->BytesPerLogicalSector == 4096 && pDrvInfo->BytesPerPhysicalSector == 4096)\r
+ {\r
+ Log("Ventoy does not support 4k native disk.");\r
+ rc = 1;\r
+ goto out;\r
+ }\r
+\r
+ if (!PartResizePreCheck(NULL))\r
+ {\r
+ Log("#### Part Resize PreCheck Failed ####");\r
+ rc = 1;\r
+ goto out;\r
+ }\r
+\r
+ rc = PartitionResizeForVentoy(pDrvInfo);\r
+\r
+out:\r
+ Log("Ventoy_CLI_NonDestInstall [%s]", rc == 0 ? "SUCCESS" : "FAILED");\r
+\r
+ return rc;\r
+}\r
+\r
+\r
static int Ventoy_CLI_Install(PHY_DRIVE_INFO* pDrvInfo, CLI_CFG *pCfg)\r
{\r
int rc; \r
\r
Log("Ventoy_CLI_Install start ...");\r
\r
+ if (pDrvInfo->BytesPerLogicalSector == 4096 && pDrvInfo->BytesPerPhysicalSector == 4096)\r
+ {\r
+ Log("Ventoy does not support 4k native disk.");\r
+ rc = 1;\r
+ goto out;\r
+ }\r
+\r
if (pCfg->ReserveMB > 0)\r
{\r
CLISetReserveSpace(pCfg->ReserveMB);\r
}\r
\r
+ SetVentoyFsType(pCfg->fstype);\r
+\r
rc = InstallVentoy2PhyDrive(pDrvInfo, pCfg->PartStyle, TryId++);\r
if (rc)\r
{\r
}\r
}\r
\r
+ SetVentoyFsType(VTOY_FS_EXFAT);\r
+\r
+out:\r
Log("Ventoy_CLI_Install [%s]", rc == 0 ? "SUCCESS" : "FAILED");\r
\r
return rc;\r
}\r
}\r
\r
+PHY_DRIVE_INFO* CLI_PhyDrvInfo(void)\r
+{\r
+ return g_CLI_PhyDrvInfo;\r
+}\r
+\r
/*\r
* Ventoy2Disk.exe VTOYCLI { /I | /U } { /Drive:F: | /PhyDrive:1 } /GPT /NoSB /R:4096 /NoUSBCheck\r
* \r
DeleteFileA(VENTOY_CLI_PERCENT);\r
DeleteFileA(VENTOY_CLI_DONE);\r
\r
- pDrvInfo = (PHY_DRIVE_INFO*)malloc(sizeof(PHY_DRIVE_INFO));\r
+ g_CLI_PhyDrvInfo = pDrvInfo = (PHY_DRIVE_INFO*)malloc(sizeof(PHY_DRIVE_INFO));\r
if (!pDrvInfo)\r
{\r
goto end;\r
\r
if (CliCfg.op == 0)\r
{\r
- ret = Ventoy_CLI_Install(pDrvInfo, &CliCfg);\r
+ if (CliCfg.NonDest)\r
+ {\r
+ ret = Ventoy_CLI_NonDestInstall(pDrvInfo, &CliCfg);\r
+ }\r
+ else\r
+ {\r
+ AlertSuppressInit();\r
+ SetAlertPromptHookEnable(TRUE);\r
+ ret = Ventoy_CLI_Install(pDrvInfo, &CliCfg);\r
+ }\r
}\r
else\r
{\r