Author: tkreuzer
Date: Mon Sep 6 01:46:06 2010
New Revision: 48706
URL: http://svn.reactos.org/svn/reactos?rev=48706&view=rev
Log:
[USETUP]
The VBR (volume boot sector) contains a structure called BPB (bios parameter block) that describes the disk and the partition. The HiddenSectors member contains the number of the first sector of the partition. This is used by the VBR code to load the secondary sector containing additional boot code that is located at secor 14 relative to the partition start. Previously we were copying the BPB (plus additionally the OemName, which makes no sense) from the old VBR. Now Linux is a bit lame and doesn't put the correct value into the HiddenSectors field. Instead it sets it to the number of sectors per track which seems to be the default value. When now the linux partition manager decides to do a non standard partitioning, aligning the partition to 0x800, then the VBR fails to load it's 2nd sector. Fix this by correcting the value in the BPB with the value from the partition info.
See issue #2733 for more details.
Modified:
trunk/reactos/base/setup/usetup/bootsup.c
trunk/reactos/base/setup/usetup/interface/usetup.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] Mon Sep 6 01:46:06 2010
@@ -31,6 +31,75 @@
#define SECTORSIZE 512
+#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
+
+} 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
+
+} FAT32_BOOTSECTOR, *PFAT32_BOOTSECTOR;
+#include <poppack.h>
+
+extern PPARTLIST PartitionList;
+
/* FUNCTIONS ****************************************************************/
@@ -1094,53 +1163,53 @@
InstallMbrBootCodeToDisk (PWSTR SrcPath,
PWSTR RootPath)
{
- OBJECT_ATTRIBUTES ObjectAttributes;
- IO_STATUS_BLOCK IoStatusBlock;
- UNICODE_STRING Name;
- HANDLE FileHandle;
- NTSTATUS Status;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ IO_STATUS_BLOCK IoStatusBlock;
+ UNICODE_STRING Name;
+ HANDLE FileHandle;
+ NTSTATUS Status;
PPARTITION_SECTOR OrigBootSector;
PPARTITION_SECTOR NewBootSector;
- /* Allocate buffer for original bootsector */
+ /* Allocate buffer for original bootsector */
OrigBootSector = (PPARTITION_SECTOR)RtlAllocateHeap(ProcessHeap,
0,
sizeof(PARTITION_SECTOR));
if (OrigBootSector == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
- /* Read current boot sector into buffer */
+ /* 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,
+ 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);
+ SECTORSIZE,
+ NULL,
+ NULL);
+ NtClose(FileHandle);
if (!NT_SUCCESS(Status))
{
RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
@@ -1256,11 +1325,12 @@
UNICODE_STRING Name;
HANDLE FileHandle;
NTSTATUS Status;
- PUCHAR OrigBootSector;
- PUCHAR NewBootSector;
+ PFAT_BOOTSECTOR OrigBootSector;
+ PFAT_BOOTSECTOR NewBootSector;
+ PARTITION_INFORMATION *PartInfo;
/* Allocate buffer for original bootsector */
- OrigBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap,
+ OrigBootSector = RtlAllocateHeap(ProcessHeap,
0,
SECTORSIZE);
if (OrigBootSector == NULL)
@@ -1306,7 +1376,7 @@
/* Allocate buffer for new bootsector */
- NewBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap,
+ NewBootSector = RtlAllocateHeap(ProcessHeap,
0,
SECTORSIZE);
if (NewBootSector == NULL)
@@ -1356,9 +1426,12 @@
}
/* Adjust bootsector (copy a part of the FAT16 BPB) */
- memcpy((NewBootSector + 3),
- (OrigBootSector + 3),
- 59); /* FAT16 BPB length*/
+ memcpy(&NewBootSector->BytesPerSector,
+ &OrigBootSector->BytesPerSector,
+ 51); /* FAT16 BPB length */
+
+ PartInfo = &PartitionList->CurrentPartition->PartInfo[PartitionList->CurrentPartitionNumber];
+ NewBootSector->HiddenSectors = PartInfo->HiddenSectors;
/* Free the original boot sector */
RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
@@ -1416,13 +1489,14 @@
UNICODE_STRING Name;
HANDLE FileHandle;
NTSTATUS Status;
- PUCHAR OrigBootSector;
- PUCHAR NewBootSector;
+ PFAT32_BOOTSECTOR OrigBootSector;
+ PFAT32_BOOTSECTOR NewBootSector;
LARGE_INTEGER FileOffset;
USHORT BackupBootSector;
+ PARTITION_INFORMATION *PartInfo;
/* Allocate buffer for original bootsector */
- OrigBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap,
+ OrigBootSector = RtlAllocateHeap(ProcessHeap,
0,
SECTORSIZE);
if (OrigBootSector == NULL)
@@ -1468,7 +1542,7 @@
/* Allocate buffer for new bootsector (2 sectors) */
- NewBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap,
+ NewBootSector = RtlAllocateHeap(ProcessHeap,
0,
2 * SECTORSIZE);
if (NewBootSector == NULL)
@@ -1518,12 +1592,15 @@
}
/* Adjust bootsector (copy a part of the FAT32 BPB) */
- memcpy((NewBootSector + 3),
- (OrigBootSector + 3),
- 87); /* FAT32 BPB length */
+ memcpy(&NewBootSector->BytesPerSector,
+ &OrigBootSector->BytesPerSector,
+ 79); /* FAT32 BPB length */
+
+ PartInfo = &PartitionList->CurrentPartition->PartInfo[PartitionList->CurrentPartitionNumber];
+ NewBootSector->HiddenSectors = PartInfo->HiddenSectors;
/* Get the location of the backup boot sector */
- BackupBootSector = (OrigBootSector[0x33] << 8) + OrigBootSector[0x32];
+ BackupBootSector = OrigBootSector->BackupBootSector;
/* Free the original boot sector */
RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
@@ -1599,7 +1676,7 @@
NULL,
NULL,
&IoStatusBlock,
- (NewBootSector + SECTORSIZE),
+ ((PUCHAR)NewBootSector + SECTORSIZE),
SECTORSIZE,
&FileOffset,
NULL);
Modified: trunk/reactos/base/setup/usetup/interface/usetup.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/setup/usetup/interfac…
==============================================================================
--- trunk/reactos/base/setup/usetup/interface/usetup.c [iso-8859-1] (original)
+++ trunk/reactos/base/setup/usetup/interface/usetup.c [iso-8859-1] Mon Sep 6 01:46:06 2010
@@ -51,10 +51,9 @@
WCHAR DefaultKBLayout[20];
BOOLEAN RepairUpdateFlag = FALSE;
HANDLE hPnpThread = INVALID_HANDLE_VALUE;
+PPARTLIST PartitionList = NULL;
/* LOCALS *******************************************************************/
-
-static PPARTLIST PartitionList = NULL;
static PFILE_SYSTEM_LIST FileSystemList = NULL;
Author: akhaldi
Date: Sun Sep 5 16:31:06 2010
New Revision: 48702
URL: http://svn.reactos.org/svn/reactos?rev=48702&view=rev
Log:
[FREELDR]
- Update fathelp.S to reflect Timo's recent changes in trunk.
Modified:
branches/cmake-bringup/boot/freeldr/freeldr/arch/amd64/fathelp.S
branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.S
Modified: branches/cmake-bringup/boot/freeldr/freeldr/arch/amd64/fathelp.S
URL: http://svn.reactos.org/svn/reactos/branches/cmake-bringup/boot/freeldr/free…
==============================================================================
--- branches/cmake-bringup/boot/freeldr/freeldr/arch/amd64/fathelp.S [iso-8859-1] (original)
+++ branches/cmake-bringup/boot/freeldr/freeldr/arch/amd64/fathelp.S [iso-8859-1] Sun Sep 5 16:31:06 2010
@@ -4,9 +4,12 @@
.intel_syntax noprefix
+//org 8000h
+
.text
.code16
+
#define BootSectorStackTop 0x7bf2
#define DataAreaStartHigh 0x2
@@ -38,6 +41,8 @@
#define VolumeLabel 43
#define FileSystem 54
+#define BootPartition 0x7dfd
+
// This code will be stored in the first 512 bytes
// of freeldr.sys. The first 3 bytes will be a jmp
@@ -46,7 +51,6 @@
//
// This code is loaded at 0000:8000 so we have to
// encode a jmp instruction to jump to 0000:8200
-//.org 0x8000
.global _mainCRTStartup // For Mingw32 builds where the linker looks for this symbol
_mainCRTStartup:
@@ -119,14 +123,14 @@
jmp LoadFile // Load the next cluster (if any)
LoadFile_Done:
- mov dl, [bp+BootDrive] // Load the boot drive into DL
- mov dh, BootPartition // Load the boot partition into DH
- push word ptr 0x0000
- push word ptr 0x8000 // We will do a far return to 0000:8000h
-
-// retf // Transfer control to ROSLDR
- .byte 0xcb // == retf
-
+ mov dl,BYTE PTR [bp+BootDrive] // Load the boot drive into DL
+ mov dh,[BootPartition] // Load the boot partition into DH
+
+ push 0 // push segment (0x0000)
+ mov bx, [0x8000 + 0xA8] // load the RVA of the EntryPoint into eax
+ add bx, 0x8000 // RVA -> VA and skip 3 bytes (jump to fathelper code)
+ push bx // push offset
+ retf // Transfer control to FreeLoader
// Reads the entire FAT into memory at 7000:0000
ReadFatIntoMemory:
@@ -225,15 +229,7 @@
-msgLoading:
- .ascii "Loading FreeLoader..."
- .byte 0x0d,0x0a,0
-
-// times 510-($-$$) db 0 // Pad to 510 bytes
-.org 0x1fe
- .word 0x0aa55 // BootSector signature
-
-
-// pseudo adresses
-//.org 0x7dfd
-BootPartition:
+msgLoading: .asciz "Loading FreeLoader...\r\n"
+
+ .org 0x1fe // Pad to 510 bytes
+ .word 0x0aa55 // BootSector signature
Modified: branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.S
URL: http://svn.reactos.org/svn/reactos/branches/cmake-bringup/boot/freeldr/free…
==============================================================================
--- branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.S [iso-8859-1] (original)
+++ branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.S [iso-8859-1] Sun Sep 5 16:31:06 2010
@@ -4,9 +4,12 @@
.intel_syntax noprefix
+//org 8000h
+
.text
.code16
+
#define BootSectorStackTop 0x7bf2
#define DataAreaStartHigh 0x2
@@ -38,6 +41,8 @@
#define VolumeLabel 43
#define FileSystem 54
+#define BootPartition 0x7dfd
+
// This code will be stored in the first 512 bytes
// of freeldr.sys. The first 3 bytes will be a jmp
@@ -46,7 +51,6 @@
//
// This code is loaded at 0000:8000 so we have to
// encode a jmp instruction to jump to 0000:8200
-//.org 0x8000
.global _mainCRTStartup // For Mingw32 builds where the linker looks for this symbol
_mainCRTStartup:
@@ -119,14 +123,14 @@
jmp LoadFile // Load the next cluster (if any)
LoadFile_Done:
- mov dl, [bp+BootDrive] // Load the boot drive into DL
- mov dh, BootPartition // Load the boot partition into DH
- push word ptr 0x0000
- push word ptr 0x8000 // We will do a far return to 0000:8000h
-
-// retf // Transfer control to ROSLDR
- .byte 0xcb // == retf
-
+ mov dl,BYTE PTR [bp+BootDrive] // Load the boot drive into DL
+ mov dh,[BootPartition] // Load the boot partition into DH
+
+ push 0 // push segment (0x0000)
+ mov bx, [0x8000 + 0xA8] // load the RVA of the EntryPoint into eax
+ add bx, 0x8000 // RVA -> VA and skip 3 bytes (jump to fathelper code)
+ push bx // push offset
+ retf // Transfer control to FreeLoader
// Reads the entire FAT into memory at 7000:0000
ReadFatIntoMemory:
@@ -225,15 +229,7 @@
-msgLoading:
- .ascii "Loading FreeLoader..."
- .byte 0x0d,0x0a,0
-
-// times 510-($-$$) db 0 // Pad to 510 bytes
-.org 0x1fe
- .word 0x0aa55 // BootSector signature
-
-
-// pseudo adresses
-//.org 0x7dfd
-BootPartition:
+msgLoading: .asciz "Loading FreeLoader...\r\n"
+
+ .org 0x1fe // Pad to 510 bytes
+ .word 0x0aa55 // BootSector signature
Author: tkreuzer
Date: Sun Sep 5 16:03:08 2010
New Revision: 48701
URL: http://svn.reactos.org/svn/reactos?rev=48701&view=rev
Log:
Update the GAS compatible fathelp.S file to reflect the latest changes to the original file (freeldr PE conversion). This version is tested and works.
Modified:
trunk/reactos/boot/freeldr/freeldr/arch/amd64/fathelp.S
Modified: trunk/reactos/boot/freeldr/freeldr/arch/amd64/fathelp.S
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/amd64/fathelp.S [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/amd64/fathelp.S [iso-8859-1] Sun Sep 5 16:03:08 2010
@@ -4,9 +4,12 @@
.intel_syntax noprefix
+//org 8000h
+
.text
.code16
+
#define BootSectorStackTop 0x7bf2
#define DataAreaStartHigh 0x2
@@ -38,6 +41,8 @@
#define VolumeLabel 43
#define FileSystem 54
+#define BootPartition 0x7dfd
+
// This code will be stored in the first 512 bytes
// of freeldr.sys. The first 3 bytes will be a jmp
@@ -46,7 +51,6 @@
//
// This code is loaded at 0000:8000 so we have to
// encode a jmp instruction to jump to 0000:8200
-//.org 0x8000
.global _mainCRTStartup // For Mingw32 builds where the linker looks for this symbol
_mainCRTStartup:
@@ -119,14 +123,14 @@
jmp LoadFile // Load the next cluster (if any)
LoadFile_Done:
- mov dl, [bp+BootDrive] // Load the boot drive into DL
- mov dh, BootPartition // Load the boot partition into DH
- push word ptr 0x0000
- push word ptr 0x8000 // We will do a far return to 0000:8000h
-
-// retf // Transfer control to ROSLDR
- .byte 0xcb // == retf
-
+ mov dl,BYTE PTR [bp+BootDrive] // Load the boot drive into DL
+ mov dh,[BootPartition] // Load the boot partition into DH
+
+ push 0 // push segment (0x0000)
+ mov bx, [0x8000 + 0xA8] // load the RVA of the EntryPoint into eax
+ add bx, 0x8000 // RVA -> VA and skip 3 bytes (jump to fathelper code)
+ push bx // push offset
+ retf // Transfer control to FreeLoader
// Reads the entire FAT into memory at 7000:0000
ReadFatIntoMemory:
@@ -225,15 +229,7 @@
-msgLoading:
- .ascii "Loading FreeLoader..."
- .byte 0x0d,0x0a,0
-
-// times 510-($-$$) db 0 // Pad to 510 bytes
-.org 0x1fe
- .word 0x0aa55 // BootSector signature
-
-
-// pseudo adresses
-//.org 0x7dfd
-BootPartition:
+msgLoading: .asciz "Loading FreeLoader...\r\n"
+
+ .org 0x1fe // Pad to 510 bytes
+ .word 0x0aa55 // BootSector signature