Update for Ventoy2Disk.exe

1. Add "Show All Devices" option
2. Add "Partition align with 4KB" option
3. Display size optimization
4. Doesn't check partition active flag anymore
This commit is contained in:
longpanda 2021-02-23 17:49:28 +08:00
parent 12e8ae26ae
commit fd6580be72
11 changed files with 56 additions and 2 deletions

Binary file not shown.

Binary file not shown.

View file

@ -63,6 +63,13 @@ typedef enum STR_ID
STR_MENU_PART_STYLE, //29
STR_DISK_2TB_MBR_ERROR,//30
STR_SHOW_ALL_DEV, //31
STR_PART_ALIGN_4KB, //32
STR_WEB_COMMUNICATION_ERR, //33
STR_WEB_REMOTE_ABNORMAL, //34
STR_WEB_REQUEST_TIMEOUT, //35
STR_WEB_SERVICE_UNAVAILABLE, //36
STR_WEB_TOKEN_MISMATCH, //37
STR_ID_MAX
}STR_ID;
@ -75,6 +82,7 @@ extern BOOL g_SecureBoot;
#define VTOY_MENU_PART_STYLE 0xA003
#define VTOY_MENU_PART_MBR 0xA004
#define VTOY_MENU_PART_GPT 0xA005
#define VTOY_MENU_ALL_DEV 0xA006
typedef enum OPT_SUBMENU
@ -83,6 +91,7 @@ typedef enum OPT_SUBMENU
OPT_SUBMENU_PART_STYLE,
OPT_SUBMENU_PART_CFG,
OPT_SUBMENU_CLEAR,
OPT_SUBMENU_ALL_DEV,
OPT_SUBMENU_MAX
}OPT_SUBMENU;

Binary file not shown.

View file

@ -468,6 +468,17 @@ int VentoyFillMBR(UINT64 DiskSizeBytes, MBR_HEAD *pMBR, int PartStyle)
ReservedSector += 33; // backup GPT part table
}
// check aligned with 4KB
if (IsPartNeed4KBAlign())
{
UINT64 sectors = DiskSizeBytes / 512;
if (sectors % 8)
{
Log("Disk need to align with 4KB %u", (UINT32)(sectors % 8));
ReservedSector += (UINT32)(sectors % 8);
}
}
Log("ReservedSector: %u", ReservedSector);
//Part1
@ -598,6 +609,16 @@ int VentoyFillGpt(UINT64 DiskSizeBytes, VTOY_GPT_INFO *pInfo)
ReservedSector += ReservedValue * 2048;
}
// check aligned with 4KB
if (IsPartNeed4KBAlign())
{
if (DiskSectorCount % 8)
{
Log("Disk need to align with 4KB %u", (UINT32)(DiskSectorCount % 8));
ReservedSector += (DiskSectorCount % 8);
}
}
Part1SectorCount = DiskSectorCount - ReservedSector - (VENTOY_EFI_PART_SIZE / 512) - 2048;
memcpy(Head->Signature, "EFI PART", 8);
@ -746,6 +767,11 @@ int GetHumanReadableGBSize(UINT64 SizeBytes)
double Delta;
double GB = SizeBytes * 1.0 / 1000 / 1000 / 1000;
if ((SizeBytes % 1073741824) == 0)
{
return (int)(SizeBytes / 1073741824);
}
for (i = 0; i < 12; i++)
{
if (Pow2 > GB)

View file

@ -26,7 +26,7 @@
PHY_DRIVE_INFO *g_PhyDriveList = NULL;
DWORD g_PhyDriveCount = 0;
static int g_FilterRemovable = 0;
static int g_FilterUSB = 1;
int g_FilterUSB = 1;
int g_ForceOperation = 1;
int ParseCmdLineOption(LPSTR lpCmdLine)
@ -152,6 +152,23 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD *pMBR, UIN
return FALSE;
}
if (pGpt->PartTbl[0].StartLBA != 2048)
{
Log("Part1 not match %llu", pGpt->PartTbl[0].StartLBA);
return FALSE;
}
PartSectorCount = VENTOY_EFI_PART_SIZE / 512;
if (pGpt->PartTbl[1].StartLBA != pGpt->PartTbl[0].LastLBA + 1 ||
(UINT32)(pGpt->PartTbl[1].LastLBA + 1 - pGpt->PartTbl[1].StartLBA) != PartSectorCount)
{
Log("Part2 not match [%llu %llu] [%llu %llu]",
pGpt->PartTbl[0].StartLBA, pGpt->PartTbl[0].LastLBA,
pGpt->PartTbl[1].StartLBA, pGpt->PartTbl[1].LastLBA);
return FALSE;
}
*Part2StartSector = pGpt->PartTbl[1].StartLBA;
memcpy(pMBR, &(pGpt->MBR), sizeof(MBR_HEAD));
@ -185,7 +202,7 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD *pMBR, UIN
if (MBR.PartTbl[2].Active != 0x80 && MBR.PartTbl[3].Active != 0x80)
{
Log("Part3 and Part4 are both NOT active 0x%x 0x%x", MBR.PartTbl[2].Active, MBR.PartTbl[3].Active);
return FALSE;
//return FALSE;
}
}

View file

@ -183,6 +183,7 @@ extern int g_ForceOperation;
extern HWND g_ProgressBarHwnd;
extern HFONT g_language_normal_font;
extern HFONT g_language_bold_font;
extern int g_FilterUSB;
void Log(const char *Fmt, ...);
BOOL IsPathExist(BOOL Dir, const char *Fmt, ...);
@ -220,6 +221,7 @@ int INIT unxz(unsigned char *in, int in_size,
void disk_io_set_param(HANDLE Handle, UINT64 SectorCount);
INT_PTR CALLBACK PartDialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
int GetReservedSpaceInMB(void);
int IsPartNeed4KBAlign(void);
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);

Binary file not shown.

Binary file not shown.