mirror of
https://github.com/pbatard/rufus.git
synced 2025-06-05 17:14:26 -04:00
[ms-sys] update ms-sys to current
* NB: This includes an updated Syslinux MBR
This commit is contained in:
parent
cc65d0494d
commit
b77561bb9b
15 changed files with 312 additions and 120 deletions
127
src/ms-sys/br.c
127
src/ms-sys/br.c
|
@ -1,5 +1,5 @@
|
|||
/******************************************************************
|
||||
Copyright (C) 2009 Henrik Carlqvist
|
||||
Copyright (C) 2009-2015 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
|
||||
|
@ -20,13 +20,35 @@
|
|||
#include "file.h"
|
||||
#include "br.h"
|
||||
|
||||
unsigned long ulBytesPerSector = 512;
|
||||
|
||||
void set_bytes_per_sector(unsigned long ulValue)
|
||||
{
|
||||
ulBytesPerSector = ulValue;
|
||||
if ((ulBytesPerSector < 512) || (ulBytesPerSector > 65536))
|
||||
ulBytesPerSector = 512;
|
||||
} /* set_bytes_per_sector */
|
||||
|
||||
uint32_t read_windows_disk_signature(FILE *fp)
|
||||
{
|
||||
uint32_t tWDS;
|
||||
if(!read_data(fp, 0x1b8, &tWDS, 4))
|
||||
return 0;
|
||||
return tWDS;
|
||||
} /* read_windows_disk_signature */
|
||||
|
||||
int write_windows_disk_signature(FILE *fp, uint32_t tWDS)
|
||||
{
|
||||
return write_data(fp, 0x1b8, &tWDS, 4);
|
||||
} /* write_windows_disk_signature */
|
||||
|
||||
int is_br(FILE *fp)
|
||||
{
|
||||
/* A "file" is probably some kind of boot record if it contains the magic
|
||||
chars 0x55, 0xAA at position 0x1FE */
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
return contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
} /* is_br */
|
||||
|
||||
int is_lilo_br(FILE *fp)
|
||||
|
@ -36,130 +58,128 @@ int is_lilo_br(FILE *fp)
|
|||
unsigned char aucRef[] = {'L','I','L','O'};
|
||||
|
||||
return ( contains_data(fp, 0x6, aucRef, sizeof(aucRef)) ||
|
||||
contains_data(fp, 0x2, aucRef, sizeof(aucRef)) );
|
||||
contains_data(fp, 0x2, aucRef, sizeof(aucRef)) );
|
||||
} /* is_lilo_br */
|
||||
|
||||
int is_dos_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_dos.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_dos_0x0, sizeof(mbr_dos_0x0)) &&
|
||||
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
is_br(fp);
|
||||
} /* is_dos_mbr */
|
||||
|
||||
int is_dos_f2_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_dos_f2.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_dos_f2_0x0, sizeof(mbr_dos_f2_0x0)) &&
|
||||
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
is_br(fp);
|
||||
} /* is_dos_f2_mbr */
|
||||
|
||||
int is_95b_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_95b.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_95b_0x0, sizeof(mbr_95b_0x0)) &&
|
||||
contains_data(fp, 0x0e0, mbr_95b_0x0e0, sizeof(mbr_95b_0x0e0)) &&
|
||||
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
is_br(fp);
|
||||
} /* is_95b_mbr */
|
||||
|
||||
int is_2000_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_2000.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_2000_0x0, sizeof(mbr_2000_0x0)) &&
|
||||
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
is_br(fp);
|
||||
} /* is_2000_mbr */
|
||||
|
||||
int is_vista_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_vista.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_vista_0x0, sizeof(mbr_vista_0x0)) &&
|
||||
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
is_br(fp);
|
||||
} /* is_vista_mbr */
|
||||
|
||||
int is_win7_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_win7.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_win7_0x0, sizeof(mbr_win7_0x0)) &&
|
||||
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
is_br(fp);
|
||||
} /* is_win7_mbr */
|
||||
|
||||
int is_rufus_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_rufus.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_rufus_0x0, sizeof(mbr_rufus_0x0)) &&
|
||||
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
is_br(fp);
|
||||
} /* is_rufus_mbr */
|
||||
|
||||
int is_reactos_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_reactos.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_reactos_0x0, sizeof(mbr_reactos_0x0)) &&
|
||||
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
is_br(fp);
|
||||
} /* is_reactos_mbr */
|
||||
|
||||
int is_grub_mbr(FILE *fp)
|
||||
int is_grub4dos_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_grub.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_grub_0x0, sizeof(mbr_grub_0x0)) &&
|
||||
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
is_br(fp);
|
||||
} /* is_grub_mbr */
|
||||
|
||||
int is_grub2_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_grub2.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_grub2_0x0, sizeof(mbr_grub2_0x0)) &&
|
||||
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
is_br(fp);
|
||||
} /* is_grub2_mbr */
|
||||
|
||||
int is_kolibri_mbr(FILE *fp)
|
||||
int is_kolibrios_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_kolibri.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_kolibri_0x0, sizeof(mbr_kolibri_0x0)) &&
|
||||
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
is_br(fp);
|
||||
} /* is_kolibri_mbr */
|
||||
|
||||
int is_syslinux_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_syslinux.h"
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_syslinux_0x0, sizeof(mbr_syslinux_0x0)) &&
|
||||
contains_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||
is_br(fp);
|
||||
} /* is_syslinux_mbr */
|
||||
|
||||
int is_syslinux_gpt_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_gpt_syslinux.h"
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_gpt_syslinux_0x0,
|
||||
sizeof(mbr_gpt_syslinux_0x0)) &&
|
||||
is_br(fp);
|
||||
} /* is_syslinux_gpt_mbr */
|
||||
|
||||
int is_zero_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_zero.h"
|
||||
|
@ -169,19 +189,37 @@ int is_zero_mbr(FILE *fp)
|
|||
/* Don't bother to check 55AA signature */
|
||||
} /* is_zero_mbr */
|
||||
|
||||
int is_zero_mbr_with_other_windows_disk_signature(FILE *fp)
|
||||
{
|
||||
#include "mbr_zero.h"
|
||||
|
||||
return
|
||||
(!contains_data(fp, 0x0, mbr_zero_0x0, sizeof(mbr_zero_0x0))) &&
|
||||
contains_data(fp, 0x0, mbr_zero_0x0, 0x1b8);
|
||||
contains_data(fp, 0x1bc, mbr_zero_0x0, 2);
|
||||
/* Don't bother to check 55AA signature */
|
||||
} /* is_zero_mbr_with_other_windows_disk_signature */
|
||||
|
||||
int is_zero_mbr_not_including_disk_signature_or_copy_protect(FILE *fp)
|
||||
{
|
||||
#include "mbr_zero.h"
|
||||
|
||||
return
|
||||
contains_data(fp, 0x0, mbr_zero_0x0, 0x1b8);
|
||||
} /* is_zero_mbr_not_including_disk_signature_or_copy_protect */
|
||||
|
||||
/* 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};
|
||||
uint32_t pos = 0x1FE;
|
||||
FAKE_FD* fd = (FAKE_FD*)fp;
|
||||
unsigned char aucRef[] = {0x55, 0xAA};
|
||||
unsigned long pos = 0x1FE;
|
||||
|
||||
for (pos = 0x1FE; pos < fd->_sector_size; pos += 0x200) {
|
||||
if (!write_data(fp, pos, aucRef, sizeof(aucRef)))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
for (pos = 0x1FE; pos < ulBytesPerSector; pos += 0x200) {
|
||||
if (!write_data(fp, pos, aucRef, sizeof(aucRef)))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int write_dos_mbr(FILE *fp)
|
||||
|
@ -248,7 +286,7 @@ int write_reactos_mbr(FILE *fp)
|
|||
write_bootmark(fp);
|
||||
} /* write_reactos_mbr */
|
||||
|
||||
int write_kolibri_mbr(FILE *fp)
|
||||
int write_kolibrios_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_kolibri.h"
|
||||
|
||||
|
@ -266,7 +304,16 @@ int write_syslinux_mbr(FILE *fp)
|
|||
write_bootmark(fp);
|
||||
} /* write_syslinux_mbr */
|
||||
|
||||
int write_grub_mbr(FILE *fp)
|
||||
int write_syslinux_gpt_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_gpt_syslinux.h"
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_gpt_syslinux_0x0, sizeof(mbr_gpt_syslinux_0x0)) &&
|
||||
write_bootmark(fp);
|
||||
} /* write_syslinux_gpt_mbr */
|
||||
|
||||
int write_grub4dos_mbr(FILE *fp)
|
||||
{
|
||||
#include "mbr_grub.h"
|
||||
|
||||
|
@ -289,6 +336,6 @@ int write_zero_mbr(FILE *fp)
|
|||
#include "mbr_zero.h"
|
||||
|
||||
return
|
||||
write_data(fp, 0x0, mbr_zero_0x0, sizeof(mbr_zero_0x0)) &&
|
||||
write_data(fp, 0x0, mbr_zero_0x0, sizeof(mbr_zero_0x0)) &&
|
||||
write_bootmark(fp);
|
||||
} /* write_zero_mbr */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue