From 4263b27dfbeeb883950c29bbbc0eaf777664b945 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Tue, 28 Jan 2003 17:29:22 +0000 Subject: [PATCH] Added bootsector installation and boot.ini manipulation. svn path=/trunk/; revision=4078 --- reactos/subsys/system/usetup/bootsup.c | 1203 ++++++++++++++++++++++- reactos/subsys/system/usetup/bootsup.h | 32 +- reactos/subsys/system/usetup/inicache.c | 43 +- reactos/subsys/system/usetup/usetup.c | 217 +++- 4 files changed, 1435 insertions(+), 60 deletions(-) diff --git a/reactos/subsys/system/usetup/bootsup.c b/reactos/subsys/system/usetup/bootsup.c index 87fd1c32c9c..4c9c07ed565 100644 --- a/reactos/subsys/system/usetup/bootsup.c +++ b/reactos/subsys/system/usetup/bootsup.c @@ -32,6 +32,8 @@ #include "bootsup.h" +#define SECTORSIZE 512 + /* FUNCTIONS ****************************************************************/ @@ -58,31 +60,34 @@ MessageBox=Edit your FREELDR.INI file to change your boot settings. L"DefaultOS", L"ReactOS"); +#if 0 /* Timeout=10 */ IniCacheInsertKey(IniSection, NULL, INSERT_LAST, L"TimeOut", L"10"); - +#endif /* Create "Display" section */ IniSection = IniCacheAppendSection(IniCache, L"Display"); + /* TitleText=ReactOS Boot Manager */ + IniCacheInsertKey(IniSection, + NULL, + INSERT_LAST, + L"TitleText", + L"ReactOS Boot Manager"); + +#if 0 /* DisplayMode=NORMAL_VGA */ IniCacheInsertKey(IniSection, NULL, INSERT_LAST, L"DisplayMode", L"NORMAL_VGA"); - - /* TitleText=Boot Menu */ - IniCacheInsertKey(IniSection, - NULL, - INSERT_LAST, - L"TitleText", - L"Boot Menu"); +#endif /* StatusBarColor=Cyan */ IniCacheInsertKey(IniSection, @@ -186,7 +191,7 @@ MessageBox=Edit your FREELDR.INI file to change your boot settings. NTSTATUS CreateFreeLoaderIniForDos(PWCHAR IniPath, - PWCHAR SystemPath) + PWCHAR ArcPath) { PINICACHE IniCache; PINICACHESECTION IniSection; @@ -195,27 +200,27 @@ CreateFreeLoaderIniForDos(PWCHAR IniPath, CreateCommonFreeLoaderSections(IniCache); - /* Create "OperatingSystems" section */ + /* Create "Operating Systems" section */ IniSection = IniCacheAppendSection(IniCache, - L"OperatingSystems"); + L"Operating Systems"); /* REACTOS=ReactOS */ IniCacheInsertKey(IniSection, NULL, INSERT_LAST, - L"REACTOS", - L"ReactOS"); + L"ReactOS", + L"\"ReactOS\""); /* DOS=Dos/Windows */ IniCacheInsertKey(IniSection, NULL, INSERT_LAST, L"DOS", - L"DOS/Windows"); + L"\"DOS/Windows\""); - /* Create "REACTOS" section */ + /* Create "ReactOS" section */ IniSection = IniCacheAppendSection(IniCache, - L"REACTOS"); + L"ReactOS"); /* BootType=ReactOS */ IniCacheInsertKey(IniSection, @@ -229,7 +234,7 @@ CreateFreeLoaderIniForDos(PWCHAR IniPath, NULL, INSERT_LAST, L"SystemPath", - SystemPath); + ArcPath); /* Options=/DEBUGPORT=SCREEN */ IniCacheInsertKey(IniSection, @@ -268,15 +273,1173 @@ CreateFreeLoaderIniForDos(PWCHAR IniPath, L"BootType", L"BootSector"); - /* BootSector=BOOTDOS.BIN */ + /* BootDrive=hd0 */ IniCacheInsertKey(IniSection, NULL, INSERT_LAST, - L"BootSector", - L"BOOTDOS.BIN"); + L"BootDrive", + L"hd0"); + + /* BootPartition=1 */ + IniCacheInsertKey(IniSection, + NULL, + INSERT_LAST, + L"BootPartition", + L"1"); + + /* BootSector=BOOTSECT.DOS */ + IniCacheInsertKey(IniSection, + NULL, + INSERT_LAST, + L"BootSectorFile", + L"BOOTSECT.DOS"); IniCacheSave(IniCache, IniPath); IniCacheDestroy(IniCache); } + +NTSTATUS +CreateFreeLoaderIniForReactos(PWCHAR IniPath, + PWCHAR ArcPath) +{ + PINICACHE IniCache; + PINICACHESECTION IniSection; + + IniCache = IniCacheCreate(); + + CreateCommonFreeLoaderSections(IniCache); + + /* Create "Operating Systems" section */ + IniSection = IniCacheAppendSection(IniCache, + L"Operating Systems"); + + /* ReactOS="ReactOS" */ + IniCacheInsertKey(IniSection, + NULL, + INSERT_LAST, + L"ReactOS", + L"\"ReactOS\""); + + /* Create "ReactOS" section */ + IniSection = IniCacheAppendSection(IniCache, + L"ReactOS"); + + /* BootType=ReactOS */ + IniCacheInsertKey(IniSection, + NULL, + INSERT_LAST, + L"BootType", + L"ReactOS"); + + /* SystemPath=multi(0)disk(0)rdisk(0)partition(1)\reactos */ + IniCacheInsertKey(IniSection, + NULL, + INSERT_LAST, + L"SystemPath", + ArcPath); + + /* Options=/DEBUGPORT=SCREEN */ + IniCacheInsertKey(IniSection, + NULL, + INSERT_LAST, + L"Options", + L"/DEBUGPORT=SCREEN"); + + + /* Kernel=\REACTOS\SYSTEM32\NTOSKRNL.EXE */ +#if 0 + IniCacheInsertKey(IniSection, + NULL, + INSERT_LAST, + L"Kernel", + L"/DEBUGPORT=SCREEN"); +#endif + + /* Hal=\REACTOS\SYSTEM32\HAL.DLL */ +#if 0 + IniCacheInsertKey(IniSection, + NULL, + INSERT_LAST, + L"Hal", + L"/DEBUGPORT=SCREEN"); +#endif + + IniCacheSave(IniCache, IniPath); + IniCacheDestroy(IniCache); +} + + +NTSTATUS +SaveCurrentBootSector(PWSTR RootPath, + PWSTR DstPath) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + UNICODE_STRING Name; + HANDLE FileHandle; + NTSTATUS Status; + PUCHAR BootSector; + + /* Allocate buffer for bootsector */ + BootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap, + 0, + SECTORSIZE); + if (BootSector == NULL) + return(STATUS_INSUFFICIENT_RESOURCES); + + /* Read current boot sector into buffer */ + RtlInitUnicodeString(&Name, + RootPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_READ_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_ALERT); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, BootSector); + return(Status); + } + + Status = NtReadFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + BootSector, + SECTORSIZE, + NULL, + NULL); + NtClose(FileHandle); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, BootSector); + return(Status); + } + + /* Write bootsector to DstPath */ + RtlInitUnicodeString(&Name, + DstPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + 0, + NULL, + NULL); + + Status = NtCreateFile(&FileHandle, + FILE_WRITE_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + NULL, + FILE_ATTRIBUTE_NORMAL, + 0, + FILE_SUPERSEDE, + FILE_SYNCHRONOUS_IO_ALERT | FILE_SEQUENTIAL_ONLY, + NULL, + 0); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, BootSector); + return(Status); + } + + Status = NtWriteFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + BootSector, + SECTORSIZE, + NULL, + NULL); + NtClose(FileHandle); + + /* Free the new boot sector */ + RtlFreeHeap(ProcessHeap, 0, BootSector); + + return(Status); +} + + +NTSTATUS +InstallFat16BootCodeToFile(PWSTR SrcPath, + PWSTR DstPath, + PWSTR RootPath) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + UNICODE_STRING Name; + HANDLE FileHandle; + NTSTATUS Status; + PUCHAR OrigBootSector; + PUCHAR NewBootSector; + + /* Allocate buffer for original bootsector */ + OrigBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap, + 0, + SECTORSIZE); + if (OrigBootSector == NULL) + return(STATUS_INSUFFICIENT_RESOURCES); + + /* Read current boot sector into buffer */ + RtlInitUnicodeString(&Name, + RootPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_READ_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_ALERT); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + return(Status); + } + + Status = NtReadFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + OrigBootSector, + SECTORSIZE, + NULL, + NULL); + NtClose(FileHandle); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + return(Status); + } + + + /* Allocate buffer for new bootsector */ + NewBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap, + 0, + SECTORSIZE); + if (NewBootSector == NULL) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + return(STATUS_INSUFFICIENT_RESOURCES); + } + + /* Read new bootsector from SrcPath */ + RtlInitUnicodeString(&Name, + SrcPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_READ_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_ALERT); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + + Status = NtReadFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + NewBootSector, + SECTORSIZE, + NULL, + NULL); + NtClose(FileHandle); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + + /* Adjust bootsector (copy a part of the FAT BPB) */ + memcpy((NewBootSector + 11), (OrigBootSector + 11), 51 /*fat BPB length*/); + + /* Free the original boot sector */ + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + + /* Write new bootsector to DstPath */ + RtlInitUnicodeString(&Name, + DstPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + 0, + NULL, + NULL); + + Status = NtCreateFile(&FileHandle, + FILE_WRITE_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + NULL, + FILE_ATTRIBUTE_NORMAL, + 0, + FILE_OVERWRITE_IF, + FILE_SYNCHRONOUS_IO_ALERT | FILE_SEQUENTIAL_ONLY, + NULL, + 0); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + +#if 0 + FilePosition.QuadPart = 0; +#endif + Status = NtWriteFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + NewBootSector, + SECTORSIZE, + NULL, + NULL); + NtClose(FileHandle); + + /* Free the new boot sector */ + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + + return(Status); +} + + +NTSTATUS +InstallFat32BootCodeToFile(PWSTR SrcPath, + PWSTR DstPath, + PWSTR RootPath) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + UNICODE_STRING Name; + HANDLE FileHandle; + NTSTATUS Status; + PUCHAR OrigBootSector; + PUCHAR NewBootSector; + LARGE_INTEGER FileOffset; + + /* Allocate buffer for original bootsector */ + OrigBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap, + 0, + SECTORSIZE); + if (OrigBootSector == NULL) + return(STATUS_INSUFFICIENT_RESOURCES); + + /* Read current boot sector into buffer */ + RtlInitUnicodeString(&Name, + RootPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_READ_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_ALERT); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + return(Status); + } + + Status = NtReadFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + OrigBootSector, + SECTORSIZE, + NULL, + NULL); + NtClose(FileHandle); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + return(Status); + } + + /* Allocate buffer for new bootsector (2 sectors) */ + NewBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap, + 0, + 2 * SECTORSIZE); + if (NewBootSector == NULL) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + return(STATUS_INSUFFICIENT_RESOURCES); + } + + /* Read new bootsector from SrcPath */ + RtlInitUnicodeString(&Name, + SrcPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_READ_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_ALERT); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + + Status = NtReadFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + NewBootSector, + 2 * SECTORSIZE, + NULL, + NULL); + NtClose(FileHandle); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + + /* Adjust bootsector (copy a part of the FAT32 BPB) */ + memcpy((NewBootSector + 3), + (OrigBootSector + 3), + 87); /* FAT32 BPB length */ + + /* Disable the backup boot sector */ + NewBootSector[0x32] = 0xFF; + NewBootSector[0x33] = 0xFF; + + /* Free the original boot sector */ + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + + /* Write the first sector of the new bootcode to DstPath */ + RtlInitUnicodeString(&Name, + DstPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + 0, + NULL, + NULL); + + Status = NtCreateFile(&FileHandle, + FILE_WRITE_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + NULL, + FILE_ATTRIBUTE_NORMAL, + 0, + FILE_SUPERSEDE, + FILE_SYNCHRONOUS_IO_ALERT | FILE_SEQUENTIAL_ONLY, + NULL, + 0); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + + Status = NtWriteFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + NewBootSector, + SECTORSIZE, + NULL, + NULL); + NtClose(FileHandle); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + + /* Write the second sector of the new bootcode to boot disk sector 14 */ + RtlInitUnicodeString(&Name, + RootPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + 0, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_WRITE_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_ALERT); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + + FileOffset.QuadPart = (ULONGLONG)(14 * SECTORSIZE); + Status = NtWriteFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + (NewBootSector + SECTORSIZE), + SECTORSIZE, + &FileOffset, + NULL); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + } + NtClose(FileHandle); + + /* Free the new boot sector */ + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + + return(Status); +} + + +NTSTATUS +InstallFat16BootCodeToDisk(PWSTR SrcPath, + PWSTR RootPath) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + UNICODE_STRING Name; + HANDLE FileHandle; + NTSTATUS Status; + PUCHAR OrigBootSector; + PUCHAR NewBootSector; + + /* Allocate buffer for original bootsector */ + OrigBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap, + 0, + SECTORSIZE); + if (OrigBootSector == NULL) + return(STATUS_INSUFFICIENT_RESOURCES); + + /* Read current boot sector into buffer */ + RtlInitUnicodeString(&Name, + RootPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_READ_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_ALERT); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + return(Status); + } + + Status = NtReadFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + OrigBootSector, + SECTORSIZE, + NULL, + NULL); + NtClose(FileHandle); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + return(Status); + } + + + /* Allocate buffer for new bootsector */ + NewBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap, + 0, + SECTORSIZE); + if (NewBootSector == NULL) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + return(STATUS_INSUFFICIENT_RESOURCES); + } + + /* Read new bootsector from SrcPath */ + RtlInitUnicodeString(&Name, + SrcPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_READ_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_ALERT); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + + Status = NtReadFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + NewBootSector, + SECTORSIZE, + NULL, + NULL); + NtClose(FileHandle); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + + /* Adjust bootsector (copy a part of the FAT BPB) */ + memcpy((NewBootSector + 11), (OrigBootSector + 11), 51 /*fat BPB length*/); + + /* Free the original boot sector */ + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + + /* Write new bootsector to RootPath */ + RtlInitUnicodeString(&Name, + RootPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + 0, + NULL, + NULL); + + Status = NtCreateFile(&FileHandle, + FILE_WRITE_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + NULL, + FILE_ATTRIBUTE_NORMAL, + 0, + FILE_OVERWRITE_IF, + FILE_SYNCHRONOUS_IO_ALERT | FILE_SEQUENTIAL_ONLY, + NULL, + 0); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + +#if 0 + FilePosition.QuadPart = 0; +#endif + Status = NtWriteFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + NewBootSector, + SECTORSIZE, + NULL, + NULL); + NtClose(FileHandle); + + /* Free the new boot sector */ + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + + return(Status); +} + + +NTSTATUS +InstallFat32BootCodeToDisk(PWSTR SrcPath, + PWSTR RootPath) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + UNICODE_STRING Name; + HANDLE FileHandle; + NTSTATUS Status; + PUCHAR OrigBootSector; + PUCHAR NewBootSector; + LARGE_INTEGER FileOffset; + USHORT BackupBootSector; + + /* Allocate buffer for original bootsector */ + OrigBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap, + 0, + SECTORSIZE); + if (OrigBootSector == NULL) + return(STATUS_INSUFFICIENT_RESOURCES); + + /* Read current boot sector into buffer */ + RtlInitUnicodeString(&Name, + RootPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_READ_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_ALERT); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + return(Status); + } + + Status = NtReadFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + OrigBootSector, + SECTORSIZE, + NULL, + NULL); + NtClose(FileHandle); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + return(Status); + } + + + /* Allocate buffer for new bootsector (2 sectors) */ + NewBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap, + 0, + 2 * SECTORSIZE); + if (NewBootSector == NULL) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + return(STATUS_INSUFFICIENT_RESOURCES); + } + + /* Read new bootsector from SrcPath */ + RtlInitUnicodeString(&Name, + SrcPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_READ_ACCESS, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_ALERT); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + + Status = NtReadFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + NewBootSector, + 2 * SECTORSIZE, + NULL, + NULL); + NtClose(FileHandle); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + + /* Adjust bootsector (copy a part of the FAT32 BPB) */ + memcpy((NewBootSector + 3), + (OrigBootSector + 3), + 87); /* FAT32 BPB length */ + + /* Get the location of the backup boot sector */ + BackupBootSector = (OrigBootSector[0x33] << 8) + OrigBootSector[0x33]; + + /* Disable the backup boot sector */ +// NewBootSector[0x32] = 0xFF; +// NewBootSector[0x33] = 0xFF; + + /* Free the original boot sector */ + RtlFreeHeap(ProcessHeap, 0, OrigBootSector); + + /* Write the first sector of the new bootcode to DstPath */ + RtlInitUnicodeString(&Name, + RootPath); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + 0, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_WRITE_ACCESS | FILE_WRITE_ATTRIBUTES, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_ALERT | FILE_SEQUENTIAL_ONLY); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtOpenFile() failed (Status %lx)\n", Status); + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + + /* Write sector 0 */ + FileOffset.QuadPart = 0ULL; + Status = NtWriteFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + NewBootSector, + SECTORSIZE, + &FileOffset, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtWriteFile() failed (Status %lx)\n", Status); + NtClose(FileHandle); + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + + /* Write backup boot sector */ + if (BackupBootSector != 0xFFFF) + { + FileOffset.QuadPart = (ULONGLONG)((ULONG)BackupBootSector * SECTORSIZE); + Status = NtWriteFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + NewBootSector, + SECTORSIZE, + &FileOffset, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtWriteFile() failed (Status %lx)\n", Status); + NtClose(FileHandle); + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return(Status); + } + } + + /* Write sector 14 */ + FileOffset.QuadPart = (ULONGLONG)(14 * SECTORSIZE); + Status = NtWriteFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + (NewBootSector + SECTORSIZE), + SECTORSIZE, + &FileOffset, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtWriteFile() failed (Status %lx)\n", Status); + } + NtClose(FileHandle); + + /* Free the new boot sector */ + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + + return(Status); +} + + +static NTSTATUS +UnprotectBootIni(PWSTR FileName, + PULONG Attributes) +{ + UNICODE_STRING Name; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + FILE_BASIC_INFORMATION FileInfo; + HANDLE FileHandle; + NTSTATUS Status; + + RtlInitUnicodeString(&Name, + FileName); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_ALERT); + if (Status == STATUS_NO_SUCH_FILE) + { + DPRINT1("NtOpenFile() failed (Status %lx)\n", Status); + *Attributes = 0; + return(STATUS_SUCCESS); + } + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtOpenFile() failed (Status %lx)\n", Status); + return(Status); + } + + Status = NtQueryInformationFile(FileHandle, + &IoStatusBlock, + &FileInfo, + sizeof(FILE_BASIC_INFORMATION), + FileBasicInformation); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtQueryInformationFile() failed (Status %lx)\n", Status); + NtClose(FileHandle); + return(Status); + } + + *Attributes = FileInfo.FileAttributes; + + /* Delete attributes SYSTEM, HIDDEN and READONLY */ + FileInfo.FileAttributes = FileInfo.FileAttributes & + ~(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY); + + Status = NtSetInformationFile(FileHandle, + &IoStatusBlock, + &FileInfo, + sizeof(FILE_BASIC_INFORMATION), + FileBasicInformation); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtSetInformationFile() failed (Status %lx)\n", Status); + } + + NtClose(FileHandle); + return(Status); +} + + +static NTSTATUS +ProtectBootIni(PWSTR FileName, + ULONG Attributes) +{ + UNICODE_STRING Name; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + FILE_BASIC_INFORMATION FileInfo; + HANDLE FileHandle; + NTSTATUS Status; + + RtlInitUnicodeString(&Name, + FileName); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_ALERT); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtOpenFile() failed (Status %lx)\n", Status); + return(Status); + } + + Status = NtQueryInformationFile(FileHandle, + &IoStatusBlock, + &FileInfo, + sizeof(FILE_BASIC_INFORMATION), + FileBasicInformation); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtQueryInformationFile() failed (Status %lx)\n", Status); + NtClose(FileHandle); + return(Status); + } + + FileInfo.FileAttributes = FileInfo.FileAttributes | Attributes; + + Status = NtSetInformationFile(FileHandle, + &IoStatusBlock, + &FileInfo, + sizeof(FILE_BASIC_INFORMATION), + FileBasicInformation); + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtSetInformationFile() failed (Status %lx)\n", Status); + } + + NtClose(FileHandle); + return(Status); +} + + +NTSTATUS +UpdateBootIni(PWSTR BootIniPath, + PWSTR EntryName, + PWSTR EntryValue) +{ + UNICODE_STRING Name; + PINICACHE Cache = NULL; + PINICACHESECTION Section = NULL; + NTSTATUS Status; + ULONG FileAttribute; + + RtlInitUnicodeString(&Name, + BootIniPath); + + Status = IniCacheLoad(&Cache, + &Name); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + return(Status); + } + + Section = IniCacheGetSection(Cache, + L"operating systems"); + if (Section == NULL) + { +CHECKPOINT1; + IniCacheDestroy(Cache); + return(STATUS_UNSUCCESSFUL); + } + + IniCacheInsertKey(Section, + NULL, + INSERT_LAST, + EntryName, + EntryValue); + + Status = UnprotectBootIni(BootIniPath, + &FileAttribute); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + IniCacheDestroy(Cache); + return(Status); + } + + Status = IniCacheSave(Cache, + BootIniPath); + if (!NT_SUCCESS(Status)) + { +CHECKPOINT1; + IniCacheDestroy(Cache); + return(Status); + } + + FileAttribute |= (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY); + Status = ProtectBootIni(BootIniPath, + FileAttribute); + + IniCacheDestroy(Cache); + + return(Status); +} + /* EOF */ \ No newline at end of file diff --git a/reactos/subsys/system/usetup/bootsup.h b/reactos/subsys/system/usetup/bootsup.h index 41c44a357bf..a98ce08e065 100644 --- a/reactos/subsys/system/usetup/bootsup.h +++ b/reactos/subsys/system/usetup/bootsup.h @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: bootsup.h,v 1.1 2003/01/17 13:18:15 ekohl Exp $ +/* $Id: bootsup.h,v 1.2 2003/01/28 17:29:22 ekohl Exp $ * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS text-mode setup * FILE: subsys/system/usetup/bootsup.h @@ -29,8 +29,36 @@ NTSTATUS CreateFreeLoaderIniForDos(PWCHAR IniPath, - PWCHAR SystemPath); + PWCHAR ArcPath); +NTSTATUS +CreateFreeLoaderIniForReactos(PWCHAR IniPath, + PWCHAR ArcPath); + + +NTSTATUS +InstallFat16BootCodeToFile(PWSTR SrcPath, + PWSTR DstPath, + PWSTR RootPath); + +NTSTATUS +InstallFat32BootCodeToFile(PWSTR SrcPath, + PWSTR DstPath, + PWSTR RootPath); + +NTSTATUS +InstallFat16BootCodeToDisk(PWSTR SrcPath, + PWSTR RootPath); + +NTSTATUS +InstallFat32BootCodeToDisk(PWSTR SrcPath, + PWSTR RootPath); + + +NTSTATUS +UpdateBootIni(PWSTR BootIniPath, + PWSTR EntryName, + PWSTR EntryValue); #endif /* __BOOTSUP_H__ */ diff --git a/reactos/subsys/system/usetup/inicache.c b/reactos/subsys/system/usetup/inicache.c index eb182c5f559..990a263bf86 100644 --- a/reactos/subsys/system/usetup/inicache.c +++ b/reactos/subsys/system/usetup/inicache.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: inicache.c,v 1.2 2003/01/17 13:18:15 ekohl Exp $ +/* $Id: inicache.c,v 1.3 2003/01/28 17:29:22 ekohl Exp $ * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS text-mode setup * FILE: subsys/system/usetup/inicache.c @@ -423,55 +423,38 @@ IniCacheGetKeyValue(PCHAR Ptr, *DataPtr = NULL; *DataSize = 0; - /* skip whitespace */ + /* Skip whitespace */ while (*Ptr != 0 && isspace(*Ptr)) { Ptr++; } - /* check and skip '=' */ + /* Check and skip '=' */ if (*Ptr != '=') { return(NULL); } Ptr++; - /* skip whitespace */ + /* Skip whitespace */ while (*Ptr != 0 && isspace(*Ptr)) { Ptr++; } - /* check for quoted data */ - if (*Ptr == '\"') + /* Get data */ + *DataPtr = Ptr; + while (*Ptr != 0 && *Ptr != '\r') { Ptr++; - *DataPtr = Ptr; - - while (*Ptr != 0 && *Ptr != '\"') - { - Ptr++; - Size++; - } - Ptr++; - } - else - { - *DataPtr = Ptr; - - while (*Ptr != 0 && !isspace(*Ptr) && *Ptr != '\n') - { - Ptr++; - Size++; - } + Size++; } /* Skip to next line */ - while (*Ptr != 0 && *Ptr != '\n') - { - Ptr++; - } - Ptr++; + if (*Ptr == '\r') + Ptr++; + if (*Ptr == '\n') + Ptr++; *DataSize = Size; @@ -1069,7 +1052,7 @@ IniCacheSave(PINICACHE Cache, NULL, FILE_ATTRIBUTE_NORMAL, 0, - FILE_OVERWRITE_IF, + FILE_SUPERSEDE, FILE_SYNCHRONOUS_IO_ALERT | FILE_SEQUENTIAL_ONLY, NULL, 0); diff --git a/reactos/subsys/system/usetup/usetup.c b/reactos/subsys/system/usetup/usetup.c index 91c2297cf14..de8117c74c6 100644 --- a/reactos/subsys/system/usetup/usetup.c +++ b/reactos/subsys/system/usetup/usetup.c @@ -82,6 +82,7 @@ UNICODE_STRING SourceRootPath; UNICODE_STRING InstallPath; UNICODE_STRING DestinationPath; +UNICODE_STRING DestinationArcPath; UNICODE_STRING DestinationRootPath; UNICODE_STRING SystemRootPath; /* Path to the active partition */ @@ -927,6 +928,19 @@ InstallDirectoryPage(PINPUT_RECORD Ir) RtlCreateUnicodeString(&DestinationPath, PathBuffer); + /* Create 'DestinationArcPath' */ + RtlFreeUnicodeString(&DestinationArcPath); + swprintf(PathBuffer, + L"multi(0)disk(0)rdisk(%lu)partition(%lu)", + PartData.DiskNumber, + PartData.PartNumber); + if (InstallDir[0] != L'\\') + wcscat(PathBuffer, + L"\\"); + wcscat(PathBuffer, InstallDir); + RtlCreateUnicodeString(&DestinationArcPath, + PathBuffer); + return(PREPARE_COPY_PAGE); } else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x08) /* BACKSPACE */ @@ -1397,6 +1411,7 @@ BootLoaderPage(PINPUT_RECORD Ir) WCHAR DstPath[MAX_PATH]; PINICACHE IniCache; PINICACHESECTION IniSection; + NTSTATUS Status; SetTextXY(6, 8, "Installing the boot loader"); @@ -1439,7 +1454,7 @@ BootLoaderPage(PINPUT_RECORD Ir) (ActivePartition.PartType == PARTITION_FAT32) || (ActivePartition.PartType == PARTITION_FAT32_XINT13)) { - /* FAT or FAT 32 partition */ + /* FAT or FAT32 partition */ PrintTextXY(6, 10, "System path: '%wZ'", &SystemRootPath); if (DoesFileExist(SystemRootPath.Buffer, L"ntldr") == TRUE || @@ -1448,7 +1463,81 @@ BootLoaderPage(PINPUT_RECORD Ir) /* Search root directory for 'ntldr' and 'boot.ini'. */ SetTextXY(6, 12, "Found Microsoft Windows NT/2000/XP boot loader"); + /* Copy FreeLoader to the boot partition */ + wcscpy(SrcPath, SourceRootPath.Buffer); + wcscat(SrcPath, L"\\loader\\freeldr.sys"); + wcscpy(DstPath, SystemRootPath.Buffer); + wcscat(DstPath, L"\\freeldr.sys"); +// PrintTextXY(6, 14, "Copy: %S ==> %S", SrcPath, DstPath); + Status = SetupCopyFile(SrcPath, DstPath); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status); + } + + /* Create freeldr.ini */ + wcscpy(DstPath, SystemRootPath.Buffer); + wcscat(DstPath, L"\\freeldr.ini"); + + Status = CreateFreeLoaderIniForReactos(DstPath, + DestinationArcPath.Buffer); + if (!NT_SUCCESS(Status)) + { + DPRINT1("CreateFreeLoaderIniForReactos() failed (Status %lx)\n", Status); + } + + /* Install new bootsector */ + if ((ActivePartition.PartType == PARTITION_FAT32) || + (ActivePartition.PartType == PARTITION_FAT32_XINT13)) + { + wcscpy(SrcPath, SourceRootPath.Buffer); + wcscat(SrcPath, L"\\loader\\fat32.bin"); + + wcscpy(DstPath, SystemRootPath.Buffer); + wcscat(DstPath, L"\\bootsect.ros"); + +// PrintTextXY(6, 16, "Install FAT32 bootcode: %S ==> %S", +// SrcPath, DstPath); + Status = InstallFat32BootCodeToFile(SrcPath, + DstPath, + SystemRootPath.Buffer); + if (!NT_SUCCESS(Status)) + { + DPRINT1("InstallFat32BootCodeToFile() failed (Status %lx)\n", Status); + } + } + else + { + wcscpy(SrcPath, SourceRootPath.Buffer); + wcscat(SrcPath, L"\\loader\\fat.bin"); + + wcscpy(DstPath, SystemRootPath.Buffer); + wcscat(DstPath, L"\\bootsect.ros"); + +// PrintTextXY(6, 16, "Install FAT bootcode: %S ==> %S", +// SrcPath, DstPath); + Status = InstallFat16BootCodeToFile(SrcPath, + DstPath, + SystemRootPath.Buffer); + if (!NT_SUCCESS(Status)) + { + DPRINT1("InstallFat16BootCodeToFile() failed (Status %lx)\n", Status); + } + } + + /* Update 'boot.ini' */ + wcscpy(DstPath, SystemRootPath.Buffer); + wcscat(DstPath, L"\\boot.ini"); + +// PrintTextXY(6, 18, "Update 'boot.ini': %S", DstPath); + Status = UpdateBootIni(DstPath, + L"C:\\bootsect.ros", + L"\"ReactOS\""); + if (!NT_SUCCESS(Status)) + { + DPRINT1("UpdateBootIni() failed (Status %lx)\n", Status); + } } else if (DoesFileExist(SystemRootPath.Buffer, L"io.sys") == TRUE || DoesFileExist(SystemRootPath.Buffer, L"msdos.sys") == TRUE) @@ -1462,33 +1551,144 @@ BootLoaderPage(PINPUT_RECORD Ir) wcscpy(DstPath, SystemRootPath.Buffer); wcscat(DstPath, L"\\freeldr.sys"); - PrintTextXY(6, 14, "Copy: %S ==> %S", SrcPath, DstPath); - - SetupCopyFile(SrcPath, DstPath); +// PrintTextXY(6, 14, "Copy: %S ==> %S", SrcPath, DstPath); + Status = SetupCopyFile(SrcPath, DstPath); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status); + } /* Create freeldr.ini */ wcscpy(DstPath, SystemRootPath.Buffer); wcscat(DstPath, L"\\freeldr.ini"); - CreateFreeLoaderIniForDos(DstPath, - DestinationPath.Buffer); + Status = CreateFreeLoaderIniForDos(DstPath, + DestinationArcPath.Buffer); + if (!NT_SUCCESS(Status)) + { + DPRINT1("CreateFreeLoaderIniForDos() failed (Status %lx)\n", Status); + } - /* Copy current bootsector to 'BOOTSECT.DOS' */ + /* Save current bootsector as 'BOOTSECT.DOS' */ + wcscpy(SrcPath, SystemRootPath.Buffer); + wcscpy(DstPath, SystemRootPath.Buffer); + wcscat(DstPath, L"\\bootsect.dos"); + +// PrintTextXY(6, 16, "Save bootsector: %S ==> %S", SrcPath, DstPath); + Status = SaveCurrentBootSector(SrcPath, + DstPath); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SaveCurrentBootSector() failed (Status %lx)\n", Status); + } + + /* Install new bootsector */ if ((ActivePartition.PartType == PARTITION_FAT32) || (ActivePartition.PartType == PARTITION_FAT32_XINT13)) { + wcscpy(SrcPath, SourceRootPath.Buffer); + wcscat(SrcPath, L"\\loader\\fat32.bin"); +// PrintTextXY(6, 18, "Install FAT32 bootcode: %S ==> %S", +// SrcPath, SystemRootPath.Buffer); + Status = InstallFat32BootCodeToDisk(SrcPath, + SystemRootPath.Buffer); + if (!NT_SUCCESS(Status)) + { + DPRINT1("InstallFat32BootCodeToDisk() failed (Status %lx)\n", Status); + } } else { + wcscpy(SrcPath, SourceRootPath.Buffer); + wcscat(SrcPath, L"\\loader\\fat.bin"); +// PrintTextXY(6, 18, "Install FAT bootcode: %S ==> %S", +// SrcPath, SystemRootPath.Buffer); + Status = InstallFat16BootCodeToDisk(SrcPath, + SystemRootPath.Buffer); + if (!NT_SUCCESS(Status)) + { + DPRINT1("InstallFat16BootCodeToDisk() failed (Status %lx)\n", Status); + } } } else { - SetTextXY(6, 12, "No or unknown boot loader found"); + /* Copy FreeLoader to the boot partition */ + wcscpy(SrcPath, SourceRootPath.Buffer); + wcscat(SrcPath, L"\\loader\\freeldr.sys"); + wcscpy(DstPath, SystemRootPath.Buffer); + wcscat(DstPath, L"\\freeldr.sys"); + +// PrintTextXY(6, 14, "Copy: %S ==> %S", SrcPath, DstPath); + DPRINT1("Copy: %S ==> %S", SrcPath, DstPath); + Status = SetupCopyFile(SrcPath, DstPath); + DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SetupCopyFile() failed (Status %lx)\n", Status); + } + + /* Create freeldr.ini */ + wcscpy(DstPath, SystemRootPath.Buffer); + wcscat(DstPath, L"\\freeldr.ini"); + +// DPRINT1("Copy: %S ==> %S", SrcPath, DstPath); + Status = CreateFreeLoaderIniForReactos(DstPath, + DestinationArcPath.Buffer); + DPRINT1("CreateFreeLoaderIniForReactos() failed (Status %lx)\n", Status); + if (!NT_SUCCESS(Status)) + { + DPRINT1("CreateFreeLoaderIniForReactos() failed (Status %lx)\n", Status); + } + + /* Save current bootsector as 'BOOTSECT.OLD' */ + wcscpy(SrcPath, SystemRootPath.Buffer); + wcscpy(DstPath, SystemRootPath.Buffer); + wcscat(DstPath, L"\\bootsect.old"); + +// PrintTextXY(6, 16, "Save bootsector: %S ==> %S", SrcPath, DstPath); + Status = SaveCurrentBootSector(SrcPath, + DstPath); + DPRINT1("SaveCurrentBootSector() failed (Status %lx)\n", Status); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SaveCurrentBootSector() failed (Status %lx)\n", Status); + } + + /* Install new bootsector */ + if ((ActivePartition.PartType == PARTITION_FAT32) || + (ActivePartition.PartType == PARTITION_FAT32_XINT13)) + { + wcscpy(SrcPath, SourceRootPath.Buffer); + wcscat(SrcPath, L"\\loader\\fat32.bin"); + +// PrintTextXY(6, 18, "Install FAT32 bootcode: %S ==> %S", +// SrcPath, SystemRootPath.Buffer); + Status = InstallFat32BootCodeToDisk(SrcPath, + SystemRootPath.Buffer); + if (!NT_SUCCESS(Status)) + { + DPRINT1("InstallFat32BootCodeToDisk() failed (Status %lx)\n", Status); + } + } + else + { + wcscpy(SrcPath, SourceRootPath.Buffer); + wcscat(SrcPath, L"\\loader\\fat.bin"); + +// PrintTextXY(6, 18, "Install FAT bootcode: %S ==> %S", +// SrcPath, SystemRootPath.Buffer); + Status = InstallFat16BootCodeToDisk(SrcPath, + SystemRootPath.Buffer); + if (!NT_SUCCESS(Status)) + { + DPRINT1("InstallFat16BootCodeToDisk() failed (Status %lx)\n", Status); + } + } } } else @@ -1597,6 +1797,7 @@ NtProcessStartup(PPEB Peb) RtlInitUnicodeString(&SourceRootPath, NULL); RtlInitUnicodeString(&InstallPath, NULL); RtlInitUnicodeString(&DestinationPath, NULL); + RtlInitUnicodeString(&DestinationArcPath, NULL); RtlInitUnicodeString(&DestinationRootPath, NULL); RtlInitUnicodeString(&SystemRootPath, NULL);