mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[syslinux] add support for 4K sector size
* Also add 4K sector size support in ms-sys
This commit is contained in:
parent
bf967dc39b
commit
9e7b0bad89
8 changed files with 75 additions and 42 deletions
|
@ -169,123 +169,126 @@ int is_zero_mbr(FILE *fp)
|
|||
/* Don't bother to check 55AA signature */
|
||||
} /* is_zero_mbr */
|
||||
|
||||
/* Handle nonstandard sector sizes (such as 4K) by writing
|
||||
the boot marker at every 512-2 bytes location */
|
||||
static int write_bootmark(FILE *fp)
|
||||
{
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
int pos = 0x1FE;
|
||||
|
||||
/* We use fp->_bufsiz as our sector size indicator */
|
||||
for (pos = 0x1FE; pos < fp->_bufsiz; pos += 0x200) {
|
||||
if (!write_data(fp, pos, aucRef, sizeof(aucRef)))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int write_dos_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_dos.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_dos_0x0, sizeof(mbr_dos_0x0)) &&
|
||||
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
write_bootmark(fp);
|
||||
} /* write_dos_mbr */
|
||||
|
||||
int write_95b_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_95b.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_95b_0x0, sizeof(mbr_95b_0x0)) &&
|
||||
write_data(fp, 0x0e0, mbr_95b_0x0e0, sizeof(mbr_95b_0x0e0)) &&
|
||||
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
write_bootmark(fp);
|
||||
} /* write_95b_mbr */
|
||||
|
||||
int write_2000_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_2000.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_2000_0x0, sizeof(mbr_2000_0x0)) &&
|
||||
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
write_bootmark(fp);
|
||||
} /* write_2000_mbr */
|
||||
|
||||
int write_vista_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_vista.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_vista_0x0, sizeof(mbr_vista_0x0)) &&
|
||||
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
write_bootmark(fp);
|
||||
} /* write_vista_mbr */
|
||||
|
||||
int write_win7_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_win7.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_win7_0x0, sizeof(mbr_win7_0x0)) &&
|
||||
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
write_bootmark(fp);
|
||||
} /* write_win7_mbr */
|
||||
|
||||
int write_rufus_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_rufus.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_rufus_0x0, sizeof(mbr_rufus_0x0)) &&
|
||||
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
write_bootmark(fp);
|
||||
} /* write_rufus_mbr */
|
||||
|
||||
int write_reactos_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_reactos.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_reactos_0x0, sizeof(mbr_reactos_0x0)) &&
|
||||
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
write_bootmark(fp);
|
||||
} /* write_reactos_mbr */
|
||||
|
||||
int write_kolibri_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_kolibri.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_kolibri_0x0, sizeof(mbr_kolibri_0x0)) &&
|
||||
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
write_bootmark(fp);
|
||||
} /* write_kolibri_mbr */
|
||||
|
||||
int write_syslinux_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_syslinux.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_syslinux_0x0, sizeof(mbr_syslinux_0x0)) &&
|
||||
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
write_bootmark(fp);
|
||||
} /* write_syslinux_mbr */
|
||||
|
||||
int write_grub_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_grub.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_grub_0x0, sizeof(mbr_grub_0x0)) &&
|
||||
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
write_bootmark(fp);
|
||||
}
|
||||
|
||||
int write_grub2_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_grub2.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_grub2_0x0, sizeof(mbr_grub2_0x0)) &&
|
||||
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
write_bootmark(fp);
|
||||
}
|
||||
|
||||
int write_zero_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_zero.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_zero_0x0, sizeof(mbr_zero_0x0)) &&
|
||||
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
write_bootmark(fp);
|
||||
} /* write_zero_mbr */
|
||||
|
|
16
src/rufus.rc
16
src/rufus.rc
|
@ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
|
|||
|
||||
IDD_DIALOG DIALOGEX 12, 12, 242, 376
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Rufus 2.2.668"
|
||||
CAPTION "Rufus 2.2.669"
|
||||
FONT 8, "Segoe UI", 400, 0, 0x1
|
||||
BEGIN
|
||||
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
|
||||
|
@ -157,7 +157,7 @@ END
|
|||
|
||||
IDD_DIALOG_XP DIALOGEX 12, 12, 242, 376
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Rufus 2.2.668"
|
||||
CAPTION "Rufus 2.2.669"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
|
||||
|
@ -283,7 +283,7 @@ END
|
|||
IDD_DIALOG_RTL DIALOGEX 12, 12, 242, 376
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
|
||||
CAPTION "Rufus 2.2.668"
|
||||
CAPTION "Rufus 2.2.669"
|
||||
FONT 8, "Segoe UI", 400, 0, 0x1
|
||||
BEGIN
|
||||
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
|
||||
|
@ -415,7 +415,7 @@ END
|
|||
IDD_DIALOG_RTL_XP DIALOGEX 12, 12, 242, 376
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
|
||||
CAPTION "Rufus 2.2.668"
|
||||
CAPTION "Rufus 2.2.669"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
|
||||
|
@ -671,8 +671,8 @@ END
|
|||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 2,2,668,0
|
||||
PRODUCTVERSION 2,2,668,0
|
||||
FILEVERSION 2,2,669,0
|
||||
PRODUCTVERSION 2,2,669,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
|
@ -689,13 +689,13 @@ BEGIN
|
|||
BEGIN
|
||||
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
|
||||
VALUE "FileDescription", "Rufus"
|
||||
VALUE "FileVersion", "2.2.668"
|
||||
VALUE "FileVersion", "2.2.669"
|
||||
VALUE "InternalName", "Rufus"
|
||||
VALUE "LegalCopyright", "© 2011-2015 Pete Batard (GPL v3)"
|
||||
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
||||
VALUE "OriginalFilename", "rufus.exe"
|
||||
VALUE "ProductName", "Rufus"
|
||||
VALUE "ProductVersion", "2.2.668"
|
||||
VALUE "ProductVersion", "2.2.669"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
|
|
@ -43,6 +43,13 @@ DWORD syslinux_ldlinux_len[2];
|
|||
unsigned char* syslinux_mboot = NULL;
|
||||
DWORD syslinux_mboot_len;
|
||||
|
||||
// Workaround for 4K support
|
||||
uint32_t SECTOR_SHIFT = 9;
|
||||
uint32_t SECTOR_SIZE = 512;
|
||||
uint32_t LIBFAT_SECTOR_SHIFT = 9;
|
||||
uint32_t LIBFAT_SECTOR_SIZE = 512;
|
||||
uint32_t LIBFAT_SECTOR_MASK = 511;
|
||||
|
||||
/*
|
||||
* Wrapper for ReadFile suitable for libfat
|
||||
*/
|
||||
|
@ -82,7 +89,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type)
|
|||
FILE* fd;
|
||||
size_t length;
|
||||
|
||||
static unsigned char sectbuf[SECTOR_SIZE];
|
||||
static unsigned char* sectbuf = NULL;
|
||||
static char* resource[2][2] = {
|
||||
{ MAKEINTRESOURCEA(IDR_SL_LDLINUX_V4_SYS), MAKEINTRESOURCEA(IDR_SL_LDLINUX_V4_BSS) },
|
||||
{ MAKEINTRESOURCEA(IDR_SL_LDLINUX_V6_SYS), MAKEINTRESOURCEA(IDR_SL_LDLINUX_V6_BSS) } };
|
||||
|
@ -102,6 +109,20 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type)
|
|||
|
||||
PrintInfoDebug(0, MSG_234, (dt == DT_ISO)?iso_report.sl_version_str:embedded_sl_version_str[use_v5?1:0]);
|
||||
|
||||
// 4K sector size workaround
|
||||
SECTOR_SHIFT = 0;
|
||||
SECTOR_SIZE = SelectedDrive.Geometry.BytesPerSector;
|
||||
while (SECTOR_SIZE>>=1)
|
||||
SECTOR_SHIFT++;
|
||||
SECTOR_SIZE = SelectedDrive.Geometry.BytesPerSector;
|
||||
LIBFAT_SECTOR_SHIFT = SECTOR_SHIFT;
|
||||
LIBFAT_SECTOR_SIZE = SECTOR_SIZE;
|
||||
LIBFAT_SECTOR_MASK = SECTOR_SIZE - 1;
|
||||
|
||||
sectbuf = malloc(SECTOR_SIZE);
|
||||
if (sectbuf == NULL)
|
||||
goto out;
|
||||
|
||||
/* Initialize the ADV -- this should be smarter */
|
||||
syslinux_reset_adv(syslinux_adv);
|
||||
|
||||
|
@ -335,6 +356,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type)
|
|||
r = TRUE;
|
||||
|
||||
out:
|
||||
safe_free(sectbuf);
|
||||
safe_free(syslinux_ldlinux[0]);
|
||||
safe_free(syslinux_ldlinux[1]);
|
||||
safe_free(sectors);
|
||||
|
|
|
@ -29,10 +29,10 @@ void *libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n)
|
|||
}
|
||||
|
||||
/* Not found in cache */
|
||||
ls = malloc(sizeof(struct libfat_sector));
|
||||
ls = malloc(sizeof(struct libfat_sector) + LIBFAT_SECTOR_SIZE);
|
||||
if (!ls) {
|
||||
libfat_flush(fs);
|
||||
ls = malloc(sizeof(struct libfat_sector));
|
||||
ls = malloc(sizeof(struct libfat_sector) + LIBFAT_SECTOR_SIZE);
|
||||
|
||||
if (!ls)
|
||||
return NULL; /* Can't allocate memory */
|
||||
|
|
|
@ -22,9 +22,14 @@
|
|||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#define LIBFAT_SECTOR_SHIFT 9
|
||||
#define LIBFAT_SECTOR_SIZE 512
|
||||
#define LIBFAT_SECTOR_MASK 511
|
||||
// Workaround for 4K support
|
||||
extern uint32_t LIBFAT_SECTOR_SHIFT;
|
||||
extern uint32_t LIBFAT_SECTOR_SIZE;
|
||||
extern uint32_t LIBFAT_SECTOR_MASK;
|
||||
#define MAX_LIBFAT_SECTOR_SIZE 4096
|
||||
//#define LIBFAT_SECTOR_SHIFT 9
|
||||
//#define LIBFAT_SECTOR_SIZE 512
|
||||
//#define LIBFAT_SECTOR_MASK 511
|
||||
|
||||
typedef uint64_t libfat_sector_t;
|
||||
struct libfat_filesystem;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
struct libfat_sector {
|
||||
libfat_sector_t n; /* Sector number */
|
||||
struct libfat_sector *next; /* Next in list */
|
||||
char data[LIBFAT_SECTOR_SIZE];
|
||||
char data[0];
|
||||
};
|
||||
|
||||
enum fat_type {
|
||||
|
|
|
@ -25,7 +25,7 @@ int32_t libfat_searchdir(struct libfat_filesystem *fs, int32_t dirclust,
|
|||
const void *name, struct libfat_direntry *direntry)
|
||||
{
|
||||
struct fat_dirent *dep;
|
||||
int nent;
|
||||
unsigned int nent;
|
||||
libfat_sector_t s = libfat_clustertosector(fs, dirclust);
|
||||
|
||||
while (1) {
|
||||
|
|
|
@ -41,8 +41,11 @@ extern const unsigned int syslinux_mbr_len;
|
|||
extern const int syslinux_mbr_mtime;
|
||||
|
||||
/* Sector size assumptions... */
|
||||
#define SECTOR_SHIFT 9
|
||||
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
|
||||
// Workaround for 4K support
|
||||
extern uint32_t SECTOR_SHIFT;
|
||||
extern uint32_t SECTOR_SIZE;
|
||||
//#define SECTOR_SHIFT 9
|
||||
//#define SECTOR_SIZE (1 << SECTOR_SHIFT)
|
||||
|
||||
/* This takes a boot sector and merges in the syslinux fields */
|
||||
void syslinux_make_bootsect(void *bs, int fs_type);
|
||||
|
|
Loading…
Reference in a new issue