Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dadigang
Ventoy
Commits
5fcb3971
Commit
5fcb3971
authored
Oct 26, 2021
by
longpanda
Browse files
Optimization for Ventoy2Disk.exe
parent
e47e4484
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
30 deletions
+66
-30
INSTALL/Ventoy2Disk.exe
INSTALL/Ventoy2Disk.exe
+0
-0
Ventoy2Disk/Ventoy2Disk/PhyDrive.c
Ventoy2Disk/Ventoy2Disk/PhyDrive.c
+66
-30
Ventoy2Disk/Ventoy2Disk/WinDialog.c
Ventoy2Disk/Ventoy2Disk/WinDialog.c
+0
-0
No files found.
INSTALL/Ventoy2Disk.exe
View file @
5fcb3971
No preview for this file type
Ventoy2Disk/Ventoy2Disk/PhyDrive.c
View file @
5fcb3971
...
@@ -1591,9 +1591,11 @@ int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int PartStyle, int TryId)
...
@@ -1591,9 +1591,11 @@ int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int PartStyle, int TryId)
UINT64
Part1SectorCount
=
0
;
UINT64
Part1SectorCount
=
0
;
UINT64
Part2StartSector
=
0
;
UINT64
Part2StartSector
=
0
;
Log
(
"#####################################################"
);
Log
(
"InstallVentoy2PhyDrive try%d %s PhyDrive%d <<%s %s %dGB>>"
,
TryId
,
Log
(
"InstallVentoy2PhyDrive try%d %s PhyDrive%d <<%s %s %dGB>>"
,
TryId
,
PartStyle
?
"GPT"
:
"MBR"
,
pPhyDrive
->
PhyDrive
,
pPhyDrive
->
VendorId
,
pPhyDrive
->
ProductId
,
PartStyle
?
"GPT"
:
"MBR"
,
pPhyDrive
->
PhyDrive
,
pPhyDrive
->
VendorId
,
pPhyDrive
->
ProductId
,
GetHumanReadableGBSize
(
pPhyDrive
->
SizeInBytes
));
GetHumanReadableGBSize
(
pPhyDrive
->
SizeInBytes
));
Log
(
"#####################################################"
);
if
(
PartStyle
)
if
(
PartStyle
)
{
{
...
@@ -1828,29 +1830,14 @@ End:
...
@@ -1828,29 +1830,14 @@ End:
return
rc
;
return
rc
;
}
}
static
BOOL
BackupDataBeforeCleanDisk
(
int
PhyDrive
,
UINT64
DiskSize
,
BYTE
**
pBackup
)
static
BOOL
DiskCheckWriteAccess
(
HANDLE
hDrive
)
{
{
DWORD
dwSize
;
DWORD
dwSize
;
DWORD
dwStatus
;
BOOL
Return
=
FALSE
;
BOOL
ret
=
FALSE
;
BOOL
ret
=
FALSE
;
BYTE
*
backup
=
NULL
;
BOOL
bRet
=
FALSE
;
UINT64
offset
;
BYTE
Buffer
[
512
];
BYTE
Buffer
[
512
];
HANDLE
hDrive
=
INVALID_HANDLE_VALUE
;
LARGE_INTEGER
liCurPosition
;
LARGE_INTEGER
liCurPosition
;
LARGE_INTEGER
liNewPosition
;
LARGE_INTEGER
liNewPosition
;
VTOY_GPT_INFO
*
pGPT
=
NULL
;
Log
(
"BackupDataBeforeCleanDisk %d"
,
PhyDrive
);
// step1: check write access
hDrive
=
GetPhysicalHandle
(
PhyDrive
,
TRUE
,
TRUE
,
FALSE
);
if
(
hDrive
==
INVALID_HANDLE_VALUE
)
{
Log
(
"Failed to GetPhysicalHandle for write."
);
goto
out
;
}
liCurPosition
.
QuadPart
=
2039
*
512
;
liCurPosition
.
QuadPart
=
2039
*
512
;
liNewPosition
.
QuadPart
=
0
;
liNewPosition
.
QuadPart
=
0
;
...
@@ -1860,7 +1847,7 @@ static BOOL BackupDataBeforeCleanDisk(int PhyDrive, UINT64 DiskSize, BYTE **pBac
...
@@ -1860,7 +1847,7 @@ static BOOL BackupDataBeforeCleanDisk(int PhyDrive, UINT64 DiskSize, BYTE **pBac
Log
(
"SetFilePointer1 Failed %u"
,
LASTERR
);
Log
(
"SetFilePointer1 Failed %u"
,
LASTERR
);
goto
out
;
goto
out
;
}
}
dwSize
=
0
;
dwSize
=
0
;
ret
=
ReadFile
(
hDrive
,
Buffer
,
512
,
&
dwSize
,
NULL
);
ret
=
ReadFile
(
hDrive
,
Buffer
,
512
,
&
dwSize
,
NULL
);
...
@@ -1880,6 +1867,7 @@ static BOOL BackupDataBeforeCleanDisk(int PhyDrive, UINT64 DiskSize, BYTE **pBac
...
@@ -1880,6 +1867,7 @@ static BOOL BackupDataBeforeCleanDisk(int PhyDrive, UINT64 DiskSize, BYTE **pBac
goto
out
;
goto
out
;
}
}
dwSize
=
0
;
ret
=
WriteFile
(
hDrive
,
Buffer
,
512
,
&
dwSize
,
NULL
);
ret
=
WriteFile
(
hDrive
,
Buffer
,
512
,
&
dwSize
,
NULL
);
if
((
!
ret
)
||
dwSize
!=
512
)
if
((
!
ret
)
||
dwSize
!=
512
)
{
{
...
@@ -1887,9 +1875,46 @@ static BOOL BackupDataBeforeCleanDisk(int PhyDrive, UINT64 DiskSize, BYTE **pBac
...
@@ -1887,9 +1875,46 @@ static BOOL BackupDataBeforeCleanDisk(int PhyDrive, UINT64 DiskSize, BYTE **pBac
goto
out
;
goto
out
;
}
}
CHECK_CLOSE_HANDLE
(
hDrive
);
bRet
=
TRUE
;
Log
(
"Write access check success"
);
out:
return
bRet
;
}
static
BOOL
BackupDataBeforeCleanDisk
(
int
PhyDrive
,
UINT64
DiskSize
,
BYTE
**
pBackup
)
{
DWORD
dwSize
;
DWORD
dwStatus
;
BOOL
Return
=
FALSE
;
BOOL
ret
=
FALSE
;
BYTE
*
backup
=
NULL
;
UINT64
offset
;
HANDLE
hDrive
=
INVALID_HANDLE_VALUE
;
LARGE_INTEGER
liCurPosition
;
LARGE_INTEGER
liNewPosition
;
VTOY_GPT_INFO
*
pGPT
=
NULL
;
Log
(
"BackupDataBeforeCleanDisk %d"
,
PhyDrive
);
// step1: check write access
hDrive
=
GetPhysicalHandle
(
PhyDrive
,
TRUE
,
TRUE
,
FALSE
);
if
(
hDrive
==
INVALID_HANDLE_VALUE
)
{
Log
(
"Failed to GetPhysicalHandle for write."
);
goto
out
;
}
if
(
DiskCheckWriteAccess
(
hDrive
))
{
Log
(
"DiskCheckWriteAccess success"
);
CHECK_CLOSE_HANDLE
(
hDrive
);
}
else
{
Log
(
"DiskCheckWriteAccess failed"
);
goto
out
;
}
//step2 backup 4MB data
//step2 backup 4MB data
backup
=
malloc
(
SIZE_1MB
*
4
);
backup
=
malloc
(
SIZE_1MB
*
4
);
...
@@ -2016,9 +2041,11 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int TryId)
...
@@ -2016,9 +2041,11 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int TryId)
VTOY_GPT_INFO
*
pGptInfo
=
NULL
;
VTOY_GPT_INFO
*
pGptInfo
=
NULL
;
UINT8
ReservedData
[
4096
];
UINT8
ReservedData
[
4096
];
Log
(
"#####################################################"
);
Log
(
"UpdateVentoy2PhyDrive try%d %s PhyDrive%d <<%s %s %dGB>>"
,
TryId
,
Log
(
"UpdateVentoy2PhyDrive try%d %s PhyDrive%d <<%s %s %dGB>>"
,
TryId
,
pPhyDrive
->
PartStyle
?
"GPT"
:
"MBR"
,
pPhyDrive
->
PhyDrive
,
pPhyDrive
->
VendorId
,
pPhyDrive
->
ProductId
,
pPhyDrive
->
PartStyle
?
"GPT"
:
"MBR"
,
pPhyDrive
->
PhyDrive
,
pPhyDrive
->
VendorId
,
pPhyDrive
->
ProductId
,
GetHumanReadableGBSize
(
pPhyDrive
->
SizeInBytes
));
GetHumanReadableGBSize
(
pPhyDrive
->
SizeInBytes
));
Log
(
"#####################################################"
);
PROGRESS_BAR_SET_POS
(
PT_LOCK_FOR_CLEAN
);
PROGRESS_BAR_SET_POS
(
PT_LOCK_FOR_CLEAN
);
...
@@ -2262,20 +2289,29 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int TryId)
...
@@ -2262,20 +2289,29 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int TryId)
{
{
if
(
pPhyDrive
->
PartStyle
==
0
)
if
(
pPhyDrive
->
PartStyle
==
0
)
{
{
ForceMBR
=
TRUE
;
if
(
DiskCheckWriteAccess
(
hDrive
))
{
Log
(
"MBR DiskCheckWriteAccess success"
);
Log
(
"Try write failed, now delete partition 2 for MBR..."
);
ForceMBR
=
TRUE
;
CHECK_CLOSE_HANDLE
(
hDrive
);
Log
(
"
N
ow delete partition 2..."
);
Log
(
"
Try write failed, n
ow delete partition 2
for MBR
..."
);
VDS_DeleteVtoyEFIPartition
(
pPhyDrive
->
Phy
Drive
);
CHECK_CLOSE_HANDLE
(
h
Drive
);
hDrive
=
GetPhysicalHandle
(
pPhyDrive
->
PhyDrive
,
TRUE
,
TRUE
,
FALSE
);
Log
(
"Now delete partition 2..."
);
if
(
hDrive
==
INVALID_HANDLE_VALUE
)
VDS_DeleteVtoyEFIPartition
(
pPhyDrive
->
PhyDrive
);
hDrive
=
GetPhysicalHandle
(
pPhyDrive
->
PhyDrive
,
TRUE
,
TRUE
,
FALSE
);
if
(
hDrive
==
INVALID_HANDLE_VALUE
)
{
Log
(
"Failed to GetPhysicalHandle for write."
);
rc
=
1
;
goto
End
;
}
}
else
{
{
Log
(
"Failed to GetPhysicalHandle for write."
);
Log
(
"MBR DiskCheckWriteAccess failed"
);
rc
=
1
;
goto
End
;
}
}
}
}
else
else
...
...
Ventoy2Disk/Ventoy2Disk/WinDialog.c
View file @
5fcb3971
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment