[USETUP][SETUPLIB] Move the bootsup.c code into the setuplib, and perform the necessa...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 26 Aug 2017 11:42:32 +0000 (11:42 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 27 Oct 2018 20:09:32 +0000 (22:09 +0200)
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
base/setup/lib/bootsup.c [moved from base/setup/usetup/bootsup.c with 91% similarity]
base/setup/lib/bootsup.h [moved from base/setup/usetup/bootsup.h with 68% similarity]
base/setup/lib/fsutil.h
base/setup/lib/setuplib.h
base/setup/usetup/CMakeLists.txt
base/setup/usetup/usetup.c

index cf3f2b8..a1b9a90 100644 (file)
@@ -2,6 +2,7 @@
 list(APPEND SOURCE
     arcname.c
     bldrsup.c
+    bootsup.c
     filesup.c
     fsutil.c
     genlist.c
similarity index 91%
rename from base/setup/usetup/bootsup.c
rename to base/setup/lib/bootsup.c
index b6d4220..7ea6240 100644 (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!!
  * ===========
 #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;
similarity index 68%
rename from base/setup/usetup/bootsup.h
rename to base/setup/lib/bootsup.h
index 33de23d..c9bd854 100644 (file)
  */
 /*
  * 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 */
index 46fe556..bb10c4a 100644 (file)
@@ -6,6 +6,8 @@
  *              Copyright 2017-2018 Hermes Belusca-Maito
  */
 
+#pragma once
+
 #include <fmifs/fmifs.h>
 
 typedef struct _FILE_SYSTEM
index 154b1d5..2d30fd0 100644 (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"
index 66a22fc..d82f1c2 100644 (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
index a053d90..4e20095 100644 (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))
     {