From b03065b1f558ea2983b5dda4d62923a818adc889 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Fri, 24 Feb 2012 18:51:33 +0000 Subject: [PATCH] [ntfs] fix creation of Windows 7 bootable USB from XP * When using Win7 installation ISOs, XP would return the error: [0x00000456] The media in the drive may have changed * This seems to be due to unmounting of the drive before writing the PBR * Also, our ms-sys/NTFS code wasn't identifying NTFS properly on XP --- src/format.c | 8 +++----- src/ms-sys/ntfs.c | 6 +++--- src/rufus.rc | 12 ++++++------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/format.c b/src/format.c index 3aa638cd..932b1b36 100644 --- a/src/format.c +++ b/src/format.c @@ -66,7 +66,6 @@ static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, case FCC_PROGRESS: percent = (DWORD*)pData; PrintStatus(0, FALSE, "Formatting: %d%% completed.", *percent); -// uprintf("%d percent completed.\n", *percent); UpdateProgress(OP_FORMAT, 1.0f * (*percent)); break; case FCC_STRUCTURE_PROGRESS: // No progress on quick format @@ -611,10 +610,8 @@ DWORD WINAPI FormatThread(LPVOID param) FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED; goto out; } - // Make sure the volume is dismounted before writing the PBR - // This is especially critical, as NTFS will only be made bootable - // after the FS is re-mounted by Windows - UnmountDrive(hLogicalVolume); + // NB: if you unmount the logical volume here, XP will report error: + // [0x00000456] The media in the drive may have changed PrintStatus(0, TRUE, "Writing partition boot record..."); if (!WritePBR(hLogicalVolume)) { if (!FormatStatus) @@ -668,6 +665,7 @@ DWORD WINAPI FormatThread(LPVOID param) } if (IsChecked(IDC_SET_ICON)) SetAutorun(drive_name); + UpdateProgress(OP_DOS, -1.0f); // Issue another complete remount before we exit, to ensure we're clean RemountVolume(drive_name[0]); } diff --git a/src/ms-sys/ntfs.c b/src/ms-sys/ntfs.c index 2fa86397..e4b5eb31 100644 --- a/src/ms-sys/ntfs.c +++ b/src/ms-sys/ntfs.c @@ -25,9 +25,9 @@ int is_ntfs_fs(FILE *fp) { - char *szMagic = "NTFS"; + unsigned char aucMagic[] = {'N','T','F','S',' ',' ',' ',' '}; - return contains_data(fp, 0x6F, szMagic, strlen(szMagic)); + return contains_data(fp, 0x03, aucMagic, sizeof(aucMagic)); } /* is_ntfs_fs */ int is_ntfs_br(FILE *fp) @@ -35,7 +35,7 @@ int is_ntfs_br(FILE *fp) /* A "file" is probably some kind of NTFS boot record if it contains the magic chars 0x55, 0xAA at positions 0x1FE */ unsigned char aucRef[] = {0x55, 0xAA}; - unsigned char aucMagic[] = {'N','T','F','S','0','0','0','0'}; + unsigned char aucMagic[] = {'N','T','F','S',' ',' ',' ',' '}; if( ! contains_data(fp, 0x1FE, aucRef, sizeof(aucRef))) return 0; diff --git a/src/rufus.rc b/src/rufus.rc index c73413dd..54191d64 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 206, 289 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW -CAPTION "Rufus v1.1.3.144" +CAPTION "Rufus v1.1.3.145" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN DEFPUSHBUTTON "Start",IDC_START,94,248,50,14 @@ -73,7 +73,7 @@ BEGIN DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP CONTROL "http://rufus.akeo.ie",IDC_ABOUT_RUFUS_URL, "SysLink",WS_TABSTOP,46,47,114,9 - LTEXT "Version 1.1.3 (Build 144)",IDC_STATIC,46,19,78,8 + LTEXT "Version 1.1.3 (Build 145)",IDC_STATIC,46,19,78,8 PUSHBUTTON "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP EDITTEXT IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8 @@ -223,8 +223,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,1,3,144 - PRODUCTVERSION 1,1,3,144 + FILEVERSION 1,1,3,145 + PRODUCTVERSION 1,1,3,145 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -241,13 +241,13 @@ BEGIN BEGIN VALUE "CompanyName", "akeo.ie" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "1.1.3.144" + VALUE "FileVersion", "1.1.3.145" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "1.1.3.144" + VALUE "ProductVersion", "1.1.3.145" END END BLOCK "VarFileInfo"