mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[syslinux] use SetFilePointerEx and other improvements
This commit is contained in:
parent
f31a90bba2
commit
f1f620411c
3 changed files with 28 additions and 22 deletions
|
@ -1138,6 +1138,7 @@ static BOOL SetupWinPE(char drive_letter)
|
||||||
const char* patch_str_rep[] = { "\\i386\\txtsetup.sif", "\\i386\\system32\\" };
|
const char* patch_str_rep[] = { "\\i386\\txtsetup.sif", "\\i386\\system32\\" };
|
||||||
const char *win_nt_bt_org = "$win_nt$.~bt", *win_nt_bt_rep = "i386";
|
const char *win_nt_bt_org = "$win_nt$.~bt", *win_nt_bt_rep = "i386";
|
||||||
const char *rdisk_zero = "rdisk(0)";
|
const char *rdisk_zero = "rdisk(0)";
|
||||||
|
const LARGE_INTEGER liZero = { {0, 0} };
|
||||||
char setupsrcdev[64];
|
char setupsrcdev[64];
|
||||||
HANDLE handle = INVALID_HANDLE_VALUE;
|
HANDLE handle = INVALID_HANDLE_VALUE;
|
||||||
DWORD i, j, size, rw_size, index = 0;
|
DWORD i, j, size, rw_size, index = 0;
|
||||||
|
@ -1203,7 +1204,7 @@ static BOOL SetupWinPE(char drive_letter)
|
||||||
uprintf("Could not read file %s: %s\n", dst, WindowsErrorString());
|
uprintf("Could not read file %s: %s\n", dst, WindowsErrorString());
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
SetFilePointer(handle, 0, NULL, FILE_BEGIN);
|
SetFilePointerEx(handle, liZero, NULL, FILE_BEGIN);
|
||||||
|
|
||||||
// Patch setupldr.bin
|
// Patch setupldr.bin
|
||||||
uprintf("Patching file %s\n", dst);
|
uprintf("Patching file %s\n", dst);
|
||||||
|
|
10
src/rufus.rc
10
src/rufus.rc
|
@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
|
||||||
IDD_DIALOG DIALOGEX 12, 12, 242, 376
|
IDD_DIALOG DIALOGEX 12, 12, 242, 376
|
||||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
EXSTYLE WS_EX_ACCEPTFILES
|
EXSTYLE WS_EX_ACCEPTFILES
|
||||||
CAPTION "Rufus 2.10.953"
|
CAPTION "Rufus 2.10.954"
|
||||||
FONT 8, "Segoe UI Symbol", 400, 0, 0x0
|
FONT 8, "Segoe UI Symbol", 400, 0, 0x0
|
||||||
BEGIN
|
BEGIN
|
||||||
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
|
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
|
||||||
|
@ -320,8 +320,8 @@ END
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 2,10,953,0
|
FILEVERSION 2,10,954,0
|
||||||
PRODUCTVERSION 2,10,953,0
|
PRODUCTVERSION 2,10,954,0
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -338,13 +338,13 @@ BEGIN
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
|
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
|
||||||
VALUE "FileDescription", "Rufus"
|
VALUE "FileDescription", "Rufus"
|
||||||
VALUE "FileVersion", "2.10.953"
|
VALUE "FileVersion", "2.10.954"
|
||||||
VALUE "InternalName", "Rufus"
|
VALUE "InternalName", "Rufus"
|
||||||
VALUE "LegalCopyright", "© 2011-2016 Pete Batard (GPL v3)"
|
VALUE "LegalCopyright", "© 2011-2016 Pete Batard (GPL v3)"
|
||||||
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
||||||
VALUE "OriginalFilename", "rufus.exe"
|
VALUE "OriginalFilename", "rufus.exe"
|
||||||
VALUE "ProductName", "Rufus"
|
VALUE "ProductName", "Rufus"
|
||||||
VALUE "ProductVersion", "2.10.953"
|
VALUE "ProductVersion", "2.10.954"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
|
@ -55,20 +55,24 @@ uint32_t LIBFAT_SECTOR_MASK = 511;
|
||||||
/*
|
/*
|
||||||
* Wrapper for ReadFile suitable for libfat
|
* Wrapper for ReadFile suitable for libfat
|
||||||
*/
|
*/
|
||||||
int libfat_readfile(intptr_t pp, void *buf, size_t secsize,
|
int libfat_readfile(intptr_t pp, void *buf, size_t secsize, libfat_sector_t sector)
|
||||||
libfat_sector_t sector)
|
|
||||||
{
|
{
|
||||||
uint64_t offset = (uint64_t) sector * secsize;
|
LARGE_INTEGER offset;
|
||||||
LONG loword = (LONG) offset;
|
|
||||||
LONG hiword = (LONG) (offset >> 32);
|
|
||||||
LONG hiwordx = hiword;
|
|
||||||
DWORD bytes_read;
|
DWORD bytes_read;
|
||||||
|
|
||||||
if (SetFilePointer((HANDLE) pp, loword, &hiwordx, FILE_BEGIN) != loword ||
|
offset.QuadPart = (LONGLONG) sector * secsize;
|
||||||
hiword != hiwordx ||
|
if (!SetFilePointerEx((HANDLE) pp, offset, NULL, FILE_BEGIN)) {
|
||||||
!ReadFile((HANDLE) pp, buf, (DWORD)secsize, &bytes_read, NULL) ||
|
uprintf("Could not set pointer to position %llu: %s", offset.QuadPart, WindowsErrorString());
|
||||||
bytes_read != secsize) {
|
return 0;
|
||||||
uprintf("Cannot read sector %u\n", sector);
|
}
|
||||||
|
|
||||||
|
if (!ReadFile((HANDLE) pp, buf, (DWORD) secsize, &bytes_read, NULL)) {
|
||||||
|
uprintf("Could not read sector %llu: %s", sector, WindowsErrorString());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bytes_read != secsize) {
|
||||||
|
uprintf("Sector %llu: Read %d bytes instead of %d requested", sector, bytes_read, secsize);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +85,7 @@ int libfat_readfile(intptr_t pp, void *buf, size_t secsize,
|
||||||
*/
|
*/
|
||||||
BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type)
|
BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type)
|
||||||
{
|
{
|
||||||
|
const LARGE_INTEGER liZero = { {0, 0} };
|
||||||
HANDLE f_handle = INVALID_HANDLE_VALUE;
|
HANDLE f_handle = INVALID_HANDLE_VALUE;
|
||||||
HANDLE d_handle = INVALID_HANDLE_VALUE;
|
HANDLE d_handle = INVALID_HANDLE_VALUE;
|
||||||
DWORD bytes_read, bytes_written, err;
|
DWORD bytes_read, bytes_written, err;
|
||||||
|
@ -198,7 +203,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type)
|
||||||
|
|
||||||
/* Reopen the volume (we already have a lock) */
|
/* Reopen the volume (we already have a lock) */
|
||||||
d_handle = GetLogicalHandle(drive_index, TRUE, FALSE);
|
d_handle = GetLogicalHandle(drive_index, TRUE, FALSE);
|
||||||
if (d_handle == INVALID_HANDLE_VALUE) {
|
if ((d_handle == INVALID_HANDLE_VALUE) || (d_handle == NULL)) {
|
||||||
uprintf("Could open volume for Syslinux installation");
|
uprintf("Could open volume for Syslinux installation");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -270,10 +275,10 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Rewrite the file */
|
/* Rewrite the file */
|
||||||
if (SetFilePointer(f_handle, 0, NULL, FILE_BEGIN) != 0 ||
|
if (!SetFilePointerEx(f_handle, liZero, NULL, FILE_BEGIN) ||
|
||||||
!WriteFileWithRetry(f_handle, syslinux_ldlinux[0], syslinux_ldlinux_len[0],
|
!WriteFileWithRetry(f_handle, syslinux_ldlinux[0], syslinux_ldlinux_len[0],
|
||||||
&bytes_written, WRITE_RETRIES)) {
|
&bytes_written, WRITE_RETRIES)) {
|
||||||
uprintf("Could not write '%s': %s\n", &path[3], WindowsErrorString());
|
uprintf("Could not rewrite '%s': %s\n", &path[3], WindowsErrorString());
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +286,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type)
|
||||||
safe_closehandle(f_handle);
|
safe_closehandle(f_handle);
|
||||||
|
|
||||||
/* Read existing FAT data into boot sector */
|
/* Read existing FAT data into boot sector */
|
||||||
if (SetFilePointer(d_handle, 0, NULL, FILE_BEGIN) != 0 ||
|
if (!SetFilePointerEx(d_handle, liZero, NULL, FILE_BEGIN) ||
|
||||||
!ReadFile(d_handle, sectbuf, SECTOR_SIZE,
|
!ReadFile(d_handle, sectbuf, SECTOR_SIZE,
|
||||||
&bytes_read, NULL)) {
|
&bytes_read, NULL)) {
|
||||||
uprintf("Could not read Syslinux boot record: %s", WindowsErrorString());
|
uprintf("Could not read Syslinux boot record: %s", WindowsErrorString());
|
||||||
|
@ -296,7 +301,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type)
|
||||||
syslinux_make_bootsect(sectbuf, (fs_type == FS_NTFS)?NTFS:VFAT);
|
syslinux_make_bootsect(sectbuf, (fs_type == FS_NTFS)?NTFS:VFAT);
|
||||||
|
|
||||||
/* Write boot sector back */
|
/* Write boot sector back */
|
||||||
if (SetFilePointer(d_handle, 0, NULL, FILE_BEGIN) != 0 ||
|
if (!SetFilePointerEx(d_handle, liZero, NULL, FILE_BEGIN) ||
|
||||||
!WriteFileWithRetry(d_handle, sectbuf, SECTOR_SIZE,
|
!WriteFileWithRetry(d_handle, sectbuf, SECTOR_SIZE,
|
||||||
&bytes_written, WRITE_RETRIES)) {
|
&bytes_written, WRITE_RETRIES)) {
|
||||||
uprintf("Could not write Syslinux boot record: %s", WindowsErrorString());
|
uprintf("Could not write Syslinux boot record: %s", WindowsErrorString());
|
||||||
|
|
Loading…
Reference in a new issue