https://git.reactos.org/?p=reactos.git;a=commitdiff;h=95a34ef6fc5d916ebb751…
commit 95a34ef6fc5d916ebb751230c5b18cb1d80ab641
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sat Aug 26 11:42:32 2017 +0000
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Oct 27 22:09:32 2018 +0200
[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
---
base/setup/lib/CMakeLists.txt | 1 +
base/setup/{usetup => lib}/bootsup.c | 207 +++++++++++++++++++++++------------
base/setup/{usetup => lib}/bootsup.h | 30 ++---
base/setup/lib/fsutil.h | 2 +
base/setup/lib/setuplib.h | 1 +
base/setup/usetup/CMakeLists.txt | 1 -
base/setup/usetup/usetup.c | 24 +---
7 files changed, 151 insertions(+), 115 deletions(-)
diff --git a/base/setup/lib/CMakeLists.txt b/base/setup/lib/CMakeLists.txt
index cf3f2b8a2a..a1b9a90f36 100644
--- a/base/setup/lib/CMakeLists.txt
+++ b/base/setup/lib/CMakeLists.txt
@@ -2,6 +2,7 @@
list(APPEND SOURCE
arcname.c
bldrsup.c
+ bootsup.c
filesup.c
fsutil.c
genlist.c
diff --git a/base/setup/usetup/bootsup.c b/base/setup/lib/bootsup.c
similarity index 91%
rename from base/setup/usetup/bootsup.c
rename to base/setup/lib/bootsup.c
index b6d4220dc0..7ea6240b9a 100644
--- a/base/setup/usetup/bootsup.c
+++ b/base/setup/lib/bootsup.c
@@ -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(a)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!!
* ===========
@@ -31,66 +45,66 @@
#include <pshpack1.h>
typedef struct _FAT_BOOTSECTOR
{
- 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
+ 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
} FAT_BOOTSECTOR, *PFAT_BOOTSECTOR;
typedef struct _FAT32_BOOTSECTOR
{
- 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
+ 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
} FAT32_BOOTSECTOR, *PFAT32_BOOTSECTOR;
@@ -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;
diff --git a/base/setup/usetup/bootsup.h b/base/setup/lib/bootsup.h
similarity index 68%
rename from base/setup/usetup/bootsup.h
rename to base/setup/lib/bootsup.h
index 33de23d7dc..c9bd8544ee 100644
--- a/base/setup/usetup/bootsup.h
+++ b/base/setup/lib/bootsup.h
@@ -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 */
diff --git a/base/setup/lib/fsutil.h b/base/setup/lib/fsutil.h
index 46fe556d8f..bb10c4a0f6 100644
--- a/base/setup/lib/fsutil.h
+++ b/base/setup/lib/fsutil.h
@@ -6,6 +6,8 @@
* Copyright 2017-2018 Hermes Belusca-Maito
*/
+#pragma once
+
#include <fmifs/fmifs.h>
typedef struct _FILE_SYSTEM
diff --git a/base/setup/lib/setuplib.h b/base/setup/lib/setuplib.h
index 154b1d5f25..2d30fd0f72 100644
--- a/base/setup/lib/setuplib.h
+++ b/base/setup/lib/setuplib.h
@@ -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"
diff --git a/base/setup/usetup/CMakeLists.txt b/base/setup/usetup/CMakeLists.txt
index 66a22fcbb5..d82f1c2f75 100644
--- a/base/setup/usetup/CMakeLists.txt
+++ b/base/setup/usetup/CMakeLists.txt
@@ -10,7 +10,6 @@ include_directories(
${REACTOS_SOURCE_DIR}/sdk/include/reactos/drivers)
list(APPEND SOURCE
- bootsup.c
cabinet.c
chkdsk.c
cmdcons.c
diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c
index a053d90fd0..4e200955f7 100644
--- a/base/setup/usetup/usetup.c
+++ b/base/setup/usetup/usetup.c
@@ -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))
{