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
e47e4484
Commit
e47e4484
authored
Oct 25, 2021
by
longpanda
Browse files
Optimization for Ventoy2Disk.exe
parent
7e26decb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
3 deletions
+57
-3
INSTALL/Ventoy2Disk.exe
INSTALL/Ventoy2Disk.exe
+0
-0
Ventoy2Disk/Ventoy2Disk/PhyDrive.c
Ventoy2Disk/Ventoy2Disk/PhyDrive.c
+57
-3
No files found.
INSTALL/Ventoy2Disk.exe
View file @
e47e4484
No preview for this file type
Ventoy2Disk/Ventoy2Disk/PhyDrive.c
View file @
e47e4484
...
@@ -1660,9 +1660,7 @@ int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int PartStyle, int TryId)
...
@@ -1660,9 +1660,7 @@ int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int PartStyle, int TryId)
if
(
!
VDS_DeleteAllPartitions
(
pPhyDrive
->
PhyDrive
))
if
(
!
VDS_DeleteAllPartitions
(
pPhyDrive
->
PhyDrive
))
{
{
Log
(
"Notice: Could not delete partitions: 0x%x"
,
GetLastError
());
Log
(
"Notice: Could not delete partitions: 0x%x, but we continue."
,
GetLastError
());
rc
=
1
;
goto
End
;
}
}
Log
(
"Deleting all partitions ......................... OK"
);
Log
(
"Deleting all partitions ......................... OK"
);
...
@@ -1838,6 +1836,7 @@ static BOOL BackupDataBeforeCleanDisk(int PhyDrive, UINT64 DiskSize, BYTE **pBac
...
@@ -1838,6 +1836,7 @@ static BOOL BackupDataBeforeCleanDisk(int PhyDrive, UINT64 DiskSize, BYTE **pBac
BOOL
ret
=
FALSE
;
BOOL
ret
=
FALSE
;
BYTE
*
backup
=
NULL
;
BYTE
*
backup
=
NULL
;
UINT64
offset
;
UINT64
offset
;
BYTE
Buffer
[
512
];
HANDLE
hDrive
=
INVALID_HANDLE_VALUE
;
HANDLE
hDrive
=
INVALID_HANDLE_VALUE
;
LARGE_INTEGER
liCurPosition
;
LARGE_INTEGER
liCurPosition
;
LARGE_INTEGER
liNewPosition
;
LARGE_INTEGER
liNewPosition
;
...
@@ -1845,6 +1844,54 @@ static BOOL BackupDataBeforeCleanDisk(int PhyDrive, UINT64 DiskSize, BYTE **pBac
...
@@ -1845,6 +1844,54 @@ static BOOL BackupDataBeforeCleanDisk(int PhyDrive, UINT64 DiskSize, BYTE **pBac
Log
(
"BackupDataBeforeCleanDisk %d"
,
PhyDrive
);
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
;
liNewPosition
.
QuadPart
=
0
;
if
(
0
==
SetFilePointerEx
(
hDrive
,
liCurPosition
,
&
liNewPosition
,
FILE_BEGIN
)
||
liNewPosition
.
QuadPart
!=
liCurPosition
.
QuadPart
)
{
Log
(
"SetFilePointer1 Failed %u"
,
LASTERR
);
goto
out
;
}
dwSize
=
0
;
ret
=
ReadFile
(
hDrive
,
Buffer
,
512
,
&
dwSize
,
NULL
);
if
((
!
ret
)
||
(
dwSize
!=
512
))
{
Log
(
"Failed to read %d %u 0x%x"
,
ret
,
dwSize
,
LASTERR
);
goto
out
;
}
liCurPosition
.
QuadPart
=
2039
*
512
;
liNewPosition
.
QuadPart
=
0
;
if
(
0
==
SetFilePointerEx
(
hDrive
,
liCurPosition
,
&
liNewPosition
,
FILE_BEGIN
)
||
liNewPosition
.
QuadPart
!=
liCurPosition
.
QuadPart
)
{
Log
(
"SetFilePointer2 Failed %u"
,
LASTERR
);
goto
out
;
}
ret
=
WriteFile
(
hDrive
,
Buffer
,
512
,
&
dwSize
,
NULL
);
if
((
!
ret
)
||
dwSize
!=
512
)
{
Log
(
"Failed to write %d %u %u"
,
ret
,
dwSize
,
LASTERR
);
goto
out
;
}
CHECK_CLOSE_HANDLE
(
hDrive
);
Log
(
"Write access check success"
);
//step2 backup 4MB data
backup
=
malloc
(
SIZE_1MB
*
4
);
backup
=
malloc
(
SIZE_1MB
*
4
);
if
(
!
backup
)
if
(
!
backup
)
{
{
...
@@ -2334,6 +2381,13 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int TryId)
...
@@ -2334,6 +2381,13 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int TryId)
End:
End:
if
(
hVolume
!=
INVALID_HANDLE_VALUE
)
{
bRet
=
DeviceIoControl
(
hVolume
,
FSCTL_UNLOCK_VOLUME
,
NULL
,
0
,
NULL
,
0
,
&
dwSize
,
NULL
);
Log
(
"FSCTL_UNLOCK_VOLUME bRet:%u code:%u"
,
bRet
,
LASTERR
);
CHECK_CLOSE_HANDLE
(
hVolume
);
}
if
(
rc
==
0
)
if
(
rc
==
0
)
{
{
Log
(
"OK"
);
Log
(
"OK"
);
...
...
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