Skip to content

Commit 636e2e9

Browse files
HBeluscatkreuzer
andcommitted
[SETUPLIB] Introduce a helper for copying bootloader files (reactos#7310)
This function could be generalized later to copy other files necessary for the bootloader; removing also the currently hardcoded placement in the installation source directory, and instead, using a configurable path (specified in txtsetup.sif); etc. Adapted from a commit by Timo Kreuzer (see PR reactos#7420) Co-Authored-By: Timo Kreuzer <[email protected]>
1 parent d6d3d0e commit 636e2e9

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

base/setup/lib/bootsup.c

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,31 @@ InstallMbrBootCodeToDisk(
878878
}
879879

880880

881+
static
882+
NTSTATUS
883+
InstallBootloaderFiles(
884+
_In_ PCUNICODE_STRING SystemRootPath,
885+
_In_ PCUNICODE_STRING SourceRootPath)
886+
{
887+
NTSTATUS Status;
888+
WCHAR SrcPath[MAX_PATH];
889+
WCHAR DstPath[MAX_PATH];
890+
891+
/* Copy FreeLoader to the system partition, always overwriting the older version */
892+
CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys");
893+
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.sys");
894+
895+
DPRINT1("Copy: %S ==> %S\n", SrcPath, DstPath);
896+
Status = SetupCopyFile(SrcPath, DstPath, FALSE);
897+
if (!NT_SUCCESS(Status))
898+
{
899+
DPRINT1("SetupCopyFile() failed (Status 0x%08lx)\n", Status);
900+
return Status;
901+
}
902+
903+
return STATUS_SUCCESS;
904+
}
905+
881906
static
882907
NTSTATUS
883908
InstallFatBootcodeToPartition(
@@ -894,15 +919,11 @@ InstallFatBootcodeToPartition(
894919
/* FAT or FAT32 partition */
895920
DPRINT("System path: '%wZ'\n", SystemRootPath);
896921

897-
/* Copy FreeLoader to the system partition, always overwriting the older version */
898-
CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys");
899-
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.sys");
900-
901-
DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath);
902-
Status = SetupCopyFile(SrcPath, DstPath, FALSE);
922+
/* Install the bootloader */
923+
Status = InstallBootloaderFiles(SystemRootPath, SourceRootPath);
903924
if (!NT_SUCCESS(Status))
904925
{
905-
DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status);
926+
DPRINT1("InstallBootloaderFiles() failed (Status %lx)\n", Status);
906927
return Status;
907928
}
908929

@@ -1187,15 +1208,11 @@ InstallBtrfsBootcodeToPartition(
11871208
/* BTRFS partition */
11881209
DPRINT("System path: '%wZ'\n", SystemRootPath);
11891210

1190-
/* Copy FreeLoader to the system partition, always overwriting the older version */
1191-
CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys");
1192-
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.sys");
1193-
1194-
DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath);
1195-
Status = SetupCopyFile(SrcPath, DstPath, FALSE);
1211+
/* Install the bootloader */
1212+
Status = InstallBootloaderFiles(SystemRootPath, SourceRootPath);
11961213
if (!NT_SUCCESS(Status))
11971214
{
1198-
DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status);
1215+
DPRINT1("InstallBootloaderFiles() failed (Status %lx)\n", Status);
11991216
return Status;
12001217
}
12011218

@@ -1290,15 +1307,11 @@ InstallNtfsBootcodeToPartition(
12901307
/* NTFS partition */
12911308
DPRINT("System path: '%wZ'\n", SystemRootPath);
12921309

1293-
/* Copy FreeLoader to the system partition, always overwriting the older version */
1294-
CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys");
1295-
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.sys");
1296-
1297-
DPRINT1("Copy: %S ==> %S\n", SrcPath, DstPath);
1298-
Status = SetupCopyFile(SrcPath, DstPath, FALSE);
1310+
/* Install the bootloader */
1311+
Status = InstallBootloaderFiles(SystemRootPath, SourceRootPath);
12991312
if (!NT_SUCCESS(Status))
13001313
{
1301-
DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status);
1314+
DPRINT1("InstallBootloaderFiles() failed (Status %lx)\n", Status);
13021315
return Status;
13031316
}
13041317

0 commit comments

Comments
 (0)