Author: cgutman
Date: Sat Oct 29 15:10:11 2011
New Revision: 54269
URL:
http://svn.reactos.org/svn/reactos?rev=54269&view=rev
Log:
[USETUP]
- Use a separate function, InstallFat12BootCodeToFloppy(), to install the floppy boot
code
- Format the floppy to FAT12 before writing to it
- Booting FreeLoader from floppy works again (bug #6495)
Modified:
trunk/reactos/base/setup/usetup/bootsup.c
Modified: trunk/reactos/base/setup/usetup/bootsup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/setup/usetup/bootsup.…
==============================================================================
--- trunk/reactos/base/setup/usetup/bootsup.c [iso-8859-1] (original)
+++ trunk/reactos/base/setup/usetup/bootsup.c [iso-8859-1] Sat Oct 29 15:10:11 2011
@@ -1259,6 +1259,161 @@
return Status;
}
+NTSTATUS
+InstallFat12BootCodeToFloppy(PWSTR SrcPath,
+ PWSTR RootPath)
+{
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ IO_STATUS_BLOCK IoStatusBlock;
+ UNICODE_STRING Name;
+ HANDLE FileHandle;
+ NTSTATUS Status;
+ PFAT_BOOTSECTOR OrigBootSector;
+ PFAT_BOOTSECTOR NewBootSector;
+
+ /* Allocate buffer for original bootsector */
+ OrigBootSector = 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,
+ GENERIC_READ,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ 0,
+ FILE_SYNCHRONOUS_IO_NONALERT);
+ if (!NT_SUCCESS(Status))
+ {
+ RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+ return Status;
+ }
+
+ Status = NtReadFile(FileHandle,
+ NULL,
+ NULL,
+ NULL,
+ &IoStatusBlock,
+ OrigBootSector,
+ SECTORSIZE,
+ NULL,
+ NULL);
+ NtClose(FileHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+ return Status;
+ }
+
+
+ /* Allocate buffer for new bootsector */
+ NewBootSector = RtlAllocateHeap(ProcessHeap,
+ 0,
+ SECTORSIZE);
+ if (NewBootSector == NULL)
+ {
+ 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,
+ GENERIC_READ,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ 0,
+ FILE_SYNCHRONOUS_IO_NONALERT);
+ if (!NT_SUCCESS(Status))
+ {
+ 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))
+ {
+ RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+ RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+ return Status;
+ }
+
+ /* Adjust bootsector (copy a part of the FAT16 BPB) */
+ memcpy(&NewBootSector->OemName,
+ &OrigBootSector->OemName,
+ FIELD_OFFSET(FAT_BOOTSECTOR, BootCodeAndData) -
+ FIELD_OFFSET(FAT_BOOTSECTOR, OemName));
+
+ /* Free the original boot sector */
+ RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+
+ /* Write new bootsector to RootPath */
+ RtlInitUnicodeString(&Name, RootPath);
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &Name,
+ 0,
+ NULL,
+ NULL);
+
+ Status = NtOpenFile(&FileHandle,
+ GENERIC_WRITE,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ 0,
+ FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
+ 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
InstallFat16BootCodeToDisk(
@@ -2198,9 +2353,23 @@
PUNICODE_STRING DestinationArcPath)
{
#ifdef __REACTOS__
+ UNICODE_STRING FloppyDevice = RTL_CONSTANT_STRING(L"\\Device\\Floppy0");
WCHAR SrcPath[MAX_PATH];
WCHAR DstPath[MAX_PATH];
NTSTATUS Status;
+
+ /* Format the floppy first */
+ Status = VfatFormat(&FloppyDevice,
+ FMIFS_FLOPPY,
+ NULL,
+ TRUE,
+ 0,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("VfatFormat() failed (Status %lx)\n", Status);
+ return Status;
+ }
/* Copy FreeLoader to the boot partition */
wcscpy(SrcPath, SourceRootPath->Buffer);
@@ -2234,7 +2403,7 @@
wcscpy(DstPath, L"\\Device\\Floppy0");
DPRINT("Install FAT bootcode: %S ==> %S\n", SrcPath, DstPath);
- Status = InstallFat16BootCodeToDisk(SrcPath, DstPath);
+ Status = InstallFat12BootCodeToFloppy(SrcPath, DstPath);
if (!NT_SUCCESS(Status))
{
DPRINT1("InstallFat16BootCodeToDisk() failed (Status %lx)\n", Status);