mirror of
https://github.com/reactos/reactos.git
synced 2025-02-25 01:39:30 +00:00
* Install MBR boot code if necessary.
* Install partition boot code after formatting. svn path=/trunk/; revision=5674
This commit is contained in:
parent
8fcc6f51cd
commit
a0f1b6fbfe
5 changed files with 123 additions and 132 deletions
|
@ -922,8 +922,8 @@ CHECKPOINT1;
|
|||
|
||||
|
||||
NTSTATUS
|
||||
InstallMbrCodeToDisk (PWSTR SrcPath,
|
||||
PWSTR RootPath)
|
||||
InstallMbrBootCodeToDisk (PWSTR SrcPath,
|
||||
PWSTR RootPath)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
IO_STATUS_BLOCK IoStatusBlock;
|
||||
|
@ -1030,9 +1030,9 @@ InstallMbrCodeToDisk (PWSTR SrcPath,
|
|||
}
|
||||
|
||||
/* Copy partition table from old MBR to new */
|
||||
memcpy((NewBootSector + 446),
|
||||
(OrigBootSector + 446),
|
||||
4*16 /* Length of partition table */);
|
||||
RtlCopyMemory ((NewBootSector + 446),
|
||||
(OrigBootSector + 446),
|
||||
4*16 /* Length of partition table */);
|
||||
|
||||
/* Free the original boot sector */
|
||||
RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
|
||||
|
|
|
@ -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.5 2003/08/18 17:39:26 ekohl Exp $
|
||||
/* $Id: bootsup.h,v 1.6 2003/08/19 15:54:47 ekohl Exp $
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS text-mode setup
|
||||
* FILE: subsys/system/usetup/bootsup.h
|
||||
|
@ -54,8 +54,8 @@ InstallFat32BootCodeToFile(PWSTR SrcPath,
|
|||
PWSTR RootPath);
|
||||
|
||||
NTSTATUS
|
||||
InstallMBRBootCodeToDisk(PWSTR SrcPath,
|
||||
PWSTR RootPath);
|
||||
InstallMbrBootCodeToDisk (PWSTR SrcPath,
|
||||
PWSTR RootPath);
|
||||
|
||||
NTSTATUS
|
||||
InstallFat16BootCodeToDisk(PWSTR SrcPath,
|
||||
|
|
|
@ -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: partlist.c,v 1.18 2003/08/18 17:39:26 ekohl Exp $
|
||||
/* $Id: partlist.c,v 1.19 2003/08/19 15:54:47 ekohl Exp $
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS text-mode setup
|
||||
* FILE: subsys/system/usetup/partlist.c
|
||||
|
@ -479,6 +479,11 @@ AddDiskToList (HANDLE FileHandle,
|
|||
8192);
|
||||
if (NT_SUCCESS (Status))
|
||||
{
|
||||
if (LayoutBuffer->PartitionCount == 0)
|
||||
{
|
||||
DiskEntry->NewDisk = TRUE;
|
||||
}
|
||||
|
||||
AddPartitionToList (DiskNumber,
|
||||
DiskEntry,
|
||||
LayoutBuffer);
|
||||
|
@ -1135,53 +1140,6 @@ ScrollUpPartitionList (PPARTLIST List)
|
|||
}
|
||||
|
||||
|
||||
VOID
|
||||
SetActiveBootPartition (PPARTLIST List)
|
||||
{
|
||||
PDISKENTRY DiskEntry;
|
||||
PPARTENTRY PartEntry;
|
||||
|
||||
/* Check for empty disk list */
|
||||
if (IsListEmpty (&List->DiskListHead))
|
||||
{
|
||||
List->ActiveBootDisk = NULL;
|
||||
List->ActiveBootPartition = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
DiskEntry = CONTAINING_RECORD (List->DiskListHead.Flink,
|
||||
DISKENTRY,
|
||||
ListEntry);
|
||||
|
||||
/* Check for empty partition list */
|
||||
if (IsListEmpty (&DiskEntry->PartListHead))
|
||||
{
|
||||
List->ActiveBootDisk = NULL;
|
||||
List->ActiveBootPartition = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
PartEntry = CONTAINING_RECORD (DiskEntry->PartListHead.Flink,
|
||||
PARTENTRY,
|
||||
ListEntry);
|
||||
|
||||
/* Set active boot partition 1 */
|
||||
if (PartEntry->PartInfo[0].BootIndicator == FALSE &&
|
||||
PartEntry->PartInfo[1].BootIndicator == FALSE &&
|
||||
PartEntry->PartInfo[2].BootIndicator == FALSE &&
|
||||
PartEntry->PartInfo[3].BootIndicator == FALSE)
|
||||
{
|
||||
PartEntry->PartInfo[0].BootIndicator == TRUE;
|
||||
PartEntry->PartInfo[0].RewritePartition == TRUE;
|
||||
DiskEntry->Modified = TRUE;
|
||||
}
|
||||
|
||||
/* FIXME: Might be incorrect if partitions were created by Linux FDISK */
|
||||
List->ActiveBootDisk = DiskEntry;
|
||||
List->ActiveBootPartition = PartEntry;
|
||||
}
|
||||
|
||||
|
||||
static PPARTENTRY
|
||||
GetPrevPartitionedEntry (PDISKENTRY DiskEntry,
|
||||
PPARTENTRY CurrentEntry)
|
||||
|
@ -1632,13 +1590,71 @@ DeleteCurrentPartition (PPARTLIST List)
|
|||
}
|
||||
|
||||
|
||||
VOID
|
||||
CheckActiveBootPartition (PPARTLIST List)
|
||||
{
|
||||
PDISKENTRY DiskEntry;
|
||||
PPARTENTRY PartEntry;
|
||||
|
||||
/* Check for empty disk list */
|
||||
if (IsListEmpty (&List->DiskListHead))
|
||||
{
|
||||
List->ActiveBootDisk = NULL;
|
||||
List->ActiveBootPartition = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (List->ActiveBootDisk != NULL &&
|
||||
List->ActiveBootPartition != NULL)
|
||||
{
|
||||
/* We already have an active boot partition */
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
DiskEntry = CONTAINING_RECORD (List->DiskListHead.Flink,
|
||||
DISKENTRY,
|
||||
ListEntry);
|
||||
|
||||
/* Check for empty partition list */
|
||||
if (IsListEmpty (&DiskEntry->PartListHead))
|
||||
{
|
||||
List->ActiveBootDisk = NULL;
|
||||
List->ActiveBootPartition = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
PartEntry = CONTAINING_RECORD (DiskEntry->PartListHead.Flink,
|
||||
PARTENTRY,
|
||||
ListEntry);
|
||||
|
||||
/* Set active boot partition */
|
||||
if ((DiskEntry->NewDisk == TRUE) ||
|
||||
(PartEntry->PartInfo[0].BootIndicator == FALSE &&
|
||||
PartEntry->PartInfo[1].BootIndicator == FALSE &&
|
||||
PartEntry->PartInfo[2].BootIndicator == FALSE &&
|
||||
PartEntry->PartInfo[3].BootIndicator == FALSE))
|
||||
{
|
||||
PartEntry->PartInfo[0].BootIndicator = TRUE;
|
||||
PartEntry->PartInfo[0].RewritePartition = TRUE;
|
||||
DiskEntry->Modified = TRUE;
|
||||
}
|
||||
|
||||
/* FIXME: Might be incorrect if partitions were created by Linux FDISK */
|
||||
List->ActiveBootDisk = DiskEntry;
|
||||
List->ActiveBootPartition = PartEntry;
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN
|
||||
WritePartitionsToDisk (PPARTLIST List)
|
||||
{
|
||||
PDRIVE_LAYOUT_INFORMATION DriveLayout;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
IO_STATUS_BLOCK Iosb;
|
||||
WCHAR Buffer[MAX_PATH];
|
||||
WCHAR SrcPath[MAX_PATH];
|
||||
WCHAR DstPath[MAX_PATH];
|
||||
UNICODE_STRING Name;
|
||||
HANDLE FileHandle;
|
||||
PDISKENTRY DiskEntry;
|
||||
|
@ -1716,11 +1732,11 @@ WritePartitionsToDisk (PPARTLIST List)
|
|||
Entry2 = Entry2->Flink;
|
||||
}
|
||||
|
||||
swprintf (Buffer,
|
||||
swprintf (DstPath,
|
||||
L"\\Device\\Harddisk%d\\Partition0",
|
||||
DiskEntry->DiskNumber);
|
||||
RtlInitUnicodeString (&Name,
|
||||
Buffer);
|
||||
DstPath);
|
||||
InitializeObjectAttributes (&ObjectAttributes,
|
||||
&Name,
|
||||
0,
|
||||
|
@ -1728,7 +1744,7 @@ WritePartitionsToDisk (PPARTLIST List)
|
|||
NULL);
|
||||
|
||||
Status = NtOpenFile (&FileHandle,
|
||||
FILE_GENERIC_WRITE,
|
||||
FILE_ALL_ACCESS,
|
||||
&ObjectAttributes,
|
||||
&Iosb,
|
||||
0,
|
||||
|
@ -1760,9 +1776,29 @@ WritePartitionsToDisk (PPARTLIST List)
|
|||
0,
|
||||
DriveLayout);
|
||||
|
||||
/* FIXME: Install MBR code */
|
||||
|
||||
NtClose (FileHandle);
|
||||
|
||||
/* Install MBR code if the disk is new */
|
||||
if (DiskEntry->NewDisk == TRUE)
|
||||
{
|
||||
wcscpy (SrcPath, SourceRootPath.Buffer);
|
||||
wcscat (SrcPath, L"\\loader\\dosmbr.bin");
|
||||
|
||||
DPRINT1 ("Install MBR bootcode: %S ==> %S\n",
|
||||
SrcPath, DstPath);
|
||||
|
||||
/* Install MBR bootcode */
|
||||
Status = InstallMbrBootCodeToDisk (SrcPath,
|
||||
DstPath);
|
||||
if (!NT_SUCCESS (Status))
|
||||
{
|
||||
DPRINT1 ("InstallMbrBootCodeToDisk() failed (Status %lx)\n",
|
||||
Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DiskEntry->NewDisk = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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: partlist.h,v 1.18 2003/08/18 17:39:26 ekohl Exp $
|
||||
/* $Id: partlist.h,v 1.19 2003/08/19 15:54:47 ekohl Exp $
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS text-mode setup
|
||||
* FILE: subsys/system/usetup/partlist.h
|
||||
|
@ -81,6 +81,8 @@ typedef struct _DISKENTRY
|
|||
/* Has the partition list been modified? */
|
||||
BOOLEAN Modified;
|
||||
|
||||
BOOLEAN NewDisk;
|
||||
|
||||
UNICODE_STRING DriverName;
|
||||
|
||||
LIST_ENTRY PartListHead;
|
||||
|
@ -130,9 +132,6 @@ ScrollDownPartitionList (PPARTLIST List);
|
|||
VOID
|
||||
ScrollUpPartitionList (PPARTLIST List);
|
||||
|
||||
VOID
|
||||
SetActiveBootPartition (PPARTLIST List);
|
||||
|
||||
VOID
|
||||
CreateNewPartition (PPARTLIST List,
|
||||
ULONGLONG PartitionSize,
|
||||
|
@ -141,6 +140,9 @@ CreateNewPartition (PPARTLIST List,
|
|||
VOID
|
||||
DeleteCurrentPartition (PPARTLIST List);
|
||||
|
||||
VOID
|
||||
CheckActiveBootPartition (PPARTLIST List);
|
||||
|
||||
BOOLEAN
|
||||
WritePartitionsToDisk (PPARTLIST List);
|
||||
|
||||
|
|
|
@ -1580,6 +1580,8 @@ FormatPartitionPage (PINPUT_RECORD Ir)
|
|||
return QUIT_PAGE;
|
||||
}
|
||||
|
||||
CheckActiveBootPartition (PartitionList);
|
||||
|
||||
//#ifndef NDEBUG
|
||||
PrintTextXY (6, 12,
|
||||
"Disk: %I64u Cylinder: %I64u Track: %I64u",
|
||||
|
@ -1600,9 +1602,10 @@ FormatPartitionPage (PINPUT_RECORD Ir)
|
|||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
PrintTextXY (6, Line,
|
||||
"%u: %u %12I64u %12I64u %u %c",
|
||||
"%2u: %2u %c %12I64u %12I64u %2u %c",
|
||||
i,
|
||||
PartEntry->PartInfo[i].PartitionNumber,
|
||||
PartEntry->PartInfo[i].BootIndicator ? 'A' : '-',
|
||||
PartEntry->PartInfo[i].StartingOffset.QuadPart,
|
||||
PartEntry->PartInfo[i].PartitionLength.QuadPart,
|
||||
PartEntry->PartInfo[i].PartitionType,
|
||||
|
@ -1618,8 +1621,6 @@ FormatPartitionPage (PINPUT_RECORD Ir)
|
|||
}
|
||||
//#endif
|
||||
|
||||
SetActiveBootPartition (PartitionList);
|
||||
|
||||
if (WritePartitionsToDisk (PartitionList) == FALSE)
|
||||
{
|
||||
DPRINT ("WritePartitionsToDisk() failed\n");
|
||||
|
@ -1671,6 +1672,21 @@ FormatPartitionPage (PINPUT_RECORD Ir)
|
|||
/* FIXME: show an error dialog */
|
||||
return QUIT_PAGE;
|
||||
}
|
||||
|
||||
/* FIXME: Install boot code. This is a hack! */
|
||||
wcscpy (PathBuffer, SourceRootPath.Buffer);
|
||||
wcscat (PathBuffer, L"\\loader\\fat32.bin");
|
||||
|
||||
DPRINT1 ("Install FAT32 bootcode: %S ==> %S\n", PathBuffer,
|
||||
DestinationRootPath.Buffer);
|
||||
Status = InstallFat32BootCodeToDisk (PathBuffer,
|
||||
DestinationRootPath.Buffer);
|
||||
if (!NT_SUCCESS (Status))
|
||||
{
|
||||
DPRINT1 ("InstallFat32BootCodeToDisk() failed with status 0x%.08x\n", Status);
|
||||
/* FIXME: show an error dialog */
|
||||
return QUIT_PAGE;
|
||||
}
|
||||
break;
|
||||
|
||||
case FsKeep:
|
||||
|
@ -2290,74 +2306,11 @@ BootLoaderPage(PINPUT_RECORD Ir)
|
|||
PINICACHE IniCache;
|
||||
PINICACHESECTION IniSection;
|
||||
NTSTATUS Status;
|
||||
BOOLEAN InstallMBR = FALSE;
|
||||
|
||||
SetTextXY(6, 8, "Installing the boot loader");
|
||||
|
||||
SetStatusText(" Please wait...");
|
||||
|
||||
#if 0
|
||||
if (ActivePartitionValid == FALSE)
|
||||
{
|
||||
/* Mark the chosen partition as active since there is no active
|
||||
partition now */
|
||||
|
||||
if (!MarkPartitionActive(PartData.DiskNumber,
|
||||
PartData.PartNumber, &ActivePartition))
|
||||
{
|
||||
PopupError("Setup could not mark the system partiton active\n",
|
||||
"ENTER = Reboot computer");
|
||||
|
||||
while(TRUE)
|
||||
{
|
||||
ConInKey(Ir);
|
||||
|
||||
if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
|
||||
{
|
||||
return(QUIT_PAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
InstallMBR = TRUE;
|
||||
}
|
||||
|
||||
if (InstallMBR)
|
||||
{
|
||||
WCHAR PathBuffer[MAX_PATH];
|
||||
UNICODE_STRING SystemRootMBRPath;
|
||||
|
||||
RtlFreeUnicodeString(&SystemRootMBRPath);
|
||||
swprintf(PathBuffer,
|
||||
L"\\Device\\Harddisk%lu\\Partition0",
|
||||
PartData.DiskNumber);
|
||||
RtlCreateUnicodeString(&SystemRootMBRPath,
|
||||
PathBuffer);
|
||||
|
||||
/* Install MBR bootcode */
|
||||
wcscpy(SrcPath, SourceRootPath.Buffer);
|
||||
wcscat(SrcPath, L"\\loader\\dosmbr.bin");
|
||||
|
||||
DPRINT1("Install MBR bootcode: %S ==> %S\n", SrcPath, SystemRootMBRPath.Buffer);
|
||||
Status = InstallMBRBootCodeToDisk(SrcPath,
|
||||
SystemRootMBRPath.Buffer);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("InstallMBRBootCodeToDisk() failed (Status %lx)\n", Status);
|
||||
PopupError("Setup failed to install the MBR bootcode.",
|
||||
"ENTER = Reboot computer");
|
||||
|
||||
while(TRUE)
|
||||
{
|
||||
ConInKey(Ir);
|
||||
|
||||
if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
|
||||
{
|
||||
return(QUIT_PAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_ENTRY_UNUSED)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue