* Write modified partition sectors to disk.

* Enable partition formatting code.

svn path=/trunk/; revision=5653
This commit is contained in:
Eric Kohl 2003-08-18 17:39:26 +00:00
parent c5cce225e2
commit c01dbcf16b
6 changed files with 234 additions and 269 deletions

View file

@ -922,7 +922,7 @@ CHECKPOINT1;
NTSTATUS
InstallMBRBootCodeToDisk(PWSTR SrcPath,
InstallMbrCodeToDisk (PWSTR SrcPath,
PWSTR RootPath)
{
OBJECT_ATTRIBUTES ObjectAttributes;
@ -1030,7 +1030,9 @@ InstallMBRBootCodeToDisk(PWSTR SrcPath,
}
/* Copy partition table from old MBR to new */
memcpy((NewBootSector + 446), (OrigBootSector + 446), 4*16 /* Length of partition table */);
memcpy((NewBootSector + 446),
(OrigBootSector + 446),
4*16 /* Length of partition table */);
/* Free the original boot sector */
RtlFreeHeap(ProcessHeap, 0, OrigBootSector);

View file

@ -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.4 2003/04/05 15:36:34 chorns Exp $
/* $Id: bootsup.h,v 1.5 2003/08/18 17:39:26 ekohl Exp $
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup
* FILE: subsys/system/usetup/bootsup.h

View file

@ -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: format.c,v 1.1 2003/04/28 19:44:13 chorns Exp $
/* $Id: format.c,v 1.2 2003/08/18 17:39:26 ekohl Exp $
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup
* FILE: subsys/system/usetup/format.c
@ -47,7 +47,7 @@ FormatPartition(PUNICODE_STRING DriveRoot)
TRUE, // QuickFormat
0, // ClusterSize
NULL); // Callback
DPRINT("VfatFormat() status 0x%.08x\n", Status);
DPRINT1("VfatFormat() status 0x%.08x\n", Status);
VfatCleanup();

View file

@ -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.17 2003/08/12 15:56:21 ekohl Exp $
/* $Id: partlist.c,v 1.18 2003/08/18 17:39:26 ekohl Exp $
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup
* FILE: subsys/system/usetup/partlist.c
@ -47,11 +47,6 @@ GetDriverName (PDISKENTRY DiskEntry)
WCHAR KeyName[32];
NTSTATUS Status;
#if 0
RtlCreateUnicodeString (&DiskEntry->DriverName,
L"atapi");
#endif
RtlInitUnicodeString (&DiskEntry->DriverName,
NULL);
@ -521,10 +516,6 @@ CreatePartitionList (SHORT Left,
if (List == NULL)
return NULL;
// List->Left = 0;
// List->Top = 0;
// List->Right = 0;
// List->Bottom = 0;
List->Left = Left;
List->Top = Top;
List->Right = Right;
@ -621,26 +612,6 @@ DestroyPartitionList (PPARTLIST List)
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry;
PLIST_ENTRY Entry;
#if 0
COORD coPos;
USHORT Width;
/* clear occupied screen area */
coPos.X = List->Left;
Width = List->Right - List->Left + 1;
for (coPos.Y = List->Top; coPos.Y <= List->Bottom; coPos.Y++)
{
FillConsoleOutputAttribute(0x17,
Width,
coPos,
&i);
FillConsoleOutputCharacter(' ',
Width,
coPos,
&i);
}
#endif
/* Release disk and partition info */
while (!IsListEmpty (&List->DiskListHead))
@ -755,7 +726,6 @@ PrintPartitionData (PPARTLIST List,
}
else
{
/* Determine partition type */
PartType = NULL;
if (PartEntry->New == TRUE)
@ -1166,45 +1136,49 @@ ScrollUpPartitionList (PPARTLIST List)
VOID
GetActiveBootPartition (PPARTLIST List,
PDISKENTRY *DiskEntry,
PPARTENTRY *PartEntry)
SetActiveBootPartition (PPARTLIST List)
{
PDISKENTRY LocalDiskEntry;
PPARTENTRY LocalPartEntry;
PLIST_ENTRY Entry;
ULONG i;
*DiskEntry = NULL;
*PartEntry = NULL;
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry;
/* Check for empty disk list */
if (IsListEmpty (&List->DiskListHead))
{
List->ActiveBootDisk = NULL;
List->ActiveBootPartition = NULL;
return;
}
/* Get first disk entry from the disk list */
Entry = List->DiskListHead.Flink;
LocalDiskEntry = CONTAINING_RECORD (Entry, DISKENTRY, ListEntry);
DiskEntry = CONTAINING_RECORD (List->DiskListHead.Flink,
DISKENTRY,
ListEntry);
/* Check for empty partition list */
if (IsListEmpty (&LocalDiskEntry->PartListHead))
return;
/* Search for active partition */
Entry = LocalDiskEntry->PartListHead.Flink;
while (Entry != &LocalDiskEntry->PartListHead)
if (IsListEmpty (&DiskEntry->PartListHead))
{
LocalPartEntry = CONTAINING_RECORD (Entry, PARTENTRY, ListEntry);
if (LocalPartEntry->PartInfo[0].BootIndicator)
{
*DiskEntry = LocalDiskEntry;
*PartEntry = LocalPartEntry;
List->ActiveBootDisk = NULL;
List->ActiveBootPartition = NULL;
return;
}
Entry = Entry->Flink;
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;
}
@ -1661,7 +1635,6 @@ DeleteCurrentPartition (PPARTLIST List)
BOOLEAN
WritePartitionsToDisk (PPARTLIST List)
{
#if 0
PDRIVE_LAYOUT_INFORMATION DriveLayout;
OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK Iosb;
@ -1776,22 +1749,25 @@ WritePartitionsToDisk (PPARTLIST List)
DriveLayoutSize,
NULL,
0);
NtClose (FileHandle);
if (!NT_SUCCESS (Status))
{
DPRINT1 ("NtDeviceIoControlFile() failed (Status %lx)\n", Status);
NtClose (FileHandle);
return FALSE;
}
RtlFreeHeap (ProcessHeap,
0,
DriveLayout);
/* FIXME: Install MBR code */
NtClose (FileHandle);
}
}
Entry1 = Entry1->Flink;
}
#endif
return TRUE;
}

View file

@ -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.17 2003/08/12 15:56:21 ekohl Exp $
/* $Id: partlist.h,v 1.18 2003/08/18 17:39:26 ekohl Exp $
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup
* FILE: subsys/system/usetup/partlist.h
@ -103,11 +103,8 @@ typedef struct _PARTLIST
PDISKENTRY CurrentDisk;
PPARTENTRY CurrentPartition;
#if 0
/* Not used yet! */
PDISKENTRY ActiveBootDisk;
PPARTENTRY ActiveBootPartition;
#endif
LIST_ENTRY DiskListHead;
@ -134,9 +131,7 @@ VOID
ScrollUpPartitionList (PPARTLIST List);
VOID
GetActiveBootPartition(PPARTLIST List,
PDISKENTRY *DiskEntry,
PPARTENTRY *PartEntry);
SetActiveBootPartition (PPARTLIST List);
VOID
CreateNewPartition (PPARTLIST List,

View file

@ -94,9 +94,6 @@ UNICODE_STRING SourceRootPath;
static PPARTLIST PartitionList = NULL;
static PDISKENTRY ActiveBootDisk = NULL;
static PPARTENTRY ActiveBootPartition = NULL;
static PFILE_SYSTEM_LIST FileSystemList = NULL;
@ -677,7 +674,6 @@ InstallIntroPage(PINPUT_RECORD Ir)
static PAGE_NUMBER
SelectPartitionPage(PINPUT_RECORD Ir)
{
WCHAR PathBuffer[MAX_PATH];
SHORT xScreen;
SHORT yScreen;
@ -691,9 +687,6 @@ SelectPartitionPage(PINPUT_RECORD Ir)
SetStatusText(" Please wait...");
RtlFreeUnicodeString(&DestinationPath);
RtlFreeUnicodeString(&DestinationRootPath);
GetScreenSize(&xScreen, &yScreen);
if (PartitionList == NULL)
@ -755,55 +748,10 @@ SelectPartitionPage(PINPUT_RECORD Ir)
CreateNewPartition (PartitionList,
0ULL,
TRUE);
/* FIXME: Update drive letters and partition numbers */
}
return SELECT_FILE_SYSTEM_PAGE;
}
else
{
RtlFreeUnicodeString (&DestinationRootPath);
swprintf (PathBuffer,
L"\\Device\\Harddisk%lu\\Partition%lu",
PartitionList->CurrentDisk->DiskNumber,
PartitionList->CurrentPartition->PartInfo[0].PartitionNumber);
RtlCreateUnicodeString (&DestinationRootPath,
PathBuffer);
GetActiveBootPartition (PartitionList,
&ActiveBootDisk,
&ActiveBootPartition);
RtlFreeUnicodeString (&SystemRootPath);
if (ActiveBootDisk != NULL && ActiveBootPartition != NULL)
{
swprintf (PathBuffer,
L"\\Device\\Harddisk%lu\\Partition%lu",
ActiveBootDisk->DiskNumber,
ActiveBootPartition->PartInfo[0].PartitionNumber);
}
else
{
/*
* FIXME:
* Check whether partition can be activated.
* We may have to force Disk0\Partition1.
* Mark partition active.
*/
swprintf (PathBuffer,
L"\\Device\\Harddisk%lu\\Partition%lu",
PartitionList->CurrentDisk->DiskNumber,
PartitionList->CurrentPartition->PartInfo[0].PartitionNumber);
}
RtlCreateUnicodeString (&SystemRootPath,
PathBuffer);
DPRINT ("DestinationRootPath: %wZ\n", &DestinationRootPath);
DPRINT ("SystemRootPath: %wZ\n", &SystemRootPath);
return SELECT_FILE_SYSTEM_PAGE;
}
}
else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_C) /* C */
{
if (PartitionList->CurrentPartition->Unpartitioned == FALSE)
@ -1347,7 +1295,6 @@ SelectFileSystemPage (PINPUT_RECORD Ir)
{
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry;
// BOOLEAN ForceFormat;
ULONGLONG DiskSize;
ULONGLONG PartSize;
PCHAR DiskUnit;
@ -1488,11 +1435,8 @@ SelectFileSystemPage (PINPUT_RECORD Ir)
SetTextXY(8, 21, "\x07 Press ENTER to format the partition.");
SetTextXY(8, 23, "\x07 Press ESC to select another partition.");
// ForceFormat = (PartEntry->PartInfo[0].PartitionType == PARTITION_ENTRY_UNUSED);
if (FileSystemList == NULL)
{
// FileSystemList = CreateFileSystemList (6, 26, ForceFormat, FsFat);
FileSystemList = CreateFileSystemList (6, 26, PartEntry->New, FsFat);
if (FileSystemList == NULL)
{
@ -1536,7 +1480,6 @@ SelectFileSystemPage (PINPUT_RECORD Ir)
}
else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */
{
#if 0
if (FileSystemList->CurrentFileSystem == FsKeep)
{
return CHECK_FILE_SYSTEM_PAGE;
@ -1545,8 +1488,6 @@ SelectFileSystemPage (PINPUT_RECORD Ir)
{
return FORMAT_PARTITION_PAGE;
}
#endif
return FORMAT_PARTITION_PAGE;
}
}
@ -1557,14 +1498,16 @@ SelectFileSystemPage (PINPUT_RECORD Ir)
static ULONG
FormatPartitionPage (PINPUT_RECORD Ir)
{
WCHAR PathBuffer[MAX_PATH];
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry;
PLIST_ENTRY Entry;
// NTSTATUS Status;
NTSTATUS Status;
//#ifndef NDEBUG
ULONG Line;
ULONG i;
//#endif
SetTextXY(6, 8, "Format partition");
@ -1637,7 +1580,7 @@ FormatPartitionPage (PINPUT_RECORD Ir)
return QUIT_PAGE;
}
//#if 0
//#ifndef NDEBUG
PrintTextXY (6, 12,
"Disk: %I64u Cylinder: %I64u Track: %I64u",
DiskEntry->DiskSize,
@ -1675,6 +1618,8 @@ FormatPartitionPage (PINPUT_RECORD Ir)
}
//#endif
SetActiveBootPartition (PartitionList);
if (WritePartitionsToDisk (PartitionList) == FALSE)
{
DPRINT ("WritePartitionsToDisk() failed\n");
@ -1693,10 +1638,29 @@ FormatPartitionPage (PINPUT_RECORD Ir)
}
}
SetStatusText (" Press any key ...");
ConInKey(Ir);
#if 0
/* Set DestinationRootPath */
RtlFreeUnicodeString (&DestinationRootPath);
swprintf (PathBuffer,
L"\\Device\\Harddisk%lu\\Partition%lu",
PartitionList->CurrentDisk->DiskNumber,
PartitionList->CurrentPartition->PartInfo[0].PartitionNumber);
RtlCreateUnicodeString (&DestinationRootPath,
PathBuffer);
DPRINT1 ("DestinationRootPath: %wZ\n", &DestinationRootPath);
/* Set SystemRootPath */
RtlFreeUnicodeString (&SystemRootPath);
swprintf (PathBuffer,
L"\\Device\\Harddisk%lu\\Partition%lu",
PartitionList->ActiveBootDisk->DiskNumber,
PartitionList->ActiveBootPartition->PartInfo[0].PartitionNumber);
RtlCreateUnicodeString (&SystemRootPath,
PathBuffer);
DPRINT1 ("SystemRootPath: %wZ\n", &SystemRootPath);
switch (FileSystemList->CurrentFileSystem)
{
case FsFat:
@ -1716,6 +1680,10 @@ FormatPartitionPage (PINPUT_RECORD Ir)
return QUIT_PAGE;
}
SetStatusText (" Done. Press any key ...");
ConInKey(Ir);
#if 0
return INSTALL_DIRECTORY_PAGE;
#endif
@ -1730,6 +1698,8 @@ FormatPartitionPage (PINPUT_RECORD Ir)
static ULONG
CheckFileSystemPage(PINPUT_RECORD Ir)
{
WCHAR PathBuffer[MAX_PATH];
SetTextXY(6, 8, "Check file system");
SetTextXY(6, 10, "At present, ReactOS can not check file systems.");
@ -1739,6 +1709,28 @@ CheckFileSystemPage(PINPUT_RECORD Ir)
SetStatusText(" ENTER = Continue F3 = Quit");
/* Set DestinationRootPath */
RtlFreeUnicodeString (&DestinationRootPath);
swprintf (PathBuffer,
L"\\Device\\Harddisk%lu\\Partition%lu",
PartitionList->CurrentDisk->DiskNumber,
PartitionList->CurrentPartition->PartInfo[0].PartitionNumber);
RtlCreateUnicodeString (&DestinationRootPath,
PathBuffer);
DPRINT1 ("DestinationRootPath: %wZ\n", &DestinationRootPath);
/* Set SystemRootPath */
RtlFreeUnicodeString (&SystemRootPath);
swprintf (PathBuffer,
L"\\Device\\Harddisk%lu\\Partition%lu",
PartitionList->ActiveBootDisk->DiskNumber,
PartitionList->ActiveBootPartition->PartInfo[0].PartitionNumber);
RtlCreateUnicodeString (&SystemRootPath,
PathBuffer);
DPRINT1 ("SystemRootPath: %wZ\n", &SystemRootPath);
while(TRUE)
{
ConInKey(Ir);
@ -2367,7 +2359,7 @@ BootLoaderPage(PINPUT_RECORD Ir)
}
#endif
if (ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_ENTRY_UNUSED)
if (PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_ENTRY_UNUSED)
{
DPRINT1("Error: active partition invalid (unused)\n");
PopupError("The active partition is unused (invalid).\n",
@ -2384,7 +2376,7 @@ BootLoaderPage(PINPUT_RECORD Ir)
}
}
if (ActiveBootPartition->PartInfo[0].PartitionType == 0x0A)
if (PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == 0x0A)
{
/* OS/2 boot manager partition */
DPRINT1("Found OS/2 boot manager partition\n");
@ -2402,7 +2394,7 @@ BootLoaderPage(PINPUT_RECORD Ir)
}
}
}
else if (ActiveBootPartition->PartInfo[0].PartitionType == 0x83)
else if (PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == 0x83)
{
/* Linux ext2 partition */
DPRINT1("Found Linux ext2 partition\n");
@ -2420,7 +2412,7 @@ BootLoaderPage(PINPUT_RECORD Ir)
}
}
}
else if (ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_IFS)
else if (PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_IFS)
{
/* NTFS partition */
DPRINT1("Found NTFS partition\n");
@ -2438,12 +2430,12 @@ BootLoaderPage(PINPUT_RECORD Ir)
}
}
}
else if ((ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT_12) ||
(ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT_16) ||
(ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_HUGE) ||
(ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_XINT13) ||
(ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32) ||
(ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13))
else if ((PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT_12) ||
(PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT_16) ||
(PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_HUGE) ||
(PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_XINT13) ||
(PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32) ||
(PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13))
{
/* FAT or FAT32 partition */
DPRINT1("System path: '%wZ'\n", &SystemRootPath);
@ -2507,8 +2499,8 @@ BootLoaderPage(PINPUT_RECORD Ir)
}
/* Install new bootcode */
if ((ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32) ||
(ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13))
if ((PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32) ||
(PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13))
{
/* Install FAT32 bootcode */
wcscpy(SrcPath, SourceRootPath.Buffer);
@ -2703,8 +2695,8 @@ BootLoaderPage(PINPUT_RECORD Ir)
}
/* Install new bootsector */
if ((ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32) ||
(ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13))
if ((PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32) ||
(PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13))
{
wcscpy(SrcPath, SourceRootPath.Buffer);
wcscat(SrcPath, L"\\loader\\fat32.bin");
@ -2864,8 +2856,8 @@ BootLoaderPage(PINPUT_RECORD Ir)
}
/* Install new bootsector */
if ((ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32) ||
(ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13))
if ((PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32) ||
(PartitionList->ActiveBootPartition->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13))
{
wcscpy(SrcPath, SourceRootPath.Buffer);
wcscat(SrcPath, L"\\loader\\fat32.bin");