mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[format] fix large FAT32 format for GPT drives
* Also set FSCTL_ALLOW_EXTENDED_DASD_IO before locking a drive * Closes #181
This commit is contained in:
parent
fcf16fed25
commit
a5f98d636f
3 changed files with 24 additions and 11 deletions
12
src/drive.c
12
src/drive.c
|
@ -66,7 +66,7 @@ static HANDLE GetHandle(char* Path, BOOL bWriteAccess, BOOL bLockDrive)
|
||||||
if (Path == NULL)
|
if (Path == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
hDrive = CreateFileA(Path, GENERIC_READ|(bWriteAccess?GENERIC_WRITE:0),
|
hDrive = CreateFileA(Path, GENERIC_READ|(bWriteAccess?GENERIC_WRITE:0),
|
||||||
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
|
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||||
if (hDrive == INVALID_HANDLE_VALUE) {
|
if (hDrive == INVALID_HANDLE_VALUE) {
|
||||||
uprintf("Could not open drive %s: %s\n", Path, WindowsErrorString());
|
uprintf("Could not open drive %s: %s\n", Path, WindowsErrorString());
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -77,6 +77,10 @@ static HANDLE GetHandle(char* Path, BOOL bWriteAccess, BOOL bLockDrive)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bLockDrive) {
|
if (bLockDrive) {
|
||||||
|
if (DeviceIoControl(hDrive, FSCTL_ALLOW_EXTENDED_DASD_IO, NULL, 0, NULL, 0, &size, NULL)) {
|
||||||
|
uprintf("I/O boundary checks disabled\n");
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < DRIVE_ACCESS_RETRIES; i++) {
|
for (i = 0; i < DRIVE_ACCESS_RETRIES; i++) {
|
||||||
if (DeviceIoControl(hDrive, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &size, NULL))
|
if (DeviceIoControl(hDrive, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &size, NULL))
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -186,7 +190,7 @@ char* GetLogicalName(DWORD DriveIndex, BOOL bKeepTrailingBackslash, BOOL bSilent
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we can't have FILE_SHARE_WRITE, forget it
|
// If we can't have FILE_SHARE_WRITE, forget it
|
||||||
hDrive = CreateFileA(volume_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
|
hDrive = CreateFileA(volume_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||||
if (hDrive == INVALID_HANDLE_VALUE) {
|
if (hDrive == INVALID_HANDLE_VALUE) {
|
||||||
suprintf("Could not open GUID volume '%s': %s\n", volume_name, WindowsErrorString());
|
suprintf("Could not open GUID volume '%s': %s\n", volume_name, WindowsErrorString());
|
||||||
continue;
|
continue;
|
||||||
|
@ -302,7 +306,7 @@ static BOOL _GetDriveLetterAndType(DWORD DriveIndex, char* drive_letter, UINT* d
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
safe_sprintf(logical_drive, sizeof(logical_drive), "\\\\.\\%c:", drive[0]);
|
safe_sprintf(logical_drive, sizeof(logical_drive), "\\\\.\\%c:", drive[0]);
|
||||||
hDrive = CreateFileA(logical_drive, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
|
hDrive = CreateFileA(logical_drive, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||||
if (hDrive == INVALID_HANDLE_VALUE) {
|
if (hDrive == INVALID_HANDLE_VALUE) {
|
||||||
uprintf("Warning: could not open drive %c: %s\n", drive[0], WindowsErrorString());
|
uprintf("Warning: could not open drive %c: %s\n", drive[0], WindowsErrorString());
|
||||||
continue;
|
continue;
|
||||||
|
@ -560,7 +564,7 @@ static BOOL FlushDrive(char drive_letter)
|
||||||
|
|
||||||
logical_drive[4] = drive_letter;
|
logical_drive[4] = drive_letter;
|
||||||
hDrive = CreateFileA(logical_drive, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
hDrive = CreateFileA(logical_drive, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
||||||
NULL, OPEN_EXISTING, 0, 0);
|
NULL, OPEN_EXISTING, 0, NULL);
|
||||||
if (hDrive == INVALID_HANDLE_VALUE) {
|
if (hDrive == INVALID_HANDLE_VALUE) {
|
||||||
uprintf("Failed to open %c: for flushing: %s\n", drive_letter, WindowsErrorString());
|
uprintf("Failed to open %c: for flushing: %s\n", drive_letter, WindowsErrorString());
|
||||||
goto out;
|
goto out;
|
||||||
|
|
13
src/format.c
13
src/format.c
|
@ -338,6 +338,7 @@ static BOOL FormatFAT32(DWORD DriveIndex)
|
||||||
DWORD cbRet;
|
DWORD cbRet;
|
||||||
DISK_GEOMETRY dgDrive;
|
DISK_GEOMETRY dgDrive;
|
||||||
PARTITION_INFORMATION piDrive;
|
PARTITION_INFORMATION piDrive;
|
||||||
|
PARTITION_INFORMATION_EX xpiDrive;
|
||||||
// Recommended values
|
// Recommended values
|
||||||
DWORD ReservedSectCount = 32;
|
DWORD ReservedSectCount = 32;
|
||||||
DWORD NumFATs = 2;
|
DWORD NumFATs = 2;
|
||||||
|
@ -387,7 +388,15 @@ static BOOL FormatFAT32(DWORD DriveIndex)
|
||||||
if (IS_ERROR(FormatStatus)) goto out;
|
if (IS_ERROR(FormatStatus)) goto out;
|
||||||
if (!DeviceIoControl (hLogicalVolume, IOCTL_DISK_GET_PARTITION_INFO, NULL, 0, &piDrive,
|
if (!DeviceIoControl (hLogicalVolume, IOCTL_DISK_GET_PARTITION_INFO, NULL, 0, &piDrive,
|
||||||
sizeof(piDrive), &cbRet, NULL)) {
|
sizeof(piDrive), &cbRet, NULL)) {
|
||||||
die("Failed to get partition info\n", ERROR_NOT_SUPPORTED);
|
if (!DeviceIoControl (hLogicalVolume, IOCTL_DISK_GET_PARTITION_INFO_EX, NULL, 0, &xpiDrive,
|
||||||
|
sizeof(xpiDrive), &cbRet, NULL)) {
|
||||||
|
die("Failed to get partition info (both regular and _ex)", ERROR_NOT_SUPPORTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset (&piDrive, 0, sizeof(piDrive));
|
||||||
|
piDrive.StartingOffset.QuadPart = xpiDrive.StartingOffset.QuadPart;
|
||||||
|
piDrive.PartitionLength.QuadPart = xpiDrive.PartitionLength.QuadPart;
|
||||||
|
piDrive.HiddenSectors = (DWORD) (xpiDrive.StartingOffset.QuadPart / dgDrive.BytesPerSector);
|
||||||
}
|
}
|
||||||
|
|
||||||
BytesPerSect = dgDrive.BytesPerSector;
|
BytesPerSect = dgDrive.BytesPerSector;
|
||||||
|
@ -419,7 +428,7 @@ static BOOL FormatFAT32(DWORD DriveIndex)
|
||||||
|
|
||||||
// fill out the boot sector and fs info
|
// fill out the boot sector and fs info
|
||||||
pFAT32BootSect->sJmpBoot[0]=0xEB;
|
pFAT32BootSect->sJmpBoot[0]=0xEB;
|
||||||
pFAT32BootSect->sJmpBoot[1]=0x5A;
|
pFAT32BootSect->sJmpBoot[1]=0x58; // jmp.s $+0x5a is 0xeb 0x58, not 0xeb 0x5a. Thanks Marco!
|
||||||
pFAT32BootSect->sJmpBoot[2]=0x90;
|
pFAT32BootSect->sJmpBoot[2]=0x90;
|
||||||
strncpy((char*)pFAT32BootSect->sOEMName, "MSWIN4.1", 8);
|
strncpy((char*)pFAT32BootSect->sOEMName, "MSWIN4.1", 8);
|
||||||
pFAT32BootSect->wBytsPerSec = (WORD) BytesPerSect;
|
pFAT32BootSect->wBytsPerSec = (WORD) BytesPerSect;
|
||||||
|
|
10
src/rufus.rc
10
src/rufus.rc
|
@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
|
||||||
IDD_DIALOG DIALOGEX 12, 12, 206, 329
|
IDD_DIALOG DIALOGEX 12, 12, 206, 329
|
||||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
EXSTYLE WS_EX_APPWINDOW
|
EXSTYLE WS_EX_APPWINDOW
|
||||||
CAPTION "Rufus v1.4.0.328"
|
CAPTION "Rufus v1.4.0.329"
|
||||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
BEGIN
|
BEGIN
|
||||||
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
|
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
|
||||||
|
@ -288,8 +288,8 @@ END
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 1,4,0,328
|
FILEVERSION 1,4,0,329
|
||||||
PRODUCTVERSION 1,4,0,328
|
PRODUCTVERSION 1,4,0,329
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -306,13 +306,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", "1.4.0.328"
|
VALUE "FileVersion", "1.4.0.329"
|
||||||
VALUE "InternalName", "Rufus"
|
VALUE "InternalName", "Rufus"
|
||||||
VALUE "LegalCopyright", "© 2011-2013 Pete Batard (GPL v3)"
|
VALUE "LegalCopyright", "© 2011-2013 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", "1.4.0.328"
|
VALUE "ProductVersion", "1.4.0.329"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
Loading…
Reference in a new issue