1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[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()
This commit is contained in:
Pete Batard 2011-12-14 20:48:20 +00:00
parent 0600005a09
commit ed4297609e
12 changed files with 126 additions and 28 deletions

4
README
View file

@ -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

View file

@ -155,6 +155,7 @@
<ClCompile Include="..\file.c" />
<ClCompile Include="..\format.c" />
<ClCompile Include="..\msdos.c" />
<ClCompile Include="..\partition_info.c" />
<ClCompile Include="..\rufus.c" />
<ClCompile Include="..\stdio.c" />
<ClCompile Include="..\stdlg.c" />
@ -190,6 +191,7 @@
<ClInclude Include="..\inc\mbr_vista.h" />
<ClInclude Include="..\inc\mbr_win7.h" />
<ClInclude Include="..\inc\mbr_zero.h" />
<ClInclude Include="..\inc\partition_info.h" />
<ClInclude Include="..\msapi_utf8.h" />
<ClInclude Include="..\msdos.h" />
<ClInclude Include="..\rufus.h" />

View file

@ -54,6 +54,9 @@
<ClCompile Include="..\badblocks.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\partition_info.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\rufus.h">
@ -161,6 +164,9 @@
<ClInclude Include="..\badblocks.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\inc\partition_info.h">
<Filter>Header Files\ms-sys inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\rufus.ico">

View file

@ -35,4 +35,5 @@ SOURCES=rufus.c \
fat12.c \
fat16.c \
fat32.c \
partition_info.c \
rufus.rc

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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)) );

View file

@ -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;
}

16
src/inc/partition_info.h Normal file
View file

@ -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

67
src/partition_info.c Normal file
View file

@ -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 <stdio.h>
#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 */

View file

@ -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 "<a href=""http://rufus.akeo.ie"">http://rufus.akeo.ie</a>",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"