2003-01-17 13:18:15 +00:00
/*
* COPYRIGHT : See COPYING in the top level directory
* PROJECT : ReactOS text - mode setup
2015-09-13 16:40:36 +00:00
* FILE : base / setup / usetup / bootsup . c
2003-01-17 13:18:15 +00:00
* PURPOSE : Bootloader support functions
* PROGRAMMER : Eric Kohl
*/
2006-08-31 09:13:03 +00:00
# include "usetup.h"
2003-01-17 13:18:15 +00:00
2010-06-07 21:38:49 +00:00
# define NDEBUG
2003-12-01 18:28:54 +00:00
# include <debug.h>
2003-01-17 13:18:15 +00:00
2003-01-28 17:29:22 +00:00
# define SECTORSIZE 512
2010-09-06 01:46:06 +00:00
# include <pshpack1.h>
typedef struct _FAT_BOOTSECTOR
{
2011-07-20 17:54:28 +00:00
UCHAR JumpBoot [ 3 ] ; // Jump instruction to boot code
CHAR OemName [ 8 ] ; // "MSWIN4.1" for MS formatted volumes
USHORT BytesPerSector ; // Bytes per sector
UCHAR SectorsPerCluster ; // Number of sectors in a cluster
USHORT ReservedSectors ; // Reserved sectors, usually 1 (the bootsector)
UCHAR NumberOfFats ; // Number of FAT tables
USHORT RootDirEntries ; // Number of root directory entries (fat12/16)
USHORT TotalSectors ; // Number of total sectors on the drive, 16-bit
UCHAR MediaDescriptor ; // Media descriptor byte
USHORT SectorsPerFat ; // Sectors per FAT table (fat12/16)
USHORT SectorsPerTrack ; // Number of sectors in a track
USHORT NumberOfHeads ; // Number of heads on the disk
ULONG HiddenSectors ; // Hidden sectors (sectors before the partition start like the partition table)
ULONG TotalSectorsBig ; // This field is the new 32-bit total count of sectors on the volume
UCHAR DriveNumber ; // Int 0x13 drive number (e.g. 0x80)
UCHAR Reserved1 ; // Reserved (used by Windows NT). Code that formats FAT volumes should always set this byte to 0.
UCHAR BootSignature ; // Extended boot signature (0x29). This is a signature byte that indicates that the following three fields in the boot sector are present.
ULONG VolumeSerialNumber ; // Volume serial number
CHAR VolumeLabel [ 11 ] ; // Volume label. This field matches the 11-byte volume label recorded in the root directory
CHAR FileSystemType [ 8 ] ; // One of the strings "FAT12 ", "FAT16 ", or "FAT "
UCHAR BootCodeAndData [ 448 ] ; // The remainder of the boot sector
USHORT BootSectorMagic ; // 0xAA55
2010-09-06 01:46:06 +00:00
} FAT_BOOTSECTOR , * PFAT_BOOTSECTOR ;
typedef struct _FAT32_BOOTSECTOR
{
2011-07-20 17:54:28 +00:00
UCHAR JumpBoot [ 3 ] ; // Jump instruction to boot code
CHAR OemName [ 8 ] ; // "MSWIN4.1" for MS formatted volumes
USHORT BytesPerSector ; // Bytes per sector
UCHAR SectorsPerCluster ; // Number of sectors in a cluster
USHORT ReservedSectors ; // Reserved sectors, usually 1 (the bootsector)
UCHAR NumberOfFats ; // Number of FAT tables
USHORT RootDirEntries ; // Number of root directory entries (fat12/16)
USHORT TotalSectors ; // Number of total sectors on the drive, 16-bit
UCHAR MediaDescriptor ; // Media descriptor byte
USHORT SectorsPerFat ; // Sectors per FAT table (fat12/16)
USHORT SectorsPerTrack ; // Number of sectors in a track
USHORT NumberOfHeads ; // Number of heads on the disk
ULONG HiddenSectors ; // Hidden sectors (sectors before the partition start like the partition table)
ULONG TotalSectorsBig ; // This field is the new 32-bit total count of sectors on the volume
ULONG SectorsPerFatBig ; // This field is the FAT32 32-bit count of sectors occupied by ONE FAT. BPB_FATSz16 must be 0
USHORT ExtendedFlags ; // Extended flags (fat32)
USHORT FileSystemVersion ; // File system version (fat32)
ULONG RootDirStartCluster ; // Starting cluster of the root directory (fat32)
USHORT FsInfo ; // Sector number of FSINFO structure in the reserved area of the FAT32 volume. Usually 1.
USHORT BackupBootSector ; // If non-zero, indicates the sector number in the reserved area of the volume of a copy of the boot record. Usually 6.
UCHAR Reserved [ 12 ] ; // Reserved for future expansion
UCHAR DriveNumber ; // Int 0x13 drive number (e.g. 0x80)
UCHAR Reserved1 ; // Reserved (used by Windows NT). Code that formats FAT volumes should always set this byte to 0.
UCHAR BootSignature ; // Extended boot signature (0x29). This is a signature byte that indicates that the following three fields in the boot sector are present.
ULONG VolumeSerialNumber ; // Volume serial number
CHAR VolumeLabel [ 11 ] ; // Volume label. This field matches the 11-byte volume label recorded in the root directory
CHAR FileSystemType [ 8 ] ; // Always set to the string "FAT32 "
UCHAR BootCodeAndData [ 420 ] ; // The remainder of the boot sector
USHORT BootSectorMagic ; // 0xAA55
2010-09-06 01:46:06 +00:00
} FAT32_BOOTSECTOR , * PFAT32_BOOTSECTOR ;
2016-02-02 01:55:05 +00:00
typedef struct _EXT2_BOOTSECTOR
{
// The EXT2 bootsector is completely user-specific.
// No FS data is stored there.
UCHAR Fill [ 1024 ] ;
} EXT2_BOOTSECTOR , * PEXT2_BOOTSECTOR ;
// TODO: Add more bootsector structures!
2010-09-06 01:46:06 +00:00
# include <poppack.h>
extern PPARTLIST PartitionList ;
2003-01-17 13:18:15 +00:00
/* FUNCTIONS ****************************************************************/
2011-07-20 17:54:28 +00:00
static
VOID
2014-05-12 14:17:37 +00:00
CreateCommonFreeLoaderSections (
PINICACHE IniCache )
2003-01-17 13:18:15 +00:00
{
2011-07-20 17:54:28 +00:00
PINICACHESECTION IniSection ;
2003-01-17 13:18:15 +00:00
2011-07-20 17:54:28 +00:00
/* Create "FREELOADER" section */
2015-12-30 18:26:42 +00:00
IniSection = IniCacheAppendSection ( IniCache , L " FREELOADER " ) ;
2003-01-17 13:18:15 +00:00
2009-06-17 12:44:05 +00:00
# if DBG
2011-07-20 17:54:28 +00:00
if ( IsUnattendedSetup )
{
/* DefaultOS=ReactOS */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " DefaultOS " ,
2011-11-19 22:50:04 +00:00
# ifndef _WINKD_
2011-07-20 17:54:28 +00:00
L " ReactOS_KdSerial " ) ;
2011-11-19 22:50:04 +00:00
# else
L " ReactOS_Debug " ) ;
# endif
2011-07-20 17:54:28 +00:00
}
else
2006-10-30 12:41:17 +00:00
# endif
2011-07-20 17:54:28 +00:00
{
/* DefaultOS=ReactOS */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " DefaultOS " ,
L " ReactOS " ) ;
}
2003-01-17 13:18:15 +00:00
2009-06-17 12:44:05 +00:00
# if DBG
2011-07-20 17:54:28 +00:00
if ( IsUnattendedSetup )
2006-10-30 12:41:17 +00:00
# endif
2011-07-20 17:54:28 +00:00
{
/* Timeout=0 for unattended or non debug*/
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " TimeOut " ,
L " 0 " ) ;
}
2009-06-17 12:44:05 +00:00
# if DBG
2011-07-20 17:54:28 +00:00
else
{
/* Timeout=0 or 10 */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " TimeOut " ,
L " 10 " ) ;
}
2006-04-25 01:31:00 +00:00
# endif
2003-01-17 13:18:15 +00:00
2011-07-20 17:54:28 +00:00
/* Create "Display" section */
IniSection = IniCacheAppendSection ( IniCache , L " Display " ) ;
/* TitleText=ReactOS Boot Manager */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " TitleText " ,
L " ReactOS Boot Manager " ) ;
/* StatusBarColor=Cyan */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " StatusBarColor " ,
L " Cyan " ) ;
/* StatusBarTextColor=Black */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " StatusBarTextColor " ,
L " Black " ) ;
/* BackdropTextColor=White */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " BackdropTextColor " ,
L " White " ) ;
/* BackdropColor=Blue */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " BackdropColor " ,
L " Blue " ) ;
/* BackdropFillStyle=Medium */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " BackdropFillStyle " ,
L " Medium " ) ;
/* TitleBoxTextColor=White */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " TitleBoxTextColor " ,
L " White " ) ;
/* TitleBoxColor=Red */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " TitleBoxColor " ,
L " Red " ) ;
/* MessageBoxTextColor=White */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " MessageBoxTextColor " ,
L " White " ) ;
/* MessageBoxColor=Blue */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " MessageBoxColor " ,
L " Blue " ) ;
/* MenuTextColor=White */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " MenuTextColor " ,
L " Gray " ) ;
/* MenuColor=Blue */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " MenuColor " ,
L " Black " ) ;
/* TextColor=Yellow */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " TextColor " ,
L " Gray " ) ;
/* SelectedTextColor=Black */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " SelectedTextColor " ,
L " Black " ) ;
/* SelectedColor=Gray */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " SelectedColor " ,
L " Gray " ) ;
2006-10-09 04:00:34 +00:00
/* SelectedColor=Gray */
2011-07-20 17:54:28 +00:00
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " ShowTime " ,
L " No " ) ;
/* SelectedColor=Gray */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " MenuBox " ,
L " No " ) ;
2006-10-09 04:00:34 +00:00
/* SelectedColor=Gray */
2011-07-20 17:54:28 +00:00
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " CenterMenu " ,
L " No " ) ;
2006-10-09 04:00:34 +00:00
/* SelectedColor=Gray */
2011-07-20 17:54:28 +00:00
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " MinimalUI " ,
L " Yes " ) ;
2006-10-09 04:00:34 +00:00
/* SelectedColor=Gray */
2011-07-20 17:54:28 +00:00
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " TimeText " ,
L " Seconds until highlighted choice will be started automatically: " ) ;
2003-01-17 13:18:15 +00:00
}
2016-02-02 01:55:05 +00:00
static
2009-10-03 19:43:29 +00:00
NTSTATUS
2016-02-02 01:55:05 +00:00
CreateNTOSEntry (
2009-10-03 19:43:29 +00:00
PINICACHE IniCache ,
PINICACHESECTION OSSection ,
PWCHAR Section ,
PWCHAR Description ,
PWCHAR BootType ,
PWCHAR ArcPath ,
PWCHAR Options )
{
PINICACHESECTION IniSection ;
/* Insert entry into "Operating Systems" section */
IniCacheInsertKey ( OSSection ,
2011-07-20 17:54:28 +00:00
NULL ,
INSERT_LAST ,
Section ,
Description ) ;
2009-10-03 19:43:29 +00:00
/* Create new section */
IniSection = IniCacheAppendSection ( IniCache , Section ) ;
/* BootType= */
IniCacheInsertKey ( IniSection ,
2011-07-20 17:54:28 +00:00
NULL ,
INSERT_LAST ,
L " BootType " ,
BootType ) ;
2009-10-03 19:43:29 +00:00
/* SystemPath= */
IniCacheInsertKey ( IniSection ,
2011-07-20 17:54:28 +00:00
NULL ,
INSERT_LAST ,
L " SystemPath " ,
ArcPath ) ;
2009-10-03 19:43:29 +00:00
2016-02-02 01:55:05 +00:00
/* Options= */
2009-10-03 19:43:29 +00:00
IniCacheInsertKey ( IniSection ,
2011-07-20 17:54:28 +00:00
NULL ,
INSERT_LAST ,
L " Options " ,
Options ) ;
2009-10-03 19:43:29 +00:00
return STATUS_SUCCESS ;
}
2015-12-30 18:26:42 +00:00
static
VOID
CreateFreeLoaderReactOSEntries (
PINICACHE IniCache ,
2011-07-20 17:54:28 +00:00
PWCHAR ArcPath )
2003-01-28 17:29:22 +00:00
{
2011-07-20 17:54:28 +00:00
PINICACHESECTION IniSection ;
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
/* Create "Operating Systems" section */
IniSection = IniCacheAppendSection ( IniCache , L " Operating Systems " ) ;
2003-01-28 17:29:22 +00:00
2009-10-03 19:43:29 +00:00
/* ReactOS */
2016-02-02 01:55:05 +00:00
CreateNTOSEntry ( IniCache , IniSection ,
L " ReactOS " , L " \" ReactOS \" " ,
L " Windows2003 " , ArcPath ,
L " " ) ;
2003-01-28 17:29:22 +00:00
2009-10-03 19:43:29 +00:00
/* ReactOS_Debug */
2016-02-02 01:55:05 +00:00
CreateNTOSEntry ( IniCache , IniSection ,
L " ReactOS_Debug " , L " \" ReactOS (Debug) \" " ,
L " Windows2003 " , ArcPath ,
L " /DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS " ) ;
2014-12-23 17:48:16 +00:00
# ifdef _WINKD_
/* ReactOS_VBoxDebug */
2016-02-02 01:55:05 +00:00
CreateNTOSEntry ( IniCache , IniSection ,
L " ReactOS_VBoxDebug " , L " \" ReactOS (VBoxDebug) \" " ,
L " Windows2003 " , ArcPath ,
L " /DEBUG /DEBUGPORT=VBOX /SOS " ) ;
2014-12-23 17:48:16 +00:00
# endif
2009-06-17 12:44:05 +00:00
# if DBG
2011-07-12 00:27:22 +00:00
# ifndef _WINKD_
2009-10-03 19:43:29 +00:00
/* ReactOS_KdSerial */
2016-02-02 01:55:05 +00:00
CreateNTOSEntry ( IniCache , IniSection ,
L " ReactOS_KdSerial " , L " \" ReactOS (RosDbg) \" " ,
L " Windows2003 " , ArcPath ,
L " /DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /KDSERIAL " ) ;
2011-07-12 00:27:22 +00:00
# endif
2009-10-03 19:43:29 +00:00
2011-11-21 05:28:08 +00:00
/* ReactOS_Screen */
2016-02-02 01:55:05 +00:00
CreateNTOSEntry ( IniCache , IniSection ,
L " ReactOS_Screen " , L " \" ReactOS (Screen) \" " ,
L " Windows2003 " , ArcPath ,
L " /DEBUG /DEBUGPORT=SCREEN /SOS " ) ;
2011-11-21 05:28:08 +00:00
2009-10-07 19:58:15 +00:00
/* ReactOS_LogFile */
2016-02-02 01:55:05 +00:00
CreateNTOSEntry ( IniCache , IniSection ,
L " ReactOS_LogFile " , L " \" ReactOS (Log file) \" " ,
L " Windows2003 " , ArcPath ,
L " /DEBUG /DEBUGPORT=FILE /SOS " ) ;
2009-10-07 19:58:15 +00:00
2009-10-03 19:43:29 +00:00
/* ReactOS_Ram */
2016-02-02 01:55:05 +00:00
CreateNTOSEntry ( IniCache , IniSection ,
L " ReactOS_Ram " , L " \" ReactOS (RAM Disk) \" " ,
L " Windows2003 " , L " ramdisk(0) \\ ReactOS " ,
L " /DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /RDPATH=reactos.img /RDIMAGEOFFSET=32256 " ) ;
2013-08-13 03:11:02 +00:00
/* ReactOS_EMS */
2016-02-02 01:55:05 +00:00
CreateNTOSEntry ( IniCache , IniSection ,
L " ReactOS_EMS " , L " \" ReactOS (Emergency Management Services) \" " ,
L " Windows2003 " , ArcPath ,
L " /DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /redirect=com2 /redirectbaudrate=115200 " ) ;
2008-06-01 19:15:15 +00:00
# endif
2015-12-30 18:26:42 +00:00
}
2008-02-27 20:13:34 +00:00
2016-02-02 01:55:05 +00:00
static
2015-12-30 18:26:42 +00:00
NTSTATUS
CreateFreeLoaderIniForReactOS (
PWCHAR IniPath ,
PWCHAR ArcPath )
{
PINICACHE IniCache ;
/* Initialize the INI file */
IniCache = IniCacheCreate ( ) ;
/* Create the common FreeLdr sections */
CreateCommonFreeLoaderSections ( IniCache ) ;
/* Add the ReactOS entries */
CreateFreeLoaderReactOSEntries ( IniCache , ArcPath ) ;
/* Save the INI file */
IniCacheSave ( IniCache , IniPath ) ;
IniCacheDestroy ( IniCache ) ;
return STATUS_SUCCESS ;
}
2016-02-02 01:55:05 +00:00
static
2015-12-30 18:26:42 +00:00
NTSTATUS
2016-02-02 01:55:05 +00:00
CreateFreeLoaderIniForReactOSAndBootSector (
2015-12-30 18:26:42 +00:00
PWCHAR IniPath ,
2016-02-02 01:55:05 +00:00
PWCHAR ArcPath ,
PWCHAR Section ,
PWCHAR Description ,
PWCHAR BootDrive ,
PWCHAR BootPartition ,
PWCHAR BootSector )
2015-12-30 18:26:42 +00:00
{
PINICACHE IniCache ;
PINICACHESECTION IniSection ;
/* Initialize the INI file */
IniCache = IniCacheCreate ( ) ;
/* Create the common FreeLdr sections */
CreateCommonFreeLoaderSections ( IniCache ) ;
/* Add the ReactOS entries */
CreateFreeLoaderReactOSEntries ( IniCache , ArcPath ) ;
/* Get "Operating Systems" section */
IniSection = IniCacheGetSection ( IniCache , L " Operating Systems " ) ;
2016-02-02 01:55:05 +00:00
/* Insert entry into "Operating Systems" section */
2015-12-30 18:26:42 +00:00
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
2016-02-02 01:55:05 +00:00
Section ,
Description ) ;
2015-12-30 18:26:42 +00:00
2016-02-02 01:55:05 +00:00
/* Create new section */
IniSection = IniCacheAppendSection ( IniCache , Section ) ;
2015-12-30 18:26:42 +00:00
/* BootType=BootSector */
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " BootType " ,
L " BootSector " ) ;
2016-02-02 01:55:05 +00:00
/* BootDrive= */
2015-12-30 18:26:42 +00:00
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " BootDrive " ,
2016-02-02 01:55:05 +00:00
BootDrive ) ;
2015-12-30 18:26:42 +00:00
2016-02-02 01:55:05 +00:00
/* BootPartition= */
2015-12-30 18:26:42 +00:00
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " BootPartition " ,
2016-02-02 01:55:05 +00:00
BootPartition ) ;
2015-12-30 18:26:42 +00:00
2016-02-02 01:55:05 +00:00
/* BootSector= */
2015-12-30 18:26:42 +00:00
IniCacheInsertKey ( IniSection ,
NULL ,
INSERT_LAST ,
L " BootSectorFile " ,
2016-02-02 01:55:05 +00:00
BootSector ) ;
2015-12-30 18:26:42 +00:00
/* Save the INI file */
2011-07-20 17:54:28 +00:00
IniCacheSave ( IniCache , IniPath ) ;
IniCacheDestroy ( IniCache ) ;
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
return STATUS_SUCCESS ;
2003-01-30 14:41:45 +00:00
}
2016-02-02 01:55:05 +00:00
static
2003-01-30 14:41:45 +00:00
NTSTATUS
2011-07-20 17:54:28 +00:00
UpdateFreeLoaderIni (
PWCHAR IniPath ,
PWCHAR ArcPath )
2003-01-30 14:41:45 +00:00
{
2016-02-02 01:55:05 +00:00
NTSTATUS Status ;
2011-07-20 17:54:28 +00:00
PINICACHE IniCache ;
PINICACHESECTION IniSection ;
PINICACHESECTION OsIniSection ;
WCHAR SectionName [ 80 ] ;
WCHAR OsName [ 80 ] ;
WCHAR SystemPath [ 200 ] ;
WCHAR SectionName2 [ 200 ] ;
PWCHAR KeyData ;
ULONG i , j ;
2015-12-30 18:26:42 +00:00
Status = IniCacheLoad ( & IniCache , IniPath , FALSE ) ;
2003-01-30 14:41:45 +00:00
if ( ! NT_SUCCESS ( Status ) )
2011-07-20 17:54:28 +00:00
return Status ;
2003-01-30 14:41:45 +00:00
2011-07-20 17:54:28 +00:00
/* Get "Operating Systems" section */
IniSection = IniCacheGetSection ( IniCache , L " Operating Systems " ) ;
if ( IniSection = = NULL )
2004-03-10 16:57:36 +00:00
{
2011-07-20 17:54:28 +00:00
IniCacheDestroy ( IniCache ) ;
return STATUS_UNSUCCESSFUL ;
2004-03-10 16:57:36 +00:00
}
2011-07-20 17:54:28 +00:00
/* Find an existing usable or an unused section name */
i = 1 ;
wcscpy ( SectionName , L " ReactOS " ) ;
wcscpy ( OsName , L " \" ReactOS \" " ) ;
while ( TRUE )
2004-03-10 16:57:36 +00:00
{
2011-07-20 17:54:28 +00:00
Status = IniCacheGetKey ( IniSection , SectionName , & KeyData ) ;
if ( ! NT_SUCCESS ( Status ) )
break ;
2004-03-10 16:57:36 +00:00
2011-07-20 17:54:28 +00:00
/* Get operation system section */
if ( KeyData [ 0 ] = = ' " ' )
2004-03-10 16:57:36 +00:00
{
2011-07-20 17:54:28 +00:00
wcscpy ( SectionName2 , & KeyData [ 1 ] ) ;
j = wcslen ( SectionName2 ) ;
if ( j > 0 )
{
SectionName2 [ j - 1 ] = 0 ;
}
2004-03-10 16:57:36 +00:00
}
else
{
2011-07-20 17:54:28 +00:00
wcscpy ( SectionName2 , KeyData ) ;
2004-03-10 16:57:36 +00:00
}
2015-12-30 20:23:18 +00:00
/* Search for an existing ReactOS entry */
2011-07-20 17:54:28 +00:00
OsIniSection = IniCacheGetSection ( IniCache , SectionName2 ) ;
if ( OsIniSection ! = NULL )
{
BOOLEAN UseExistingEntry = TRUE ;
2015-12-30 20:23:18 +00:00
/* Check for boot type "Windows2003" */
2011-07-20 17:54:28 +00:00
Status = IniCacheGetKey ( OsIniSection , L " BootType " , & KeyData ) ;
if ( NT_SUCCESS ( Status ) )
{
if ( ( KeyData = = NULL ) | |
2015-12-30 20:23:18 +00:00
( ( _wcsicmp ( KeyData , L " Windows2003 " ) ! = 0 ) & &
( _wcsicmp ( KeyData , L " \" Windows2003 \" " ) ! = 0 ) ) )
2011-07-20 17:54:28 +00:00
{
/* This is not a ReactOS entry */
UseExistingEntry = FALSE ;
}
}
else
{
UseExistingEntry = FALSE ;
}
if ( UseExistingEntry )
{
2015-12-30 20:23:18 +00:00
/* BootType is Windows2003. Now check SystemPath. */
2011-07-20 17:54:28 +00:00
Status = IniCacheGetKey ( OsIniSection , L " SystemPath " , & KeyData ) ;
if ( NT_SUCCESS ( Status ) )
{
2015-12-30 20:23:18 +00:00
swprintf ( SystemPath , L " \" %s \" " , ArcPath ) ;
2011-07-20 17:54:28 +00:00
if ( ( KeyData = = NULL ) | |
2015-12-30 20:23:18 +00:00
( ( _wcsicmp ( KeyData , ArcPath ) ! = 0 ) & &
( _wcsicmp ( KeyData , SystemPath ) ! = 0 ) ) )
2011-07-20 17:54:28 +00:00
{
2015-12-30 20:23:18 +00:00
/* This entry is a ReactOS entry, but the SystemRoot
does not match the one we are looking for . */
2011-07-20 17:54:28 +00:00
UseExistingEntry = FALSE ;
}
}
else
{
UseExistingEntry = FALSE ;
}
}
if ( UseExistingEntry )
{
IniCacheDestroy ( IniCache ) ;
return STATUS_SUCCESS ;
}
}
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
swprintf ( SectionName , L " ReactOS_%lu " , i ) ;
swprintf ( OsName , L " \" ReactOS %lu \" " , i ) ;
i + + ;
}
2003-01-28 17:29:22 +00:00
2015-12-30 20:23:18 +00:00
/* Create a new "ReactOS" entry */
2016-02-02 01:55:05 +00:00
CreateNTOSEntry ( IniCache , IniSection ,
SectionName , OsName ,
L " Windows2003 " , ArcPath ,
L " " ) ;
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
IniCacheSave ( IniCache , IniPath ) ;
IniCacheDestroy ( IniCache ) ;
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
return STATUS_SUCCESS ;
2003-01-28 17:29:22 +00:00
}
2016-02-02 01:55:05 +00:00
BOOLEAN
IsThereAValidBootSector ( PWSTR RootPath )
{
/*
2017-05-09 15:31:53 +00:00
* We first demand that the bootsector has a valid signature at its end .
* We then check the first 3 bytes ( as a ULONG ) of the bootsector for a
* potential " valid " instruction ( the BIOS starts execution of the bootsector
* at its beginning ) . Currently this criterium is that this ULONG must be
* non - zero . If both these tests pass , then the bootsector is valid ; otherwise
* it is invalid and certainly needs to be overwritten .
2016-02-02 01:55:05 +00:00
*/
2017-05-09 15:31:53 +00:00
BOOLEAN IsValid = FALSE ;
2016-02-02 01:55:05 +00:00
NTSTATUS Status ;
UNICODE_STRING Name ;
OBJECT_ATTRIBUTES ObjectAttributes ;
IO_STATUS_BLOCK IoStatusBlock ;
HANDLE FileHandle ;
LARGE_INTEGER FileOffset ;
PUCHAR BootSector ;
ULONG Instruction ;
/* Allocate buffer for bootsector */
BootSector = RtlAllocateHeap ( ProcessHeap , 0 , SECTORSIZE ) ;
if ( BootSector = = NULL )
return FALSE ; // STATUS_INSUFFICIENT_RESOURCES;
/* Read current boot sector into buffer */
RtlInitUnicodeString ( & Name , RootPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
GENERIC_READ | SYNCHRONIZE ,
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
2017-05-09 15:31:53 +00:00
goto Quit ;
RtlZeroMemory ( BootSector , SECTORSIZE ) ;
2016-02-02 01:55:05 +00:00
FileOffset . QuadPart = 0ULL ;
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
BootSector ,
SECTORSIZE ,
& FileOffset ,
NULL ) ;
NtClose ( FileHandle ) ;
2017-05-09 15:31:53 +00:00
if ( ! NT_SUCCESS ( Status ) )
goto Quit ;
2016-02-02 01:55:05 +00:00
2017-05-09 15:31:53 +00:00
/* Check the instruction; we use a ULONG to read three bytes */
Instruction = ( * ( PULONG ) BootSector ) & 0x00FFFFFF ;
IsValid = ( Instruction ! = 0x00000000 ) ;
2016-02-02 01:55:05 +00:00
2017-05-09 15:31:53 +00:00
/* Check the bootsector signature */
IsValid & = ( * ( PUSHORT ) ( BootSector + 0x1fe ) = = 0xaa55 ) ;
Quit :
2016-02-02 01:55:05 +00:00
/* Free the boot sector */
RtlFreeHeap ( ProcessHeap , 0 , BootSector ) ;
2017-05-09 15:31:53 +00:00
return IsValid ; // Status;
2016-02-02 01:55:05 +00:00
}
2003-01-28 17:29:22 +00:00
2003-04-05 15:36:34 +00:00
NTSTATUS
[USETUP]
- bootsup.c/.h, usetup.c: Save the old MBR sector in the system partition (this makes easier to restore the old one).
- fslist.c/.h, usetup.h: Fix header inclusion order.
- partlist.c/.h, usetup.c: On BIOS-PC architectures, the system partition can be formatted in any FS as long as it is the active partition (on the contrary, on architectures where such system partition is required, it is formatted in FAT). We currently do not have write support for all FSes out there (apart for FAT until now), so do a "clever" "trick" to work around this problem: on initialized disks, find the active partition and check its FS. If we support write access to this FS then we're OK, otherwise we change the (active) system partition for the one on which we are going to install ReactOS (which is, by construction, formatted with a FS on which we support write access).
The MBR (resp. the VBR) of the disk (resp. of the system partition) are always saved into files, making easy for people to boot on them (using FreeLdr) or restoring them.
CORE-10898
svn path=/trunk/; revision=70837
2016-03-01 15:00:56 +00:00
SaveBootSector (
2011-07-20 17:54:28 +00:00
PWSTR RootPath ,
2016-02-02 01:55:05 +00:00
PWSTR DstPath ,
ULONG Length )
2003-04-05 15:36:34 +00:00
{
2016-02-02 01:55:05 +00:00
NTSTATUS Status ;
UNICODE_STRING Name ;
2010-09-06 01:46:06 +00:00
OBJECT_ATTRIBUTES ObjectAttributes ;
IO_STATUS_BLOCK IoStatusBlock ;
HANDLE FileHandle ;
2016-02-02 01:55:05 +00:00
LARGE_INTEGER FileOffset ;
2011-07-20 17:54:28 +00:00
PUCHAR BootSector ;
2003-04-05 15:36:34 +00:00
2011-07-20 17:54:28 +00:00
/* Allocate buffer for bootsector */
2016-02-02 01:55:05 +00:00
BootSector = RtlAllocateHeap ( ProcessHeap , 0 , Length ) ;
2011-07-20 17:54:28 +00:00
if ( BootSector = = NULL )
return STATUS_INSUFFICIENT_RESOURCES ;
2003-04-05 15:36:34 +00:00
2010-09-06 01:46:06 +00:00
/* Read current boot sector into buffer */
2011-07-20 17:54:28 +00:00
RtlInitUnicodeString ( & Name , RootPath ) ;
2003-04-05 15:36:34 +00:00
2010-09-06 01:46:06 +00:00
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_READ | SYNCHRONIZE ,
2010-09-06 01:46:06 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , BootSector ) ;
return Status ;
}
2003-04-05 15:36:34 +00:00
2016-02-02 01:55:05 +00:00
FileOffset . QuadPart = 0ULL ;
2010-09-06 01:46:06 +00:00
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
2011-07-20 17:54:28 +00:00
BootSector ,
2016-02-02 01:55:05 +00:00
Length ,
& FileOffset ,
2010-09-06 01:46:06 +00:00
NULL ) ;
NtClose ( FileHandle ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , BootSector ) ;
return Status ;
}
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
/* Write bootsector to DstPath */
RtlInitUnicodeString ( & Name , DstPath ) ;
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
0 ,
NULL ,
NULL ) ;
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
Status = NtCreateFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_WRITE | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
NULL ,
FILE_ATTRIBUTE_NORMAL ,
0 ,
FILE_SUPERSEDE ,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY ,
NULL ,
0 ) ;
2003-01-28 17:29:22 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
2011-07-20 17:54:28 +00:00
RtlFreeHeap ( ProcessHeap , 0 , BootSector ) ;
return Status ;
}
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
Status = NtWriteFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
BootSector ,
2016-02-02 01:55:05 +00:00
Length ,
2011-07-20 17:54:28 +00:00
NULL ,
NULL ) ;
2003-01-28 17:29:22 +00:00
NtClose ( FileHandle ) ;
2016-02-02 01:55:05 +00:00
/* Free the boot sector */
2011-07-20 17:54:28 +00:00
RtlFreeHeap ( ProcessHeap , 0 , BootSector ) ;
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
return Status ;
2003-01-28 17:29:22 +00:00
}
2016-02-02 01:55:05 +00:00
static
2003-01-28 17:29:22 +00:00
NTSTATUS
2011-07-20 17:54:28 +00:00
InstallFat16BootCodeToFile (
PWSTR SrcPath ,
PWSTR DstPath ,
PWSTR RootPath )
2003-01-28 17:29:22 +00:00
{
2016-02-02 01:55:05 +00:00
NTSTATUS Status ;
UNICODE_STRING Name ;
2011-07-20 17:54:28 +00:00
OBJECT_ATTRIBUTES ObjectAttributes ;
IO_STATUS_BLOCK IoStatusBlock ;
HANDLE FileHandle ;
2016-02-02 01:55:05 +00:00
LARGE_INTEGER FileOffset ;
2011-07-20 17:54:28 +00:00
PFAT_BOOTSECTOR OrigBootSector ;
PFAT_BOOTSECTOR NewBootSector ;
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
/* Allocate buffer for original bootsector */
OrigBootSector = RtlAllocateHeap ( ProcessHeap , 0 , SECTORSIZE ) ;
if ( OrigBootSector = = NULL )
2016-02-02 01:55:05 +00:00
return STATUS_INSUFFICIENT_RESOURCES ;
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
/* Read current boot sector into buffer */
RtlInitUnicodeString ( & Name , RootPath ) ;
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
2003-01-28 17:29:22 +00:00
2011-07-20 17:54:28 +00:00
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return Status ;
}
2003-01-28 17:29:22 +00:00
2016-02-02 01:55:05 +00:00
FileOffset . QuadPart = 0ULL ;
2011-07-20 17:54:28 +00:00
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
OrigBootSector ,
SECTORSIZE ,
2016-02-02 01:55:05 +00:00
& FileOffset ,
2011-07-20 17:54:28 +00:00
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
2004-06-23 14:09:55 +00:00
{
2011-07-20 17:54:28 +00:00
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return Status ;
2004-06-23 14:09:55 +00:00
}
2011-07-20 17:54:28 +00:00
/* Allocate buffer for new bootsector */
NewBootSector = RtlAllocateHeap ( ProcessHeap , 0 , SECTORSIZE ) ;
if ( NewBootSector = = NULL )
2004-06-23 14:09:55 +00:00
{
2011-07-20 17:54:28 +00:00
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return STATUS_INSUFFICIENT_RESOURCES ;
2004-06-23 14:09:55 +00:00
}
2011-07-20 17:54:28 +00:00
/* Read new bootsector from SrcPath */
RtlInitUnicodeString ( & Name , SrcPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
2016-02-02 01:55:05 +00:00
FileOffset . QuadPart = 0ULL ;
2011-07-20 17:54:28 +00:00
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
SECTORSIZE ,
2016-02-02 01:55:05 +00:00
& FileOffset ,
2011-07-20 17:54:28 +00:00
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
/* Adjust bootsector (copy a part of the FAT BPB) */
memcpy ( & NewBootSector - > OemName ,
& OrigBootSector - > OemName ,
2011-07-20 19:56:58 +00:00
FIELD_OFFSET ( FAT_BOOTSECTOR , BootCodeAndData ) -
FIELD_OFFSET ( FAT_BOOTSECTOR , OemName ) ) ;
2011-07-20 17:54:28 +00:00
/* Free the original boot sector */
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
/* Write new bootsector to DstPath */
RtlInitUnicodeString ( & Name , DstPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
0 ,
NULL ,
NULL ) ;
Status = NtCreateFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_WRITE | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
NULL ,
FILE_ATTRIBUTE_NORMAL ,
0 ,
FILE_OVERWRITE_IF ,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY ,
NULL ,
0 ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
Status = NtWriteFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
SECTORSIZE ,
NULL ,
NULL ) ;
NtClose ( FileHandle ) ;
/* Free the new boot sector */
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
2016-02-02 01:55:05 +00:00
static
2011-07-20 17:54:28 +00:00
NTSTATUS
InstallFat32BootCodeToFile (
PWSTR SrcPath ,
PWSTR DstPath ,
PWSTR RootPath )
{
2016-02-02 01:55:05 +00:00
NTSTATUS Status ;
UNICODE_STRING Name ;
2011-07-20 17:54:28 +00:00
OBJECT_ATTRIBUTES ObjectAttributes ;
IO_STATUS_BLOCK IoStatusBlock ;
HANDLE FileHandle ;
2016-02-02 01:55:05 +00:00
LARGE_INTEGER FileOffset ;
2011-07-20 17:54:28 +00:00
PFAT32_BOOTSECTOR OrigBootSector ;
PFAT32_BOOTSECTOR NewBootSector ;
/* Allocate buffer for original bootsector */
OrigBootSector = RtlAllocateHeap ( ProcessHeap , 0 , SECTORSIZE ) ;
if ( OrigBootSector = = NULL )
return STATUS_INSUFFICIENT_RESOURCES ;
/* Read current boot sector into buffer */
RtlInitUnicodeString ( & Name , RootPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return Status ;
}
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
OrigBootSector ,
SECTORSIZE ,
NULL ,
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return Status ;
}
/* Allocate buffer for new bootsector (2 sectors) */
NewBootSector = RtlAllocateHeap ( ProcessHeap , 0 , 2 * SECTORSIZE ) ;
if ( NewBootSector = = NULL )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return STATUS_INSUFFICIENT_RESOURCES ;
}
/* Read new bootsector from SrcPath */
RtlInitUnicodeString ( & Name , SrcPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
2 * SECTORSIZE ,
NULL ,
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
/* Adjust bootsector (copy a part of the FAT32 BPB) */
memcpy ( & NewBootSector - > OemName ,
& OrigBootSector - > OemName ,
FIELD_OFFSET ( FAT32_BOOTSECTOR , BootCodeAndData ) -
FIELD_OFFSET ( FAT32_BOOTSECTOR , OemName ) ) ;
/* Disable the backup boot sector */
NewBootSector - > BackupBootSector = 0 ;
/* Free the original boot sector */
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
/* Write the first sector of the new bootcode to DstPath */
RtlInitUnicodeString ( & Name , DstPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
0 ,
NULL ,
NULL ) ;
Status = NtCreateFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_WRITE | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
NULL ,
FILE_ATTRIBUTE_NORMAL ,
0 ,
FILE_SUPERSEDE ,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY ,
NULL ,
0 ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
Status = NtWriteFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
SECTORSIZE ,
NULL ,
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
/* Write the second sector of the new bootcode to boot disk sector 14 */
RtlInitUnicodeString ( & Name , RootPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
0 ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_WRITE | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
FileOffset . QuadPart = ( ULONGLONG ) ( 14 * SECTORSIZE ) ;
Status = NtWriteFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
2011-10-31 07:32:00 +00:00
( ( PUCHAR ) NewBootSector + SECTORSIZE ) ,
2011-07-20 17:54:28 +00:00
SECTORSIZE ,
& FileOffset ,
NULL ) ;
if ( ! NT_SUCCESS ( Status ) )
{
}
NtClose ( FileHandle ) ;
/* Free the new boot sector */
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
NTSTATUS
InstallMbrBootCodeToDisk (
PWSTR SrcPath ,
PWSTR RootPath )
{
2016-02-02 01:55:05 +00:00
NTSTATUS Status ;
UNICODE_STRING Name ;
2011-07-20 17:54:28 +00:00
OBJECT_ATTRIBUTES ObjectAttributes ;
IO_STATUS_BLOCK IoStatusBlock ;
HANDLE FileHandle ;
2016-02-02 01:55:05 +00:00
LARGE_INTEGER FileOffset ;
2011-07-20 17:54:28 +00:00
PPARTITION_SECTOR OrigBootSector ;
PPARTITION_SECTOR NewBootSector ;
/* Allocate buffer for original bootsector */
OrigBootSector = ( PPARTITION_SECTOR ) RtlAllocateHeap ( ProcessHeap ,
0 ,
sizeof ( PARTITION_SECTOR ) ) ;
if ( OrigBootSector = = NULL )
return STATUS_INSUFFICIENT_RESOURCES ;
/* Read current boot sector into buffer */
RtlInitUnicodeString ( & Name ,
RootPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return Status ;
}
2016-02-02 01:55:05 +00:00
FileOffset . QuadPart = 0ULL ;
2011-07-20 17:54:28 +00:00
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
OrigBootSector ,
[USETUP]
- bootsup.c/.h, usetup.c: Save the old MBR sector in the system partition (this makes easier to restore the old one).
- fslist.c/.h, usetup.h: Fix header inclusion order.
- partlist.c/.h, usetup.c: On BIOS-PC architectures, the system partition can be formatted in any FS as long as it is the active partition (on the contrary, on architectures where such system partition is required, it is formatted in FAT). We currently do not have write support for all FSes out there (apart for FAT until now), so do a "clever" "trick" to work around this problem: on initialized disks, find the active partition and check its FS. If we support write access to this FS then we're OK, otherwise we change the (active) system partition for the one on which we are going to install ReactOS (which is, by construction, formatted with a FS on which we support write access).
The MBR (resp. the VBR) of the disk (resp. of the system partition) are always saved into files, making easy for people to boot on them (using FreeLdr) or restoring them.
CORE-10898
svn path=/trunk/; revision=70837
2016-03-01 15:00:56 +00:00
sizeof ( PARTITION_SECTOR ) ,
2016-02-02 01:55:05 +00:00
& FileOffset ,
2011-07-20 17:54:28 +00:00
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return Status ;
}
/* Allocate buffer for new bootsector */
NewBootSector = ( PPARTITION_SECTOR ) RtlAllocateHeap ( ProcessHeap ,
0 ,
sizeof ( PARTITION_SECTOR ) ) ;
if ( NewBootSector = = NULL )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return STATUS_INSUFFICIENT_RESOURCES ;
}
/* Read new bootsector from SrcPath */
RtlInitUnicodeString ( & Name , SrcPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
sizeof ( PARTITION_SECTOR ) ,
NULL ,
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
/* Copy partition table from old MBR to new */
2016-02-28 15:25:22 +00:00
RtlCopyMemory ( & NewBootSector - > Signature ,
& OrigBootSector - > Signature ,
sizeof ( PARTITION_SECTOR ) - offsetof ( PARTITION_SECTOR , Signature ) /* Length of partition table */ ) ;
2011-07-20 17:54:28 +00:00
/* Free the original boot sector */
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
/* Write new bootsector to RootPath */
RtlInitUnicodeString ( & Name , RootPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
0 ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_WRITE | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtOpenFile() failed (Status %lx) \n " , Status ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
2016-02-02 01:55:05 +00:00
FileOffset . QuadPart = 0ULL ;
2011-07-20 17:54:28 +00:00
Status = NtWriteFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
[USETUP]
- bootsup.c/.h, usetup.c: Save the old MBR sector in the system partition (this makes easier to restore the old one).
- fslist.c/.h, usetup.h: Fix header inclusion order.
- partlist.c/.h, usetup.c: On BIOS-PC architectures, the system partition can be formatted in any FS as long as it is the active partition (on the contrary, on architectures where such system partition is required, it is formatted in FAT). We currently do not have write support for all FSes out there (apart for FAT until now), so do a "clever" "trick" to work around this problem: on initialized disks, find the active partition and check its FS. If we support write access to this FS then we're OK, otherwise we change the (active) system partition for the one on which we are going to install ReactOS (which is, by construction, formatted with a FS on which we support write access).
The MBR (resp. the VBR) of the disk (resp. of the system partition) are always saved into files, making easy for people to boot on them (using FreeLdr) or restoring them.
CORE-10898
svn path=/trunk/; revision=70837
2016-03-01 15:00:56 +00:00
sizeof ( PARTITION_SECTOR ) ,
2016-02-02 01:55:05 +00:00
& FileOffset ,
2011-07-20 17:54:28 +00:00
NULL ) ;
NtClose ( FileHandle ) ;
/* Free the new boot sector */
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
2016-02-02 01:55:05 +00:00
static
2011-10-29 15:10:11 +00:00
NTSTATUS
2014-05-12 14:17:37 +00:00
InstallFat12BootCodeToFloppy (
PWSTR SrcPath ,
PWSTR RootPath )
2011-10-29 15:10:11 +00:00
{
2016-02-02 01:55:05 +00:00
NTSTATUS Status ;
UNICODE_STRING Name ;
2011-10-29 15:10:11 +00:00
OBJECT_ATTRIBUTES ObjectAttributes ;
IO_STATUS_BLOCK IoStatusBlock ;
HANDLE FileHandle ;
2016-02-02 01:55:05 +00:00
LARGE_INTEGER FileOffset ;
2011-10-29 15:10:11 +00:00
PFAT_BOOTSECTOR OrigBootSector ;
PFAT_BOOTSECTOR NewBootSector ;
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
/* Allocate buffer for original bootsector */
OrigBootSector = RtlAllocateHeap ( ProcessHeap , 0 , SECTORSIZE ) ;
if ( OrigBootSector = = NULL )
return STATUS_INSUFFICIENT_RESOURCES ;
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
/* Read current boot sector into buffer */
RtlInitUnicodeString ( & Name , RootPath ) ;
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-10-29 15:10:11 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return Status ;
}
2014-05-12 14:17:37 +00:00
2016-02-02 01:55:05 +00:00
FileOffset . QuadPart = 0ULL ;
2011-10-29 15:10:11 +00:00
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
OrigBootSector ,
SECTORSIZE ,
2016-02-02 01:55:05 +00:00
& FileOffset ,
2011-10-29 15:10:11 +00:00
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return Status ;
}
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
/* Allocate buffer for new bootsector */
NewBootSector = RtlAllocateHeap ( ProcessHeap ,
0 ,
SECTORSIZE ) ;
if ( NewBootSector = = NULL )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return STATUS_INSUFFICIENT_RESOURCES ;
}
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
/* Read new bootsector from SrcPath */
RtlInitUnicodeString ( & Name , SrcPath ) ;
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-10-29 15:10:11 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
SECTORSIZE ,
NULL ,
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
/* Adjust bootsector (copy a part of the FAT16 BPB) */
memcpy ( & NewBootSector - > OemName ,
& OrigBootSector - > OemName ,
FIELD_OFFSET ( FAT_BOOTSECTOR , BootCodeAndData ) -
FIELD_OFFSET ( FAT_BOOTSECTOR , OemName ) ) ;
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
/* Free the original boot sector */
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
/* Write new bootsector to RootPath */
RtlInitUnicodeString ( & Name , RootPath ) ;
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
0 ,
NULL ,
NULL ) ;
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_WRITE | SYNCHRONIZE ,
2011-10-29 15:10:11 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtOpenFile() failed (Status %lx) \n " , Status ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
2014-05-12 14:17:37 +00:00
2016-02-02 01:55:05 +00:00
FileOffset . QuadPart = 0ULL ;
2011-10-29 15:10:11 +00:00
Status = NtWriteFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
SECTORSIZE ,
2016-02-02 01:55:05 +00:00
& FileOffset ,
2011-10-29 15:10:11 +00:00
NULL ) ;
NtClose ( FileHandle ) ;
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
/* Free the new boot sector */
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
return Status ;
}
2016-02-02 01:55:05 +00:00
static
2011-07-20 17:54:28 +00:00
NTSTATUS
InstallFat16BootCodeToDisk (
PWSTR SrcPath ,
PWSTR RootPath )
{
2016-02-02 01:55:05 +00:00
NTSTATUS Status ;
UNICODE_STRING Name ;
2011-07-20 17:54:28 +00:00
OBJECT_ATTRIBUTES ObjectAttributes ;
IO_STATUS_BLOCK IoStatusBlock ;
HANDLE FileHandle ;
2016-02-02 01:55:05 +00:00
LARGE_INTEGER FileOffset ;
2011-07-20 17:54:28 +00:00
PFAT_BOOTSECTOR OrigBootSector ;
PFAT_BOOTSECTOR NewBootSector ;
/* Allocate buffer for original bootsector */
OrigBootSector = RtlAllocateHeap ( ProcessHeap , 0 , SECTORSIZE ) ;
if ( OrigBootSector = = NULL )
return STATUS_INSUFFICIENT_RESOURCES ;
/* Read current boot sector into buffer */
RtlInitUnicodeString ( & Name , RootPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return Status ;
}
2016-02-02 01:55:05 +00:00
FileOffset . QuadPart = 0ULL ;
2011-07-20 17:54:28 +00:00
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
OrigBootSector ,
SECTORSIZE ,
2016-02-02 01:55:05 +00:00
& FileOffset ,
2011-07-20 17:54:28 +00:00
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return Status ;
}
/* Allocate buffer for new bootsector */
2016-02-02 01:55:05 +00:00
NewBootSector = RtlAllocateHeap ( ProcessHeap , 0 , SECTORSIZE ) ;
2011-07-20 17:54:28 +00:00
if ( NewBootSector = = NULL )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return STATUS_INSUFFICIENT_RESOURCES ;
}
/* Read new bootsector from SrcPath */
RtlInitUnicodeString ( & Name , SrcPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
SECTORSIZE ,
NULL ,
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
/* Adjust bootsector (copy a part of the FAT16 BPB) */
memcpy ( & NewBootSector - > OemName ,
& OrigBootSector - > OemName ,
2011-07-20 19:56:58 +00:00
FIELD_OFFSET ( FAT_BOOTSECTOR , BootCodeAndData ) -
FIELD_OFFSET ( FAT_BOOTSECTOR , OemName ) ) ;
2011-07-20 17:54:28 +00:00
/* Free the original boot sector */
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
/* Write new bootsector to RootPath */
RtlInitUnicodeString ( & Name , RootPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
0 ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_WRITE | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtOpenFile() failed (Status %lx) \n " , Status ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
2016-02-02 01:55:05 +00:00
FileOffset . QuadPart = 0ULL ;
2011-07-20 17:54:28 +00:00
Status = NtWriteFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
SECTORSIZE ,
2016-02-02 01:55:05 +00:00
& FileOffset ,
2011-07-20 17:54:28 +00:00
NULL ) ;
NtClose ( FileHandle ) ;
/* Free the new boot sector */
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
2016-02-02 01:55:05 +00:00
static
2011-07-20 17:54:28 +00:00
NTSTATUS
InstallFat32BootCodeToDisk (
PWSTR SrcPath ,
PWSTR RootPath )
{
2016-02-02 01:55:05 +00:00
NTSTATUS Status ;
UNICODE_STRING Name ;
2011-07-20 17:54:28 +00:00
OBJECT_ATTRIBUTES ObjectAttributes ;
IO_STATUS_BLOCK IoStatusBlock ;
HANDLE FileHandle ;
2016-02-02 01:55:05 +00:00
LARGE_INTEGER FileOffset ;
2011-07-20 17:54:28 +00:00
PFAT32_BOOTSECTOR OrigBootSector ;
PFAT32_BOOTSECTOR NewBootSector ;
USHORT BackupBootSector ;
/* Allocate buffer for original bootsector */
OrigBootSector = RtlAllocateHeap ( ProcessHeap , 0 , SECTORSIZE ) ;
if ( OrigBootSector = = NULL )
return STATUS_INSUFFICIENT_RESOURCES ;
/* Read current boot sector into buffer */
RtlInitUnicodeString ( & Name , RootPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return Status ;
}
2016-02-02 01:55:05 +00:00
FileOffset . QuadPart = 0ULL ;
2011-07-20 17:54:28 +00:00
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
OrigBootSector ,
SECTORSIZE ,
2016-02-02 01:55:05 +00:00
& FileOffset ,
2011-07-20 17:54:28 +00:00
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return Status ;
}
/* Allocate buffer for new bootsector (2 sectors) */
NewBootSector = RtlAllocateHeap ( ProcessHeap , 0 , 2 * SECTORSIZE ) ;
if ( NewBootSector = = NULL )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
return STATUS_INSUFFICIENT_RESOURCES ;
}
/* Read new bootsector from SrcPath */
RtlInitUnicodeString ( & Name , SrcPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
2 * SECTORSIZE ,
NULL ,
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
{
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
/* Adjust bootsector (copy a part of the FAT32 BPB) */
memcpy ( & NewBootSector - > OemName ,
& OrigBootSector - > OemName ,
FIELD_OFFSET ( FAT32_BOOTSECTOR , BootCodeAndData ) -
FIELD_OFFSET ( FAT32_BOOTSECTOR , OemName ) ) ;
/* Get the location of the backup boot sector */
BackupBootSector = OrigBootSector - > BackupBootSector ;
/* Free the original boot sector */
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
/* Write the first sector of the new bootcode to DstPath */
RtlInitUnicodeString ( & Name , RootPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
0 ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2013-07-19 14:03:46 +00:00
GENERIC_WRITE | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtOpenFile() failed (Status %lx) \n " , Status ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
/* Write sector 0 */
FileOffset . QuadPart = 0ULL ;
Status = NtWriteFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
SECTORSIZE ,
& FileOffset ,
NULL ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtWriteFile() failed (Status %lx) \n " , Status ) ;
NtClose ( FileHandle ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
/* Write backup boot sector */
if ( ( BackupBootSector ! = 0x0000 ) & & ( BackupBootSector ! = 0xFFFF ) )
{
FileOffset . QuadPart = ( ULONGLONG ) ( ( ULONG ) BackupBootSector * SECTORSIZE ) ;
Status = NtWriteFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
SECTORSIZE ,
& FileOffset ,
NULL ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtWriteFile() failed (Status %lx) \n " , Status ) ;
NtClose ( FileHandle ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
}
/* Write sector 14 */
FileOffset . QuadPart = 14 * SECTORSIZE ;
Status = NtWriteFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
( ( PUCHAR ) NewBootSector + SECTORSIZE ) ,
SECTORSIZE ,
& FileOffset ,
NULL ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtWriteFile() failed (Status %lx) \n " , Status ) ;
}
NtClose ( FileHandle ) ;
/* Free the new boot sector */
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
static
NTSTATUS
2016-02-02 01:55:05 +00:00
InstallExt2BootCodeToDisk (
PWSTR SrcPath ,
PWSTR RootPath )
2011-07-20 17:54:28 +00:00
{
2016-02-02 01:55:05 +00:00
NTSTATUS Status ;
2011-07-20 17:54:28 +00:00
UNICODE_STRING Name ;
OBJECT_ATTRIBUTES ObjectAttributes ;
IO_STATUS_BLOCK IoStatusBlock ;
HANDLE FileHandle ;
2016-02-02 01:55:05 +00:00
LARGE_INTEGER FileOffset ;
// PEXT2_BOOTSECTOR OrigBootSector;
PEXT2_BOOTSECTOR NewBootSector ;
// USHORT BackupBootSector;
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
#if 0
/* Allocate buffer for original bootsector */
OrigBootSector = RtlAllocateHeap ( ProcessHeap , 0 , SECTORSIZE ) ;
if ( OrigBootSector = = NULL )
return STATUS_INSUFFICIENT_RESOURCES ;
/* Read current boot sector into buffer */
RtlInitUnicodeString ( & Name , RootPath ) ;
2011-07-20 17:54:28 +00:00
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2016-02-02 01:55:05 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
2016-02-02 01:55:05 +00:00
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
2011-07-20 17:54:28 +00:00
return Status ;
}
2016-02-02 01:55:05 +00:00
FileOffset . QuadPart = 0ULL ;
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
OrigBootSector ,
SECTORSIZE ,
& FileOffset ,
NULL ) ;
NtClose ( FileHandle ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
2016-02-02 01:55:05 +00:00
RtlFreeHeap ( ProcessHeap , 0 , OrigBootSector ) ;
2011-07-20 17:54:28 +00:00
return Status ;
}
2016-02-02 01:55:05 +00:00
# endif
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
/* Allocate buffer for new bootsector */
NewBootSector = RtlAllocateHeap ( ProcessHeap , 0 , sizeof ( EXT2_BOOTSECTOR ) ) ;
if ( NewBootSector = = NULL )
2011-07-20 17:54:28 +00:00
{
2016-02-02 01:55:05 +00:00
// RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
return STATUS_INSUFFICIENT_RESOURCES ;
2011-07-20 17:54:28 +00:00
}
2016-02-02 01:55:05 +00:00
/* Read new bootsector from SrcPath */
RtlInitUnicodeString ( & Name , SrcPath ) ;
2011-07-20 17:54:28 +00:00
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
2016-02-02 01:55:05 +00:00
GENERIC_READ | SYNCHRONIZE ,
2011-07-20 17:54:28 +00:00
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
2016-02-02 01:55:05 +00:00
// RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
2011-07-20 17:54:28 +00:00
return Status ;
}
2016-02-02 01:55:05 +00:00
Status = NtReadFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
sizeof ( EXT2_BOOTSECTOR ) ,
NULL ,
NULL ) ;
NtClose ( FileHandle ) ;
if ( ! NT_SUCCESS ( Status ) )
{
// RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
#if 0
/* Adjust bootsector (copy a part of the FAT32 BPB) */
memcpy ( & NewBootSector - > OemName ,
& OrigBootSector - > OemName ,
FIELD_OFFSET ( FAT32_BOOTSECTOR , BootCodeAndData ) -
FIELD_OFFSET ( FAT32_BOOTSECTOR , OemName ) ) ;
NewBootSector - > HiddenSectors = PartitionList - > CurrentDisk - > SectorsPerTrack ;
/* Get the location of the backup boot sector */
BackupBootSector = OrigBootSector - > BackupBootSector ;
/* Free the original boot sector */
// RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
# endif
/* Write new bootsector to RootPath */
RtlInitUnicodeString ( & Name , RootPath ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
0 ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
GENERIC_WRITE | SYNCHRONIZE ,
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtOpenFile() failed (Status %lx) \n " , Status ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
/* Write sector 0 */
FileOffset . QuadPart = 0ULL ;
Status = NtWriteFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
sizeof ( EXT2_BOOTSECTOR ) ,
& FileOffset ,
NULL ) ;
#if 0
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtWriteFile() failed (Status %lx) \n " , Status ) ;
NtClose ( FileHandle ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
/* Write backup boot sector */
if ( ( BackupBootSector ! = 0x0000 ) & & ( BackupBootSector ! = 0xFFFF ) )
{
FileOffset . QuadPart = ( ULONGLONG ) ( ( ULONG ) BackupBootSector * SECTORSIZE ) ;
Status = NtWriteFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector ,
SECTORSIZE ,
& FileOffset ,
NULL ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtWriteFile() failed (Status %lx) \n " , Status ) ;
NtClose ( FileHandle ) ;
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
}
/* Write sector 14 */
FileOffset . QuadPart = 14 * SECTORSIZE ;
Status = NtWriteFile ( FileHandle ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
( ( PUCHAR ) NewBootSector + SECTORSIZE ) ,
SECTORSIZE ,
& FileOffset ,
NULL ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtWriteFile() failed (Status %lx) \n " , Status ) ;
}
# endif
NtClose ( FileHandle ) ;
/* Free the new boot sector */
RtlFreeHeap ( ProcessHeap , 0 , NewBootSector ) ;
return Status ;
}
static
NTSTATUS
UnprotectBootIni (
PWSTR FileName ,
PULONG Attributes )
{
NTSTATUS Status ;
UNICODE_STRING Name ;
OBJECT_ATTRIBUTES ObjectAttributes ;
IO_STATUS_BLOCK IoStatusBlock ;
FILE_BASIC_INFORMATION FileInfo ;
HANDLE FileHandle ;
RtlInitUnicodeString ( & Name , FileName ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE ,
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( Status = = STATUS_NO_SUCH_FILE )
{
DPRINT1 ( " NtOpenFile() failed (Status %lx) \n " , Status ) ;
* Attributes = 0 ;
return STATUS_SUCCESS ;
}
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtOpenFile() failed (Status %lx) \n " , Status ) ;
return Status ;
}
Status = NtQueryInformationFile ( FileHandle ,
& IoStatusBlock ,
2011-07-20 17:54:28 +00:00
& FileInfo ,
sizeof ( FILE_BASIC_INFORMATION ) ,
FileBasicInformation ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtQueryInformationFile() failed (Status %lx) \n " , Status ) ;
NtClose ( FileHandle ) ;
return Status ;
}
2016-02-02 01:55:05 +00:00
* Attributes = FileInfo . FileAttributes ;
/* Delete attributes SYSTEM, HIDDEN and READONLY */
FileInfo . FileAttributes = FileInfo . FileAttributes &
~ ( FILE_ATTRIBUTE_SYSTEM |
FILE_ATTRIBUTE_HIDDEN |
FILE_ATTRIBUTE_READONLY ) ;
2011-07-20 17:54:28 +00:00
Status = NtSetInformationFile ( FileHandle ,
& IoStatusBlock ,
& FileInfo ,
sizeof ( FILE_BASIC_INFORMATION ) ,
FileBasicInformation ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtSetInformationFile() failed (Status %lx) \n " , Status ) ;
}
NtClose ( FileHandle ) ;
return Status ;
}
2016-02-02 01:55:05 +00:00
static
NTSTATUS
ProtectBootIni (
PWSTR FileName ,
ULONG Attributes )
{
NTSTATUS Status ;
UNICODE_STRING Name ;
OBJECT_ATTRIBUTES ObjectAttributes ;
IO_STATUS_BLOCK IoStatusBlock ;
FILE_BASIC_INFORMATION FileInfo ;
HANDLE FileHandle ;
RtlInitUnicodeString ( & Name , FileName ) ;
InitializeObjectAttributes ( & ObjectAttributes ,
& Name ,
OBJ_CASE_INSENSITIVE ,
NULL ,
NULL ) ;
Status = NtOpenFile ( & FileHandle ,
GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE ,
& ObjectAttributes ,
& IoStatusBlock ,
0 ,
FILE_SYNCHRONOUS_IO_NONALERT ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtOpenFile() failed (Status %lx) \n " , Status ) ;
return Status ;
}
Status = NtQueryInformationFile ( FileHandle ,
& IoStatusBlock ,
& FileInfo ,
sizeof ( FILE_BASIC_INFORMATION ) ,
FileBasicInformation ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtQueryInformationFile() failed (Status %lx) \n " , Status ) ;
NtClose ( FileHandle ) ;
return Status ;
}
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
FileInfo . FileAttributes = FileInfo . FileAttributes | Attributes ;
Status = NtSetInformationFile ( FileHandle ,
& IoStatusBlock ,
& FileInfo ,
sizeof ( FILE_BASIC_INFORMATION ) ,
FileBasicInformation ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtSetInformationFile() failed (Status %lx) \n " , Status ) ;
}
NtClose ( FileHandle ) ;
return Status ;
}
static
2011-07-20 17:54:28 +00:00
NTSTATUS
UpdateBootIni (
PWSTR BootIniPath ,
PWSTR EntryName ,
PWSTR EntryValue )
{
2016-02-02 01:55:05 +00:00
NTSTATUS Status ;
2011-07-20 17:54:28 +00:00
PINICACHE Cache = NULL ;
PINICACHESECTION Section = NULL ;
ULONG FileAttribute ;
PWCHAR OldValue = NULL ;
2015-12-30 18:26:42 +00:00
Status = IniCacheLoad ( & Cache , BootIniPath , FALSE ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
return Status ;
}
Section = IniCacheGetSection ( Cache ,
L " operating systems " ) ;
if ( Section = = NULL )
{
IniCacheDestroy ( Cache ) ;
return STATUS_UNSUCCESSFUL ;
}
/* Check - maybe record already exists */
Status = IniCacheGetKey ( Section , EntryName , & OldValue ) ;
/* If either key was not found, or contains something else - add new one */
if ( ! NT_SUCCESS ( Status ) | | wcscmp ( OldValue , EntryValue ) )
{
IniCacheInsertKey ( Section ,
NULL ,
INSERT_LAST ,
EntryName ,
EntryValue ) ;
}
Status = UnprotectBootIni ( BootIniPath ,
& FileAttribute ) ;
if ( ! NT_SUCCESS ( Status ) )
{
IniCacheDestroy ( Cache ) ;
return Status ;
}
Status = IniCacheSave ( Cache , BootIniPath ) ;
if ( ! NT_SUCCESS ( Status ) )
{
IniCacheDestroy ( Cache ) ;
return Status ;
}
FileAttribute | = ( FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY ) ;
Status = ProtectBootIni ( BootIniPath , FileAttribute ) ;
IniCacheDestroy ( Cache ) ;
return Status ;
}
2016-02-02 01:55:05 +00:00
static
2004-06-23 14:09:55 +00:00
NTSTATUS
2011-07-20 17:54:28 +00:00
InstallFatBootcodeToPartition (
PUNICODE_STRING SystemRootPath ,
PUNICODE_STRING SourceRootPath ,
PUNICODE_STRING DestinationArcPath ,
UCHAR PartitionType )
2004-06-23 14:09:55 +00:00
{
2016-02-02 01:55:05 +00:00
NTSTATUS Status ;
BOOLEAN DoesFreeLdrExist ;
2011-07-20 17:54:28 +00:00
WCHAR SrcPath [ MAX_PATH ] ;
WCHAR DstPath [ MAX_PATH ] ;
/* FAT or FAT32 partition */
DPRINT ( " System path: '%wZ' \n " , SystemRootPath ) ;
2016-02-28 15:25:22 +00:00
/* Copy FreeLoader to the system partition */
2016-02-02 01:55:05 +00:00
wcscpy ( SrcPath , SourceRootPath - > Buffer ) ;
wcscat ( SrcPath , L " \\ loader \\ freeldr.sys " ) ;
wcscpy ( DstPath , SystemRootPath - > Buffer ) ;
wcscat ( DstPath , L " \\ freeldr.sys " ) ;
DPRINT ( " Copy: %S ==> %S \n " , SrcPath , DstPath ) ;
Status = SetupCopyFile ( SrcPath , DstPath ) ;
if ( ! NT_SUCCESS ( Status ) )
2011-07-20 17:54:28 +00:00
{
2016-02-02 01:55:05 +00:00
DPRINT1 ( " SetupCopyFile() failed (Status %lx) \n " , Status ) ;
return Status ;
}
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
/* Prepare for possibly copying 'freeldr.ini' */
wcscpy ( DstPath , SystemRootPath - > Buffer ) ;
wcscat ( DstPath , L " \\ freeldr.ini " ) ;
2011-07-20 17:54:28 +00:00
2017-05-13 16:13:49 +00:00
DoesFreeLdrExist = DoesFileExist ( NULL , SystemRootPath - > Buffer , L " freeldr.ini " ) ;
2016-02-02 01:55:05 +00:00
if ( DoesFreeLdrExist )
{
/* Update existing 'freeldr.ini' */
DPRINT1 ( " Update existing 'freeldr.ini' \n " ) ;
Status = UpdateFreeLoaderIni ( DstPath , DestinationArcPath - > Buffer ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
2016-02-02 01:55:05 +00:00
DPRINT1 ( " UpdateFreeLoaderIni() failed (Status %lx) \n " , Status ) ;
2011-07-20 17:54:28 +00:00
return Status ;
}
2016-02-02 01:55:05 +00:00
}
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
/* Check for NT and other bootloaders */
// FIXME: Check for Vista+ bootloader!
2017-05-13 16:13:49 +00:00
if ( DoesFileExist ( NULL , SystemRootPath - > Buffer , L " ntldr " ) = = TRUE | |
DoesFileExist ( NULL , SystemRootPath - > Buffer , L " boot.ini " ) = = TRUE )
2016-02-02 01:55:05 +00:00
{
/* Search root directory for 'ntldr' and 'boot.ini' */
DPRINT1 ( " Found Microsoft Windows NT/2000/XP boot loader \n " ) ;
/* Create or update 'freeldr.ini' */
if ( DoesFreeLdrExist = = FALSE )
2011-07-20 17:54:28 +00:00
{
/* Create new 'freeldr.ini' */
DPRINT1 ( " Create new 'freeldr.ini' \n " ) ;
2016-02-02 01:55:05 +00:00
// wcscpy(DstPath, SystemRootPath->Buffer);
// wcscat(DstPath, L"\\freeldr.ini");
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
Status = CreateFreeLoaderIniForReactOS ( DstPath , DestinationArcPath - > Buffer ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
2015-04-18 09:21:51 +00:00
DPRINT1 ( " CreateFreeLoaderIniForReactOS() failed (Status %lx) \n " , Status ) ;
2011-07-20 17:54:28 +00:00
return Status ;
}
2016-02-02 01:55:05 +00:00
/* Install new bootcode into a file */
wcscpy ( DstPath , SystemRootPath - > Buffer ) ;
wcscat ( DstPath , L " \\ bootsect.ros " ) ;
2011-07-20 17:54:28 +00:00
if ( PartitionType = = PARTITION_FAT32 | |
2015-12-30 20:23:18 +00:00
PartitionType = = PARTITION_FAT32_XINT13 )
2011-07-20 17:54:28 +00:00
{
/* Install FAT32 bootcode */
wcscpy ( SrcPath , SourceRootPath - > Buffer ) ;
wcscat ( SrcPath , L " \\ loader \\ fat32.bin " ) ;
DPRINT1 ( " Install FAT32 bootcode: %S ==> %S \n " , SrcPath , DstPath ) ;
2016-02-02 01:55:05 +00:00
Status = InstallFat32BootCodeToFile ( SrcPath , DstPath ,
2011-07-20 17:54:28 +00:00
SystemRootPath - > Buffer ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " InstallFat32BootCodeToFile() failed (Status %lx) \n " , Status ) ;
return Status ;
}
}
else
{
/* Install FAT16 bootcode */
wcscpy ( SrcPath , SourceRootPath - > Buffer ) ;
wcscat ( SrcPath , L " \\ loader \\ fat.bin " ) ;
DPRINT1 ( " Install FAT bootcode: %S ==> %S \n " , SrcPath , DstPath ) ;
2016-02-02 01:55:05 +00:00
Status = InstallFat16BootCodeToFile ( SrcPath , DstPath ,
2011-07-20 17:54:28 +00:00
SystemRootPath - > Buffer ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " InstallFat16BootCodeToFile() failed (Status %lx) \n " , Status ) ;
return Status ;
}
}
}
/* Update 'boot.ini' */
wcscpy ( DstPath , SystemRootPath - > Buffer ) ;
wcscat ( DstPath , L " \\ boot.ini " ) ;
DPRINT1 ( " Update 'boot.ini': %S \n " , DstPath ) ;
Status = UpdateBootIni ( DstPath ,
L " C: \\ bootsect.ros " ,
L " \" ReactOS \" " ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " UpdateBootIni() failed (Status %lx) \n " , Status ) ;
return Status ;
}
}
2016-02-02 01:55:05 +00:00
else
2011-07-20 17:54:28 +00:00
{
2016-02-02 01:55:05 +00:00
/* Non-NT bootloaders: install our own bootloader */
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
PWCHAR Section ;
PWCHAR Description ;
PWCHAR BootDrive ;
PWCHAR BootPartition ;
PWCHAR BootSector ;
PWCHAR BootSectorFileName ;
2011-07-20 17:54:28 +00:00
2017-05-13 16:13:49 +00:00
if ( DoesFileExist ( NULL , SystemRootPath - > Buffer , L " io.sys " ) = = TRUE | |
DoesFileExist ( NULL , SystemRootPath - > Buffer , L " msdos.sys " ) = = TRUE )
2011-07-20 17:54:28 +00:00
{
2016-02-02 01:55:05 +00:00
/* Search for root directory for 'io.sys' and 'msdos.sys' */
DPRINT1 ( " Found Microsoft DOS or Windows 9x boot loader \n " ) ;
Section = L " DOS " ;
Description = L " \" DOS/Windows \" " ;
BootDrive = L " hd0 " ;
BootPartition = L " 1 " ;
BootSector = L " BOOTSECT.DOS " ;
BootSectorFileName = L " \\ bootsect.dos " ;
}
else
2017-05-13 16:13:49 +00:00
if ( DoesFileExist ( NULL , SystemRootPath - > Buffer , L " kernel.sys " ) = = TRUE )
2016-02-02 01:55:05 +00:00
{
/* Search for root directory for 'kernel.sys' */
DPRINT1 ( " Found FreeDOS boot loader \n " ) ;
Section = L " DOS " ;
Description = L " \" FreeDOS \" " ;
BootDrive = L " hd0 " ;
BootPartition = L " 1 " ;
BootSector = L " BOOTSECT.DOS " ;
BootSectorFileName = L " \\ bootsect.dos " ;
}
else
{
/* No or unknown boot loader */
DPRINT1 ( " No or unknown boot loader found \n " ) ;
Section = L " Unknown " ;
Description = L " \" Unknown Operating System \" " ;
BootDrive = L " hd0 " ;
BootPartition = L " 1 " ;
BootSector = L " BOOTSECT.OLD " ;
BootSectorFileName = L " \\ bootsect.old " ;
2011-07-20 17:54:28 +00:00
}
/* Create or update 'freeldr.ini' */
2016-02-02 01:55:05 +00:00
if ( DoesFreeLdrExist = = FALSE )
2011-07-20 17:54:28 +00:00
{
/* Create new 'freeldr.ini' */
DPRINT1 ( " Create new 'freeldr.ini' \n " ) ;
2016-02-02 01:55:05 +00:00
// wcscpy(DstPath, SystemRootPath->Buffer);
// wcscat(DstPath, L"\\freeldr.ini");
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
if ( IsThereAValidBootSector ( SystemRootPath - > Buffer ) )
2011-07-20 17:54:28 +00:00
{
2016-02-02 01:55:05 +00:00
Status = CreateFreeLoaderIniForReactOSAndBootSector (
DstPath , DestinationArcPath - > Buffer ,
Section , Description ,
BootDrive , BootPartition , BootSector ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " CreateFreeLoaderIniForReactOSAndBootSector() failed (Status %lx) \n " , Status ) ;
return Status ;
}
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
/* Save current bootsector */
wcscpy ( DstPath , SystemRootPath - > Buffer ) ;
wcscat ( DstPath , BootSectorFileName ) ;
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
DPRINT1 ( " Save bootsector: %S ==> %S \n " , SystemRootPath - > Buffer , DstPath ) ;
[USETUP]
- bootsup.c/.h, usetup.c: Save the old MBR sector in the system partition (this makes easier to restore the old one).
- fslist.c/.h, usetup.h: Fix header inclusion order.
- partlist.c/.h, usetup.c: On BIOS-PC architectures, the system partition can be formatted in any FS as long as it is the active partition (on the contrary, on architectures where such system partition is required, it is formatted in FAT). We currently do not have write support for all FSes out there (apart for FAT until now), so do a "clever" "trick" to work around this problem: on initialized disks, find the active partition and check its FS. If we support write access to this FS then we're OK, otherwise we change the (active) system partition for the one on which we are going to install ReactOS (which is, by construction, formatted with a FS on which we support write access).
The MBR (resp. the VBR) of the disk (resp. of the system partition) are always saved into files, making easy for people to boot on them (using FreeLdr) or restoring them.
CORE-10898
svn path=/trunk/; revision=70837
2016-03-01 15:00:56 +00:00
Status = SaveBootSector ( SystemRootPath - > Buffer , DstPath , SECTORSIZE ) ;
2016-02-02 01:55:05 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
[USETUP]
- bootsup.c/.h, usetup.c: Save the old MBR sector in the system partition (this makes easier to restore the old one).
- fslist.c/.h, usetup.h: Fix header inclusion order.
- partlist.c/.h, usetup.c: On BIOS-PC architectures, the system partition can be formatted in any FS as long as it is the active partition (on the contrary, on architectures where such system partition is required, it is formatted in FAT). We currently do not have write support for all FSes out there (apart for FAT until now), so do a "clever" "trick" to work around this problem: on initialized disks, find the active partition and check its FS. If we support write access to this FS then we're OK, otherwise we change the (active) system partition for the one on which we are going to install ReactOS (which is, by construction, formatted with a FS on which we support write access).
The MBR (resp. the VBR) of the disk (resp. of the system partition) are always saved into files, making easy for people to boot on them (using FreeLdr) or restoring them.
CORE-10898
svn path=/trunk/; revision=70837
2016-03-01 15:00:56 +00:00
DPRINT1 ( " SaveBootSector() failed (Status %lx) \n " , Status ) ;
2016-02-02 01:55:05 +00:00
return Status ;
}
}
else
2011-07-20 17:54:28 +00:00
{
2016-02-02 01:55:05 +00:00
Status = CreateFreeLoaderIniForReactOS ( DstPath , DestinationArcPath - > Buffer ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " CreateFreeLoaderIniForReactOS() failed (Status %lx) \n " , Status ) ;
return Status ;
}
2011-07-20 17:54:28 +00:00
}
2016-02-02 01:55:05 +00:00
/* Install new bootsector on the disk */
2011-07-20 17:54:28 +00:00
if ( PartitionType = = PARTITION_FAT32 | |
2015-12-30 20:23:18 +00:00
PartitionType = = PARTITION_FAT32_XINT13 )
2011-07-20 17:54:28 +00:00
{
2016-02-02 01:55:05 +00:00
/* Install FAT32 bootcode */
2011-07-20 17:54:28 +00:00
wcscpy ( SrcPath , SourceRootPath - > Buffer ) ;
wcscat ( SrcPath , L " \\ loader \\ fat32.bin " ) ;
DPRINT1 ( " Install FAT32 bootcode: %S ==> %S \n " , SrcPath , SystemRootPath - > Buffer ) ;
2016-02-02 01:55:05 +00:00
Status = InstallFat32BootCodeToDisk ( SrcPath , SystemRootPath - > Buffer ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " InstallFat32BootCodeToDisk() failed (Status %lx) \n " , Status ) ;
return Status ;
}
}
else
{
2016-02-02 01:55:05 +00:00
/* Install FAT16 bootcode */
2011-07-20 17:54:28 +00:00
wcscpy ( SrcPath , SourceRootPath - > Buffer ) ;
wcscat ( SrcPath , L " \\ loader \\ fat.bin " ) ;
2016-02-02 01:55:05 +00:00
DPRINT1 ( " Install FAT16 bootcode: %S ==> %S \n " , SrcPath , SystemRootPath - > Buffer ) ;
Status = InstallFat16BootCodeToDisk ( SrcPath , SystemRootPath - > Buffer ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " InstallFat16BootCodeToDisk() failed (Status %lx) \n " , Status ) ;
return Status ;
}
}
}
}
2016-02-02 01:55:05 +00:00
return STATUS_SUCCESS ;
}
static
NTSTATUS
InstallExt2BootcodeToPartition (
PUNICODE_STRING SystemRootPath ,
PUNICODE_STRING SourceRootPath ,
PUNICODE_STRING DestinationArcPath ,
UCHAR PartitionType )
{
NTSTATUS Status ;
BOOLEAN DoesFreeLdrExist ;
WCHAR SrcPath [ MAX_PATH ] ;
WCHAR DstPath [ MAX_PATH ] ;
/* EXT2 partition */
DPRINT ( " System path: '%wZ' \n " , SystemRootPath ) ;
2016-02-28 15:25:22 +00:00
/* Copy FreeLoader to the system partition */
2016-02-02 01:55:05 +00:00
wcscpy ( SrcPath , SourceRootPath - > Buffer ) ;
wcscat ( SrcPath , L " \\ loader \\ freeldr.sys " ) ;
wcscpy ( DstPath , SystemRootPath - > Buffer ) ;
wcscat ( DstPath , L " \\ freeldr.sys " ) ;
DPRINT ( " Copy: %S ==> %S \n " , SrcPath , DstPath ) ;
Status = SetupCopyFile ( SrcPath , DstPath ) ;
if ( ! NT_SUCCESS ( Status ) )
2011-07-20 17:54:28 +00:00
{
2016-02-02 01:55:05 +00:00
DPRINT1 ( " SetupCopyFile() failed (Status %lx) \n " , Status ) ;
return Status ;
}
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
/* Prepare for possibly copying 'freeldr.ini' */
wcscpy ( DstPath , SystemRootPath - > Buffer ) ;
wcscat ( DstPath , L " \\ freeldr.ini " ) ;
2011-07-20 17:54:28 +00:00
2017-05-13 16:13:49 +00:00
DoesFreeLdrExist = DoesFileExist ( NULL , SystemRootPath - > Buffer , L " freeldr.ini " ) ;
2016-02-02 01:55:05 +00:00
if ( DoesFreeLdrExist )
{
/* Update existing 'freeldr.ini' */
DPRINT1 ( " Update existing 'freeldr.ini' \n " ) ;
Status = UpdateFreeLoaderIni ( DstPath , DestinationArcPath - > Buffer ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
2016-02-02 01:55:05 +00:00
DPRINT1 ( " UpdateFreeLoaderIni() failed (Status %lx) \n " , Status ) ;
2011-07-20 17:54:28 +00:00
return Status ;
}
2016-02-02 01:55:05 +00:00
}
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
/* Check for *nix bootloaders */
/* Create or update 'freeldr.ini' */
if ( DoesFreeLdrExist = = FALSE )
{
/* Create new 'freeldr.ini' */
DPRINT1 ( " Create new 'freeldr.ini' \n " ) ;
wcscpy ( DstPath , SystemRootPath - > Buffer ) ;
wcscat ( DstPath , L " \\ freeldr.ini " ) ;
/* Certainly SysLinux, GRUB, LILO... or an unknown boot loader */
DPRINT1 ( " *nix or unknown boot loader found \n " ) ;
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
if ( IsThereAValidBootSector ( SystemRootPath - > Buffer ) )
{
Status = CreateFreeLoaderIniForReactOSAndBootSector (
DstPath , DestinationArcPath - > Buffer ,
L " Linux " , L " \" Linux \" " ,
L " hd0 " , L " 1 " , L " BOOTSECT.OLD " ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
2016-02-02 01:55:05 +00:00
DPRINT1 ( " CreateFreeLoaderIniForReactOSAndBootSector() failed (Status %lx) \n " , Status ) ;
2011-07-20 17:54:28 +00:00
return Status ;
}
2016-02-02 01:55:05 +00:00
/* Save current bootsector */
2011-07-20 17:54:28 +00:00
wcscpy ( DstPath , SystemRootPath - > Buffer ) ;
wcscat ( DstPath , L " \\ bootsect.old " ) ;
2016-02-02 01:55:05 +00:00
DPRINT1 ( " Save bootsector: %S ==> %S \n " , SystemRootPath - > Buffer , DstPath ) ;
[USETUP]
- bootsup.c/.h, usetup.c: Save the old MBR sector in the system partition (this makes easier to restore the old one).
- fslist.c/.h, usetup.h: Fix header inclusion order.
- partlist.c/.h, usetup.c: On BIOS-PC architectures, the system partition can be formatted in any FS as long as it is the active partition (on the contrary, on architectures where such system partition is required, it is formatted in FAT). We currently do not have write support for all FSes out there (apart for FAT until now), so do a "clever" "trick" to work around this problem: on initialized disks, find the active partition and check its FS. If we support write access to this FS then we're OK, otherwise we change the (active) system partition for the one on which we are going to install ReactOS (which is, by construction, formatted with a FS on which we support write access).
The MBR (resp. the VBR) of the disk (resp. of the system partition) are always saved into files, making easy for people to boot on them (using FreeLdr) or restoring them.
CORE-10898
svn path=/trunk/; revision=70837
2016-03-01 15:00:56 +00:00
Status = SaveBootSector ( SystemRootPath - > Buffer , DstPath , sizeof ( EXT2_BOOTSECTOR ) ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
[USETUP]
- bootsup.c/.h, usetup.c: Save the old MBR sector in the system partition (this makes easier to restore the old one).
- fslist.c/.h, usetup.h: Fix header inclusion order.
- partlist.c/.h, usetup.c: On BIOS-PC architectures, the system partition can be formatted in any FS as long as it is the active partition (on the contrary, on architectures where such system partition is required, it is formatted in FAT). We currently do not have write support for all FSes out there (apart for FAT until now), so do a "clever" "trick" to work around this problem: on initialized disks, find the active partition and check its FS. If we support write access to this FS then we're OK, otherwise we change the (active) system partition for the one on which we are going to install ReactOS (which is, by construction, formatted with a FS on which we support write access).
The MBR (resp. the VBR) of the disk (resp. of the system partition) are always saved into files, making easy for people to boot on them (using FreeLdr) or restoring them.
CORE-10898
svn path=/trunk/; revision=70837
2016-03-01 15:00:56 +00:00
DPRINT1 ( " SaveBootSector() failed (Status %lx) \n " , Status ) ;
2011-07-20 17:54:28 +00:00
return Status ;
}
2016-02-02 01:55:05 +00:00
}
else
{
Status = CreateFreeLoaderIniForReactOS ( DstPath , DestinationArcPath - > Buffer ) ;
if ( ! NT_SUCCESS ( Status ) )
2011-07-20 17:54:28 +00:00
{
2016-02-02 01:55:05 +00:00
DPRINT1 ( " CreateFreeLoaderIniForReactOS() failed (Status %lx) \n " , Status ) ;
return Status ;
2011-07-20 17:54:28 +00:00
}
}
2016-02-02 01:55:05 +00:00
/* Install new bootsector on the disk */
// if (PartitionType == PARTITION_EXT2)
2011-07-20 17:54:28 +00:00
{
2016-02-02 01:55:05 +00:00
/* Install EXT2 bootcode */
wcscpy ( SrcPath , SourceRootPath - > Buffer ) ;
wcscat ( SrcPath , L " \\ loader \\ ext2.bin " ) ;
2011-07-20 17:54:28 +00:00
2016-02-02 01:55:05 +00:00
DPRINT1 ( " Install EXT2 bootcode: %S ==> %S \n " , SrcPath , SystemRootPath - > Buffer ) ;
Status = InstallExt2BootCodeToDisk ( SrcPath , SystemRootPath - > Buffer ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
{
2016-02-02 01:55:05 +00:00
DPRINT1 ( " InstallExt2BootCodeToDisk() failed (Status %lx) \n " , Status ) ;
2011-07-20 17:54:28 +00:00
return Status ;
}
}
}
return STATUS_SUCCESS ;
2004-06-23 14:09:55 +00:00
}
2014-05-12 14:17:37 +00:00
2010-09-05 17:09:18 +00:00
NTSTATUS
2011-07-20 17:54:28 +00:00
InstallVBRToPartition (
PUNICODE_STRING SystemRootPath ,
PUNICODE_STRING SourceRootPath ,
PUNICODE_STRING DestinationArcPath ,
UCHAR PartitionType )
2010-09-05 17:09:18 +00:00
{
2016-02-02 01:55:05 +00:00
switch ( PartitionType )
{
case PARTITION_FAT_12 :
case PARTITION_FAT_16 :
case PARTITION_HUGE :
case PARTITION_XINT13 :
case PARTITION_FAT32 :
case PARTITION_FAT32_XINT13 :
{
return InstallFatBootcodeToPartition ( SystemRootPath ,
SourceRootPath ,
DestinationArcPath ,
PartitionType ) ;
}
case PARTITION_EXT2 :
{
return InstallExt2BootcodeToPartition ( SystemRootPath ,
SourceRootPath ,
DestinationArcPath ,
PartitionType ) ;
}
case PARTITION_IFS :
break ;
default :
2016-02-27 20:49:17 +00:00
DPRINT1 ( " PartitionType 0x%02X unknown! \n " , PartitionType ) ;
2016-02-02 01:55:05 +00:00
break ;
2010-09-05 17:09:18 +00:00
}
2011-06-29 20:27:07 +00:00
2010-09-05 17:09:18 +00:00
return STATUS_UNSUCCESSFUL ;
}
2004-06-23 14:09:55 +00:00
NTSTATUS
2011-07-20 17:54:28 +00:00
InstallFatBootcodeToFloppy (
PUNICODE_STRING SourceRootPath ,
PUNICODE_STRING DestinationArcPath )
2004-06-23 14:09:55 +00:00
{
2016-02-02 01:55:05 +00:00
NTSTATUS Status ;
2011-10-29 15:10:11 +00:00
UNICODE_STRING FloppyDevice = RTL_CONSTANT_STRING ( L " \\ Device \\ Floppy0 " ) ;
2011-07-20 17:54:28 +00:00
WCHAR SrcPath [ MAX_PATH ] ;
WCHAR DstPath [ MAX_PATH ] ;
2014-05-12 14:17:37 +00:00
2011-10-29 15:10:11 +00:00
/* Format the floppy first */
Status = VfatFormat ( & FloppyDevice ,
FMIFS_FLOPPY ,
NULL ,
TRUE ,
0 ,
NULL ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " VfatFormat() failed (Status %lx) \n " , Status ) ;
return Status ;
}
2004-06-23 14:09:55 +00:00
2011-07-20 17:54:28 +00:00
/* Copy FreeLoader to the boot partition */
wcscpy ( SrcPath , SourceRootPath - > Buffer ) ;
wcscat ( SrcPath , L " \\ loader \\ freeldr.sys " ) ;
2004-06-23 14:09:55 +00:00
2011-07-20 17:54:28 +00:00
wcscpy ( DstPath , L " \\ Device \\ Floppy0 \\ freeldr.sys " ) ;
2004-06-23 14:09:55 +00:00
2011-07-20 17:54:28 +00:00
DPRINT ( " Copy: %S ==> %S \n " , SrcPath , DstPath ) ;
Status = SetupCopyFile ( SrcPath , DstPath ) ;
if ( ! NT_SUCCESS ( Status ) )
2004-06-23 14:09:55 +00:00
{
2011-07-20 17:54:28 +00:00
DPRINT1 ( " SetupCopyFile() failed (Status %lx) \n " , Status ) ;
return Status ;
2004-06-23 14:09:55 +00:00
}
2011-07-20 17:54:28 +00:00
/* Create new 'freeldr.ini' */
wcscpy ( DstPath , L " \\ Device \\ Floppy0 \\ freeldr.ini " ) ;
2004-06-23 14:09:55 +00:00
2011-07-20 17:54:28 +00:00
DPRINT ( " Create new 'freeldr.ini' \n " ) ;
2015-04-18 09:21:51 +00:00
Status = CreateFreeLoaderIniForReactOS ( DstPath , DestinationArcPath - > Buffer ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
2004-06-23 14:09:55 +00:00
{
2015-04-18 09:21:51 +00:00
DPRINT1 ( " CreateFreeLoaderIniForReactOS() failed (Status %lx) \n " , Status ) ;
2011-07-20 17:54:28 +00:00
return Status ;
2004-06-23 14:09:55 +00:00
}
2011-07-20 17:54:28 +00:00
/* Install FAT12/16 boosector */
wcscpy ( SrcPath , SourceRootPath - > Buffer ) ;
wcscat ( SrcPath , L " \\ loader \\ fat.bin " ) ;
2004-06-23 14:09:55 +00:00
2011-07-20 17:54:28 +00:00
wcscpy ( DstPath , L " \\ Device \\ Floppy0 " ) ;
2004-06-23 14:09:55 +00:00
2011-07-20 17:54:28 +00:00
DPRINT ( " Install FAT bootcode: %S ==> %S \n " , SrcPath , DstPath ) ;
2011-10-29 15:10:11 +00:00
Status = InstallFat12BootCodeToFloppy ( SrcPath , DstPath ) ;
2011-07-20 17:54:28 +00:00
if ( ! NT_SUCCESS ( Status ) )
2004-06-23 14:09:55 +00:00
{
2011-07-20 17:54:28 +00:00
DPRINT1 ( " InstallFat16BootCodeToDisk() failed (Status %lx) \n " , Status ) ;
return Status ;
2004-06-23 14:09:55 +00:00
}
2011-07-20 17:54:28 +00:00
return STATUS_SUCCESS ;
2004-06-23 14:09:55 +00:00
}
2003-01-30 17:37:13 +00:00
/* EOF */