From ed4297609ec13c291249fd2eec35b698791a7ae9 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Wed, 14 Dec 2011 20:48:20 +0000 Subject: [PATCH] [fat] use ms-sys' partition_info source to correct Disk Drive ID * Disk Drive ID fixup for FAT32 was already available in ms-sys with option -p * modified code to add FAT16 as well as FAT32 support as well as minor fixes * reverts previous patch write_fat_32_br() and write_fat_16_br() --- README | 4 +- src/.msvc/rufus_2010.vcxproj | 2 + src/.msvc/rufus_2010.vcxproj.filters | 6 +++ src/.msvc/rufus_sources | 1 + src/Makefile.am | 2 +- src/Makefile.in | 20 ++++++--- src/fat16.c | 9 +--- src/fat32.c | 5 --- src/format.c | 10 ++++- src/inc/partition_info.h | 16 +++++++ src/partition_info.c | 67 ++++++++++++++++++++++++++++ src/rufus.rc | 12 ++--- 12 files changed, 126 insertions(+), 28 deletions(-) create mode 100644 src/inc/partition_info.h create mode 100644 src/partition_info.c diff --git a/README b/README index feb318d0..ee30ec09 100644 --- a/README +++ b/README @@ -10,9 +10,11 @@ Features: Compilation: Use either Visual Studio 2010, WDK (Windows Driver Kit) or MinGW and then invoke the .sln, wdk_build.cmd or configure/make respectively. + Remember that you can get plenty of useful information about what Rufus + is doing through a Windows debugger such as DebugView. More info: - https://github.com/pbatard/rufus/wiki/Rufus + http://rufus.akeo.ie Enhancements/Bugs https://github.com/pbatard/rufus/issues diff --git a/src/.msvc/rufus_2010.vcxproj b/src/.msvc/rufus_2010.vcxproj index 12a1a896..dffe0f9f 100644 --- a/src/.msvc/rufus_2010.vcxproj +++ b/src/.msvc/rufus_2010.vcxproj @@ -155,6 +155,7 @@ + @@ -190,6 +191,7 @@ + diff --git a/src/.msvc/rufus_2010.vcxproj.filters b/src/.msvc/rufus_2010.vcxproj.filters index d6b4d3e0..8bcbbec1 100644 --- a/src/.msvc/rufus_2010.vcxproj.filters +++ b/src/.msvc/rufus_2010.vcxproj.filters @@ -54,6 +54,9 @@ Source Files + + Source Files + @@ -161,6 +164,9 @@ Header Files + + Header Files\ms-sys inc + diff --git a/src/.msvc/rufus_sources b/src/.msvc/rufus_sources index 9982e36e..b4728474 100644 --- a/src/.msvc/rufus_sources +++ b/src/.msvc/rufus_sources @@ -35,4 +35,5 @@ SOURCES=rufus.c \ fat12.c \ fat16.c \ fat32.c \ + partition_info.c \ rufus.rc diff --git a/src/Makefile.am b/src/Makefile.am index e57b3725..27051c82 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,7 +9,7 @@ pkg_v_rc_0 = @echo " RC $@"; %_rc.o: %.rc $(pkg_v_rc)$(WINDRES) -i $< -o $@ -rufus_SOURCES = fat12.c fat16.c fat32.c br.c file.c drive.c msdos.c badblocks.c format.c stdio.c stdlg.c rufus.c +rufus_SOURCES = fat12.c fat16.c fat32.c partition_info.c br.c file.c drive.c msdos.c badblocks.c format.c stdio.c stdlg.c rufus.c rufus_CFLAGS = -I./inc $(ARCH_CFLAGS) $(AM_CFLAGS) rufus_LDFLAGS = $(AM_LDFLAGS) -mwindows rufus_LDADD = rufus_rc.o -lsetupapi -lole32 -lgdi32 diff --git a/src/Makefile.in b/src/Makefile.in index a423f1e2..0b0e0076 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -46,11 +46,11 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = PROGRAMS = $(noinst_PROGRAMS) am_rufus_OBJECTS = rufus-fat12.$(OBJEXT) rufus-fat16.$(OBJEXT) \ - rufus-fat32.$(OBJEXT) rufus-br.$(OBJEXT) rufus-file.$(OBJEXT) \ - rufus-drive.$(OBJEXT) rufus-msdos.$(OBJEXT) \ - rufus-badblocks.$(OBJEXT) rufus-format.$(OBJEXT) \ - rufus-stdio.$(OBJEXT) rufus-stdlg.$(OBJEXT) \ - rufus-rufus.$(OBJEXT) + rufus-fat32.$(OBJEXT) rufus-partition_info.$(OBJEXT) \ + rufus-br.$(OBJEXT) rufus-file.$(OBJEXT) rufus-drive.$(OBJEXT) \ + rufus-msdos.$(OBJEXT) rufus-badblocks.$(OBJEXT) \ + rufus-format.$(OBJEXT) rufus-stdio.$(OBJEXT) \ + rufus-stdlg.$(OBJEXT) rufus-rufus.$(OBJEXT) rufus_OBJECTS = $(am_rufus_OBJECTS) rufus_DEPENDENCIES = rufus_rc.o rufus_LINK = $(CCLD) $(rufus_CFLAGS) $(CFLAGS) $(rufus_LDFLAGS) \ @@ -168,7 +168,7 @@ top_srcdir = @top_srcdir@ pkg_v_rc = $(pkg_v_rc_$(V)) pkg_v_rc_ = $(pkg_v_rc_$(AM_DEFAULT_VERBOSITY)) pkg_v_rc_0 = @echo " RC $@"; -rufus_SOURCES = fat12.c fat16.c fat32.c br.c file.c drive.c msdos.c badblocks.c format.c stdio.c stdlg.c rufus.c +rufus_SOURCES = fat12.c fat16.c fat32.c partition_info.c br.c file.c drive.c msdos.c badblocks.c format.c stdio.c stdlg.c rufus.c rufus_CFLAGS = -I./inc $(ARCH_CFLAGS) $(AM_CFLAGS) rufus_LDFLAGS = $(AM_LDFLAGS) -mwindows rufus_LDADD = rufus_rc.o -lsetupapi -lole32 -lgdi32 @@ -251,6 +251,14 @@ rufus-fat32.obj: fat32.c $(AM_V_CC) @AM_BACKSLASH@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-fat32.obj `if test -f 'fat32.c'; then $(CYGPATH_W) 'fat32.c'; else $(CYGPATH_W) '$(srcdir)/fat32.c'; fi` +rufus-partition_info.o: partition_info.c + $(AM_V_CC) @AM_BACKSLASH@ + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-partition_info.o `test -f 'partition_info.c' || echo '$(srcdir)/'`partition_info.c + +rufus-partition_info.obj: partition_info.c + $(AM_V_CC) @AM_BACKSLASH@ + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-partition_info.obj `if test -f 'partition_info.c'; then $(CYGPATH_W) 'partition_info.c'; else $(CYGPATH_W) '$(srcdir)/partition_info.c'; fi` + rufus-br.o: br.c $(AM_V_CC) @AM_BACKSLASH@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-br.o `test -f 'br.c' || echo '$(srcdir)/'`br.c diff --git a/src/fat16.c b/src/fat16.c index 92fcd48a..46f0a9e1 100644 --- a/src/fat16.c +++ b/src/fat16.c @@ -58,23 +58,18 @@ int write_fat_16_br(FILE *fp, int bKeepLabel) #include "label_11_char.h" #include "br_fat16_0x0.h" #include "br_fat16_0x3e.h" - const unsigned char offset_x24 = 0x80; if(bKeepLabel) return ( write_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) && /* BIOS Parameter Block should not be overwritten */ - write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) && - /* except offset 0x24 which may have to be corrected */ - write_data(fp, 0x24, &offset_x24, 1) ); + write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) ); else return ( write_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) && /* BIOS Parameter Block should not be overwritten */ write_data(fp, 0x2b, label_11_char, sizeof(label_11_char)) && - write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) && - /* except offset 0x24 which may have to be corrected */ - write_data(fp, 0x24, &offset_x24, 1) ); + write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) ); } /* write_fat_16_br */ int entire_fat_16_fd_br_matches(FILE *fp) diff --git a/src/fat32.c b/src/fat32.c index 40f8c9fa..8b785b5d 100644 --- a/src/fat32.c +++ b/src/fat32.c @@ -64,15 +64,12 @@ int write_fat_32_br(FILE *fp, int bKeepLabel) #include "br_fat32_0x0.h" #include "br_fat32_0x52.h" #include "br_fat32_0x3f0.h" - const unsigned char offset_x40 = 0x80; if(bKeepLabel) return ( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) && /* BIOS Parameter Block should not be overwritten */ write_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) && - /* except offset 0x40 which may have to be corrected */ - write_data(fp, 0x40, &offset_x40, 1) && /* Cluster information is not overwritten, however, it would bo OK to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */ write_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) ); @@ -82,8 +79,6 @@ int write_fat_32_br(FILE *fp, int bKeepLabel) /* BIOS Parameter Block should not be overwritten */ write_data(fp, 0x47, label_11_char, sizeof(label_11_char)) && write_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) && - /* except offset 0x40 which may have to be corrected */ - write_data(fp, 0x40, &offset_x40, 1) && /* Cluster information is not overwritten, however, it would bo OK to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */ write_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) ); diff --git a/src/format.c b/src/format.c index 8c6f2b9b..fe041d7f 100644 --- a/src/format.c +++ b/src/format.c @@ -35,6 +35,7 @@ #include "br.h" #include "fat16.h" #include "fat32.h" +#include "partition_info.h" #include "file.h" #include "format.h" #include "badblocks.h" @@ -325,6 +326,7 @@ static BOOL WritePBR(HANDLE hLogicalVolume) fake_fd._ptr = (char*)hLogicalVolume; fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector; + // TODO: call write_partition_number_of_heads() and write_partition_start_sector_number()? switch (ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem))) { case FS_FAT16: if (!is_fat_16_fs(&fake_fd)) { @@ -332,7 +334,9 @@ static BOOL WritePBR(HANDLE hLogicalVolume) break; } uprintf("Confirmed new volume has a FAT16 boot sector\n"); - if (!write_fat_16_br(&fake_fd, 0)) + if (!write_fat_16_br(&fake_fd, 0) || + // Disk Drive ID needs to be corrected on XP + !write_partition_physical_disk_drive_id_fat16(&fake_fd)) break; return TRUE; case FS_FAT32: @@ -343,7 +347,9 @@ static BOOL WritePBR(HANDLE hLogicalVolume) } uprintf("Confirmed new volume has a %s FAT32 boot sector\n", i?"secondary":"primary"); uprintf("Setting %s FAT32 boot sector for DOS boot...\n", i?"secondary":"primary"); - if (!write_fat_32_br(&fake_fd, 0)) + if (!write_fat_32_br(&fake_fd, 0) || + // Disk Drive ID needs to be corrected on XP + !write_partition_physical_disk_drive_id_fat32(&fake_fd)) break; fake_fd._cnt += 6 * (int)SelectedDrive.Geometry.BytesPerSector; } diff --git a/src/inc/partition_info.h b/src/inc/partition_info.h new file mode 100644 index 00000000..4be1a7cf --- /dev/null +++ b/src/inc/partition_info.h @@ -0,0 +1,16 @@ +#ifndef PARTITION_INFO_H +#define PARTITION_INFO_H + +/* Writes the number of heads to a partition + returns TRUE on success, otherwise FALSE */ +int write_partition_number_of_heads(FILE *fp, int iHeads); + +/* Writes the start sector number to a partition (also known as + "number of hidden sectors"), returns TRUE on success, otherwise FALSE */ +int write_partition_start_sector_number(FILE *fp, int iStartSector); + +/* Writes a physical disk drive id of 0x80 (for C:) to a partition */ +int write_partition_physical_disk_drive_id_fat16(FILE *fp); +int write_partition_physical_disk_drive_id_fat32(FILE *fp); + +#endif diff --git a/src/partition_info.c b/src/partition_info.c new file mode 100644 index 00000000..e1200a86 --- /dev/null +++ b/src/partition_info.c @@ -0,0 +1,67 @@ +/****************************************************************** + Copyright (C) 2009 Henrik Carlqvist + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +******************************************************************/ +#include + +#include "file.h" +#include "partition_info.h" + +int write_partition_number_of_heads(FILE *fp, int iHeads) +{ + unsigned char aucBuf[2]; + unsigned short s = (unsigned short) iHeads; + + if(!s) + return 0; + /* Converting a number like this is not necessary as long as we are on + i386 compatible CPUs, however, the following code might make the program + more portable... */ + aucBuf[0] = (unsigned char)(s & 0xff); + aucBuf[1] = (unsigned char)((s & 0xff00) >> 8); + return write_data(fp, 0x1a, aucBuf, 2); +} /* write_partition_number_of_heads */ + +int write_partition_start_sector_number(FILE *fp, int iStartSector) +{ + unsigned char aucBuf[4]; + unsigned long l = (unsigned long)iStartSector; + + if(!l) + return 0; + /* Converting a number like this is not necessary as long as we are on + i386 compatible CPUs, however, the following code might make the program + more portable... */ + aucBuf[0] = (unsigned char)(l & 0xff); + aucBuf[1] = (unsigned char)((l & 0xff00) >> 8); + aucBuf[2] = (unsigned char)((l & 0xff0000) >> 16); + aucBuf[3] = (unsigned char)((l & 0xff000000) >> 24); + return write_data(fp, 0x1c, aucBuf, 4); +} /* write_partition_start_sector_number */ + +int write_partition_physical_disk_drive_id_fat32(FILE *fp) +{ + unsigned char ucId = 0x80; /* C: */ + + return write_data(fp, 0x40, &ucId, 1); +} /* write_partition_physical_disk_drive_id_fat32 */ + +int write_partition_physical_disk_drive_id_fat16(FILE *fp) +{ + unsigned char ucId = 0x80; /* C: */ + + return write_data(fp, 0x24, &ucId, 1); +} /* write_partition_physical_disk_drive_id_fat16 */ diff --git a/src/rufus.rc b/src/rufus.rc index 0a5b7295..6cf84f35 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -30,7 +30,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 206, 278 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW -CAPTION "Rufus v1.0.3.94" +CAPTION "Rufus v1.0.3.95" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN DEFPUSHBUTTON "Start",IDC_START,94,236,50,14 @@ -64,7 +64,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.0.3 (Build 94)",IDC_STATIC,46,19,78,8 + LTEXT "Version 1.0.3 (Build 95)",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 @@ -163,8 +163,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,3,94 - PRODUCTVERSION 1,0,3,94 + FILEVERSION 1,0,3,95 + PRODUCTVERSION 1,0,3,95 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -181,13 +181,13 @@ BEGIN BEGIN VALUE "CompanyName", "akeo.ie" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "1.0.3.94" + VALUE "FileVersion", "1.0.3.95" 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.0.3.94" + VALUE "ProductVersion", "1.0.3.95" END END BLOCK "VarFileInfo"