https://git.reactos.org/?p=reactos.git;a=commitdiff;h=636e2e9172f905b376e543c7b2fefd51300038d6
commit 636e2e9172f905b376e543c7b2fefd51300038d6 Author: Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org> AuthorDate: Thu Oct 17 13:37:25 2024 +0200 Commit: Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org> CommitDate: Sun Oct 20 16:51:24 2024 +0200 [SETUPLIB] Introduce a helper for copying bootloader files (#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 #7420) Co-Authored-By: Timo Kreuzer <timo.kreu...@reactos.org> --- base/setup/lib/bootsup.c | 55 ++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/base/setup/lib/bootsup.c b/base/setup/lib/bootsup.c index 228376348b4..047de38b3cb 100644 --- a/base/setup/lib/bootsup.c +++ b/base/setup/lib/bootsup.c @@ -878,6 +878,31 @@ InstallMbrBootCodeToDisk( } +static +NTSTATUS +InstallBootloaderFiles( + _In_ PCUNICODE_STRING SystemRootPath, + _In_ PCUNICODE_STRING SourceRootPath) +{ + NTSTATUS Status; + WCHAR SrcPath[MAX_PATH]; + WCHAR DstPath[MAX_PATH]; + + /* Copy FreeLoader to the system partition, always overwriting the older version */ + CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys"); + CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.sys"); + + DPRINT1("Copy: %S ==> %S\n", SrcPath, DstPath); + Status = SetupCopyFile(SrcPath, DstPath, FALSE); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SetupCopyFile() failed (Status 0x%08lx)\n", Status); + return Status; + } + + return STATUS_SUCCESS; +} + static NTSTATUS InstallFatBootcodeToPartition( @@ -894,15 +919,11 @@ InstallFatBootcodeToPartition( /* FAT or FAT32 partition */ DPRINT("System path: '%wZ'\n", SystemRootPath); - /* Copy FreeLoader to the system partition, always overwriting the older version */ - CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys"); - CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.sys"); - - DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath); - Status = SetupCopyFile(SrcPath, DstPath, FALSE); + /* Install the bootloader */ + Status = InstallBootloaderFiles(SystemRootPath, SourceRootPath); if (!NT_SUCCESS(Status)) { - DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status); + DPRINT1("InstallBootloaderFiles() failed (Status %lx)\n", Status); return Status; } @@ -1187,15 +1208,11 @@ InstallBtrfsBootcodeToPartition( /* BTRFS partition */ DPRINT("System path: '%wZ'\n", SystemRootPath); - /* Copy FreeLoader to the system partition, always overwriting the older version */ - CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys"); - CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.sys"); - - DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath); - Status = SetupCopyFile(SrcPath, DstPath, FALSE); + /* Install the bootloader */ + Status = InstallBootloaderFiles(SystemRootPath, SourceRootPath); if (!NT_SUCCESS(Status)) { - DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status); + DPRINT1("InstallBootloaderFiles() failed (Status %lx)\n", Status); return Status; } @@ -1290,15 +1307,11 @@ InstallNtfsBootcodeToPartition( /* NTFS partition */ DPRINT("System path: '%wZ'\n", SystemRootPath); - /* Copy FreeLoader to the system partition, always overwriting the older version */ - CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys"); - CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.sys"); - - DPRINT1("Copy: %S ==> %S\n", SrcPath, DstPath); - Status = SetupCopyFile(SrcPath, DstPath, FALSE); + /* Install the bootloader */ + Status = InstallBootloaderFiles(SystemRootPath, SourceRootPath); if (!NT_SUCCESS(Status)) { - DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status); + DPRINT1("InstallBootloaderFiles() failed (Status %lx)\n", Status); return Status; }