[USETUP][SETUPLIB] Move the bootsup.c code into the setuplib, and perform the necessary adjustments.

Move the bootsup.c code into the setuplib, as the code is generic
enough to be used by both USETUP and the 1st-stage GUI installer.

svn path=/branches/setup_improvements/; revision=75674
This commit is contained in:
Hermès Bélusca-Maïto 2017-08-26 11:42:32 +00:00
parent 5467cc9493
commit 95a34ef6fc
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
7 changed files with 147 additions and 111 deletions

View file

@ -2,6 +2,7 @@
list(APPEND SOURCE
arcname.c
bldrsup.c
bootsup.c
filesup.c
fsutil.c
genlist.c

View file

@ -1,17 +1,31 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup
* FILE: base/setup/usetup/bootsup.c
* PROJECT: ReactOS Setup Library
* FILE: base/setup/lib/bootsup.c
* PURPOSE: Bootloader support functions
* PROGRAMMERS: ...
* Hermes Belusca-Maito (hermes.belusca@sfr.fr)
*/
#include "usetup.h"
/* INCLUDES *****************************************************************/
#include "precomp.h"
#include "bldrsup.h"
#include "filesup.h"
#include "fsutil.h"
#include "partlist.h"
#include "setuplib.h" // HAXX for IsUnattendedSetup!!
#include "bootsup.h"
#define NDEBUG
#include <debug.h>
/* TYPEDEFS *****************************************************************/
/*
* BIG FIXME!!
* ===========
@ -515,6 +529,7 @@ UpdateBootIni(
}
static
BOOLEAN
IsThereAValidBootSector(
IN PCWSTR RootPath)
@ -591,6 +606,7 @@ Quit:
return IsValid; // Status;
}
static
NTSTATUS
SaveBootSector(
IN PCWSTR RootPath,
@ -693,8 +709,10 @@ SaveBootSector(
return Status;
}
static
NTSTATUS
InstallMbrBootCodeToDisk(
InstallMbrBootCodeToDiskHelper(
IN PCWSTR SrcPath,
IN PCWSTR RootPath)
{
@ -853,6 +871,48 @@ InstallMbrBootCodeToDisk(
return Status;
}
NTSTATUS
InstallMbrBootCodeToDisk(
IN PUNICODE_STRING SystemRootPath,
IN PUNICODE_STRING SourceRootPath,
IN PCWSTR DestinationDevicePathBuffer)
{
NTSTATUS Status;
WCHAR SourceMbrPathBuffer[MAX_PATH];
WCHAR DstPath[MAX_PATH];
#if 0
WCHAR DestinationDevicePathBuffer[MAX_PATH];
StringCchPrintfW(DestinationDevicePathBuffer, ARRAYSIZE(DestinationDevicePathBuffer),
L"\\Device\\Harddisk%d\\Partition0",
DiskNumber);
#endif
CombinePaths(SourceMbrPathBuffer, ARRAYSIZE(SourceMbrPathBuffer), 2,
SourceRootPath->Buffer, L"\\loader\\dosmbr.bin");
if (IsThereAValidBootSector(DestinationDevicePathBuffer))
{
/* Save current MBR */
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2,
SystemRootPath->Buffer, L"mbr.old");
DPRINT1("Save MBR: %S ==> %S\n", DestinationDevicePathBuffer, DstPath);
Status = SaveBootSector(DestinationDevicePathBuffer, DstPath, sizeof(PARTITION_SECTOR));
if (!NT_SUCCESS(Status))
{
DPRINT1("SaveBootSector() failed (Status %lx)\n", Status);
// Don't care if we succeeded or not saving the old MBR, just go ahead.
}
}
DPRINT1("Install MBR bootcode: %S ==> %S\n",
SourceMbrPathBuffer, DestinationDevicePathBuffer);
return InstallMbrBootCodeToDiskHelper(SourceMbrPathBuffer,
DestinationDevicePathBuffer);
}
static
NTSTATUS
@ -1767,13 +1827,14 @@ InstallBtrfsBootCodeToDisk(
return Status;
}
static
NTSTATUS
InstallFatBootcodeToPartition(
PUNICODE_STRING SystemRootPath,
PUNICODE_STRING SourceRootPath,
PUNICODE_STRING DestinationArcPath,
UCHAR PartitionType)
IN PUNICODE_STRING SystemRootPath,
IN PUNICODE_STRING SourceRootPath,
IN PUNICODE_STRING DestinationArcPath,
IN UCHAR PartitionType)
{
NTSTATUS Status;
BOOLEAN DoesFreeLdrExist;
@ -2083,10 +2144,10 @@ InstallFatBootcodeToPartition(
static
NTSTATUS
InstallBtrfsBootcodeToPartition(
PUNICODE_STRING SystemRootPath,
PUNICODE_STRING SourceRootPath,
PUNICODE_STRING DestinationArcPath,
UCHAR PartitionType)
IN PUNICODE_STRING SystemRootPath,
IN PUNICODE_STRING SourceRootPath,
IN PUNICODE_STRING DestinationArcPath,
IN UCHAR PartitionType)
{
NTSTATUS Status;
BOOLEAN DoesFreeLdrExist;
@ -2190,10 +2251,10 @@ InstallBtrfsBootcodeToPartition(
NTSTATUS
InstallVBRToPartition(
PUNICODE_STRING SystemRootPath,
PUNICODE_STRING SourceRootPath,
PUNICODE_STRING DestinationArcPath,
UCHAR PartitionType)
IN PUNICODE_STRING SystemRootPath,
IN PUNICODE_STRING SourceRootPath,
IN PUNICODE_STRING DestinationArcPath,
IN UCHAR PartitionType)
{
switch (PartitionType)
{
@ -2233,8 +2294,8 @@ InstallVBRToPartition(
NTSTATUS
InstallFatBootcodeToFloppy(
PUNICODE_STRING SourceRootPath,
PUNICODE_STRING DestinationArcPath)
IN PUNICODE_STRING SourceRootPath,
IN PUNICODE_STRING DestinationArcPath)
{
NTSTATUS Status;
PFILE_SYSTEM FatFS;

View file

@ -18,38 +18,30 @@
*/
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup
* FILE: base/setup/usetup/bootsup.h
* PROJECT: ReactOS Setup Library
* FILE: base/setup/lib/bootsup.h
* PURPOSE: Bootloader support functions
* PROGRAMMER:
*/
#pragma once
BOOLEAN
IsThereAValidBootSector(PWSTR RootPath);
NTSTATUS
SaveBootSector(
PWSTR RootPath,
PWSTR DstPath,
ULONG Length);
NTSTATUS
InstallMbrBootCodeToDisk(
PWSTR SrcPath,
PWSTR RootPath);
IN PUNICODE_STRING SystemRootPath,
IN PUNICODE_STRING SourceRootPath,
IN PCWSTR DestinationDevicePathBuffer);
NTSTATUS
InstallVBRToPartition(
PUNICODE_STRING SystemRootPath,
PUNICODE_STRING SourceRootPath,
PUNICODE_STRING DestinationArcPath,
UCHAR PartitionType);
IN PUNICODE_STRING SystemRootPath,
IN PUNICODE_STRING SourceRootPath,
IN PUNICODE_STRING DestinationArcPath,
IN UCHAR PartitionType);
NTSTATUS
InstallFatBootcodeToFloppy(
PUNICODE_STRING SourceRootPath,
PUNICODE_STRING DestinationArcPath);
IN PUNICODE_STRING SourceRootPath,
IN PUNICODE_STRING DestinationArcPath);
/* EOF */

View file

@ -6,6 +6,8 @@
* Copyright 2017-2018 Hermes Belusca-Maito
*/
#pragma once
#include <fmifs/fmifs.h>
typedef struct _FILE_SYSTEM

View file

@ -29,6 +29,7 @@ extern HANDLE ProcessHeap;
#include "ntverrsrc.h"
// #include "arcname.h"
#include "bldrsup.h"
#include "bootsup.h"
#include "filesup.h"
#include "fsutil.h"
#include "genlist.h"

View file

@ -10,7 +10,6 @@ include_directories(
${REACTOS_SOURCE_DIR}/sdk/include/reactos/drivers)
list(APPEND SOURCE
bootsup.c
cabinet.c
chkdsk.c
cmdcons.c

View file

@ -4601,8 +4601,6 @@ BootLoaderHarddiskMbrPage(PINPUT_RECORD Ir)
{
NTSTATUS Status;
WCHAR DestinationDevicePathBuffer[MAX_PATH];
WCHAR SourceMbrPathBuffer[MAX_PATH];
WCHAR DstPath[MAX_PATH];
/* Step 1: Write the VBR */
Status = InstallVBRToPartition(&USetupData.SystemRootPath,
@ -4619,26 +4617,8 @@ BootLoaderHarddiskMbrPage(PINPUT_RECORD Ir)
StringCchPrintfW(DestinationDevicePathBuffer, ARRAYSIZE(DestinationDevicePathBuffer),
L"\\Device\\Harddisk%d\\Partition0",
PartitionList->SystemPartition->DiskEntry->DiskNumber);
CombinePaths(SourceMbrPathBuffer, ARRAYSIZE(SourceMbrPathBuffer), 2, USetupData.SourceRootPath.Buffer, L"\\loader\\dosmbr.bin");
if (IsThereAValidBootSector(DestinationDevicePathBuffer))
{
/* Save current MBR */
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, USetupData.SystemRootPath.Buffer, L"mbr.old");
DPRINT1("Save MBR: %S ==> %S\n", DestinationDevicePathBuffer, DstPath);
Status = SaveBootSector(DestinationDevicePathBuffer, DstPath, sizeof(PARTITION_SECTOR));
if (!NT_SUCCESS(Status))
{
DPRINT1("SaveBootSector() failed (Status %lx)\n", Status);
// Don't care if we succeeded or not saving the old MBR, just go ahead.
}
}
DPRINT1("Install MBR bootcode: %S ==> %S\n",
SourceMbrPathBuffer, DestinationDevicePathBuffer);
Status = InstallMbrBootCodeToDisk(SourceMbrPathBuffer,
Status = InstallMbrBootCodeToDisk(&USetupData.SystemRootPath,
&USetupData.SourceRootPath,
DestinationDevicePathBuffer);
if (!NT_SUCCESS(Status))
{