1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00
rufus/src/ms-sys/fat16.c
Pete Batard 573ea45640 [core] add support for bare ReactOS boot record installation
* A new "ReactOS" is now available under "Create a bootable disk" when running in advanced mode.
* Using this option will install the ReactOS bootblocks (MBR & FAT PBR) _only_.
  You can then copy freeldr.sys and freeldr.ini to make the drive bootable.
* Also move Rufus MBR installation to ms-sys, and remove mbr.bin resource.
* Also add Rufus MBR detection, remove duplicate records and display MBR type on drive detection
* Also move PBR and MBR analysis calls to drive.c and add a drive.h header
* Also make extraction of embedded loc file more robust
2014-01-05 01:39:41 +00:00

133 lines
4.5 KiB
C

/******************************************************************
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 <string.h>
#include "file.h"
#include "fat16.h"
int is_fat_16_fs(FILE *fp)
{
char *szMagic = "FAT16 ";
return contains_data(fp, 0x36, szMagic, strlen(szMagic));
} /* is_fat_16_fs */
int is_fat_16_br(FILE *fp)
{
/* A "file" is probably some kind of FAT16 boot record if it contains the
magic chars 0x55, 0xAA at positions 0x1FE */
unsigned char aucRef[] = {0x55, 0xAA};
unsigned char aucMagic[] = {'M','S','W','I','N','4','.','1'};
if( ! contains_data(fp, 0x1FE, aucRef, sizeof(aucRef)))
return 0;
if( ! contains_data(fp, 0x03, aucMagic, sizeof(aucMagic)))
return 0;
return 1;
} /* is_fat_16_br */
int entire_fat_16_br_matches(FILE *fp)
{
#include "br_fat16_0x0.h"
#include "br_fat16_0x3e.h"
return
( contains_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
/* BIOS Parameter Block might differ between systems */
contains_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
} /* entire_fat_16_br_matches */
int write_fat_16_br(FILE *fp, int bKeepLabel)
{
#include "label_11_char.h"
#include "br_fat16_0x0.h"
#include "br_fat16_0x3e.h"
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)) );
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)) );
} /* write_fat_16_br */
int entire_fat_16_fd_br_matches(FILE *fp)
{
#include "br_fat16_0x0.h"
#include "br_fat16fd_0x3e.h"
return
( contains_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
/* BIOS Parameter Block might differ between systems */
contains_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
} /* entire_fat_16_fd_br_matches */
int write_fat_16_fd_br(FILE *fp, int bKeepLabel)
{
#include "label_11_char.h"
#include "br_fat16_0x0.h"
#include "br_fat16fd_0x3e.h"
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)) );
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)) );
} /* write_fat_16_fd_br */
int entire_fat_16_ros_br_matches(FILE *fp)
{
#include "br_fat16ros_0x0.h"
#include "br_fat16ros_0x3e.h"
return
( contains_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
/* BIOS Parameter Block might differ between systems */
contains_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
} /* entire_fat_16_ros_br_matches */
int write_fat_16_ros_br(FILE *fp, int bKeepLabel)
{
#include "label_11_char.h"
#include "br_fat16ros_0x0.h"
#include "br_fat16ros_0x3e.h"
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)) );
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)) );
} /* write_fat_16_ros_br */