Implemented code to update container partitions. Only a few border-cases are still missing.

svn path=/trunk/; revision=5538
This commit is contained in:
Eric Kohl 2003-08-12 15:56:21 +00:00
parent 6010f3ea82
commit 03734abbca
3 changed files with 494 additions and 132 deletions

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: partlist.c,v 1.16 2003/08/09 16:32:25 ekohl Exp $ /* $Id: partlist.c,v 1.17 2003/08/12 15:56:21 ekohl Exp $
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup * PROJECT: ReactOS text-mode setup
* FILE: subsys/system/usetup/partlist.c * FILE: subsys/system/usetup/partlist.c
@ -41,7 +41,7 @@
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
static VOID static VOID
GetDriverName(PDISKENTRY DiskEntry) GetDriverName (PDISKENTRY DiskEntry)
{ {
RTL_QUERY_REGISTRY_TABLE QueryTable[2]; RTL_QUERY_REGISTRY_TABLE QueryTable[2];
WCHAR KeyName[32]; WCHAR KeyName[32];
@ -498,7 +498,10 @@ AddDiskToList (HANDLE FileHandle,
PPARTLIST PPARTLIST
InitializePartitionList(VOID) CreatePartitionList (SHORT Left,
SHORT Top,
SHORT Right,
SHORT Bottom)
{ {
PPARTLIST List; PPARTLIST List;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
@ -518,10 +521,14 @@ InitializePartitionList(VOID)
if (List == NULL) if (List == NULL)
return NULL; return NULL;
List->Left = 0; // List->Left = 0;
List->Top = 0; // List->Top = 0;
List->Right = 0; // List->Right = 0;
List->Bottom = 0; // List->Bottom = 0;
List->Left = Left;
List->Top = Top;
List->Right = Right;
List->Bottom = Bottom;
List->Line = 0; List->Line = 0;
@ -533,35 +540,35 @@ InitializePartitionList(VOID)
InitializeListHead (&List->DiskListHead); InitializeListHead (&List->DiskListHead);
Status = NtQuerySystemInformation(SystemDeviceInformation, Status = NtQuerySystemInformation (SystemDeviceInformation,
&Sdi, &Sdi,
sizeof(SYSTEM_DEVICE_INFORMATION), sizeof(SYSTEM_DEVICE_INFORMATION),
&ReturnSize); &ReturnSize);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS (Status))
{ {
RtlFreeHeap(ProcessHeap, 0, List); RtlFreeHeap (ProcessHeap, 0, List);
return(NULL); return NULL;
} }
for (DiskNumber = 0; DiskNumber < Sdi.NumberOfDisks; DiskNumber++) for (DiskNumber = 0; DiskNumber < Sdi.NumberOfDisks; DiskNumber++)
{ {
swprintf(Buffer, swprintf (Buffer,
L"\\Device\\Harddisk%d\\Partition0", L"\\Device\\Harddisk%d\\Partition0",
DiskNumber); DiskNumber);
RtlInitUnicodeString(&Name, RtlInitUnicodeString (&Name,
Buffer); Buffer);
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes (&ObjectAttributes,
&Name, &Name,
0, 0,
NULL, NULL,
NULL); NULL);
Status = NtOpenFile(&FileHandle, Status = NtOpenFile (&FileHandle,
0x10001, FILE_GENERIC_READ,
&ObjectAttributes, &ObjectAttributes,
&Iosb, &Iosb,
1, FILE_SHARE_READ,
FILE_SYNCHRONOUS_IO_NONALERT); FILE_SYNCHRONOUS_IO_NONALERT);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
@ -608,31 +615,8 @@ InitializePartitionList(VOID)
} }
PPARTLIST
CreatePartitionList(SHORT Left,
SHORT Top,
SHORT Right,
SHORT Bottom)
{
PPARTLIST List;
List = InitializePartitionList ();
if (List == NULL)
return NULL;
List->Left = Left;
List->Top = Top;
List->Right = Right;
List->Bottom = Bottom;
DrawPartitionList (List);
return List;
}
VOID VOID
DestroyPartitionList(PPARTLIST List) DestroyPartitionList (PPARTLIST List)
{ {
PDISKENTRY DiskEntry; PDISKENTRY DiskEntry;
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
@ -688,7 +672,7 @@ DestroyPartitionList(PPARTLIST List)
static VOID static VOID
PrintEmptyLine(PPARTLIST List) PrintEmptyLine (PPARTLIST List)
{ {
COORD coPos; COORD coPos;
ULONG Written; ULONG Written;
@ -704,12 +688,12 @@ PrintEmptyLine(PPARTLIST List)
coPos.X = List->Left + 1; coPos.X = List->Left + 1;
coPos.Y = List->Top + 1 + List->Line; coPos.Y = List->Top + 1 + List->Line;
FillConsoleOutputAttribute(0x17, FillConsoleOutputAttribute (0x17,
Width, Width,
coPos, coPos,
&Written); &Written);
FillConsoleOutputCharacter(' ', FillConsoleOutputCharacter (' ',
Width, Width,
coPos, coPos,
&Written); &Written);
@ -719,7 +703,7 @@ PrintEmptyLine(PPARTLIST List)
static VOID static VOID
PrintPartitionData(PPARTLIST List, PrintPartitionData (PPARTLIST List,
PDISKENTRY DiskEntry, PDISKENTRY DiskEntry,
PPARTENTRY PartEntry) PPARTENTRY PartEntry)
{ {
@ -865,7 +849,7 @@ PrintPartitionData(PPARTLIST List,
static VOID static VOID
PrintDiskData(PPARTLIST List, PrintDiskData (PPARTLIST List,
PDISKENTRY DiskEntry) PDISKENTRY DiskEntry)
{ {
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
@ -967,7 +951,7 @@ PrintDiskData(PPARTLIST List,
VOID VOID
DrawPartitionList(PPARTLIST List) DrawPartitionList (PPARTLIST List)
{ {
PLIST_ENTRY Entry; PLIST_ENTRY Entry;
PDISKENTRY DiskEntry; PDISKENTRY DiskEntry;
@ -1060,7 +1044,7 @@ DrawPartitionList(PPARTLIST List)
VOID VOID
ScrollDownPartitionList(PPARTLIST List) ScrollDownPartitionList (PPARTLIST List)
{ {
PDISKENTRY DiskEntry; PDISKENTRY DiskEntry;
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
@ -1120,7 +1104,7 @@ ScrollDownPartitionList(PPARTLIST List)
VOID VOID
ScrollUpPartitionList(PPARTLIST List) ScrollUpPartitionList (PPARTLIST List)
{ {
PDISKENTRY DiskEntry; PDISKENTRY DiskEntry;
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
@ -1182,7 +1166,7 @@ ScrollUpPartitionList(PPARTLIST List)
VOID VOID
GetActiveBootPartition(PPARTLIST List, GetActiveBootPartition (PPARTLIST List,
PDISKENTRY *DiskEntry, PDISKENTRY *DiskEntry,
PPARTENTRY *PartEntry) PPARTENTRY *PartEntry)
{ {
@ -1224,6 +1208,96 @@ GetActiveBootPartition(PPARTLIST List,
} }
static PPARTENTRY
GetPrevPartitionedEntry (PDISKENTRY DiskEntry,
PPARTENTRY CurrentEntry)
{
PPARTENTRY PrevEntry;
PLIST_ENTRY Entry;
if (CurrentEntry->ListEntry.Blink == &DiskEntry->PartListHead)
return NULL;
Entry = CurrentEntry->ListEntry.Blink;
while (Entry != &DiskEntry->PartListHead)
{
PrevEntry = CONTAINING_RECORD (Entry,
PARTENTRY,
ListEntry);
if (PrevEntry->Unpartitioned == FALSE)
return PrevEntry;
Entry = Entry->Blink;
}
return NULL;
}
static PPARTENTRY
GetNextPartitionedEntry (PDISKENTRY DiskEntry,
PPARTENTRY CurrentEntry)
{
PPARTENTRY NextEntry;
PLIST_ENTRY Entry;
if (CurrentEntry->ListEntry.Flink == &DiskEntry->PartListHead)
return NULL;
Entry = CurrentEntry->ListEntry.Flink;
while (Entry != &DiskEntry->PartListHead)
{
NextEntry = CONTAINING_RECORD (Entry,
PARTENTRY,
ListEntry);
if (NextEntry->Unpartitioned == FALSE)
return NextEntry;
Entry = Entry->Flink;
}
return NULL;
}
static PPARTENTRY
GetPrevUnpartitionedEntry (PDISKENTRY DiskEntry,
PPARTENTRY PartEntry)
{
PPARTENTRY PrevPartEntry;
if (PartEntry->ListEntry.Blink != &DiskEntry->PartListHead)
{
PrevPartEntry = CONTAINING_RECORD (PartEntry->ListEntry.Blink,
PARTENTRY,
ListEntry);
if (PrevPartEntry->Unpartitioned == TRUE)
return PrevPartEntry;
}
return NULL;
}
static PPARTENTRY
GetNextUnpartitionedEntry (PDISKENTRY DiskEntry,
PPARTENTRY PartEntry)
{
PPARTENTRY NextPartEntry;
if (PartEntry->ListEntry.Flink != &DiskEntry->PartListHead)
{
NextPartEntry = CONTAINING_RECORD (PartEntry->ListEntry.Flink,
PARTENTRY,
ListEntry);
if (NextPartEntry->Unpartitioned == TRUE)
return NextPartEntry;
}
return NULL;
}
VOID VOID
CreateNewPartition (PPARTLIST List, CreateNewPartition (PPARTLIST List,
ULONGLONG PartitionSize, ULONGLONG PartitionSize,
@ -1257,18 +1331,74 @@ CreateNewPartition (PPARTLIST List,
PartEntry->PartInfo[0].PartitionType = PARTITION_ENTRY_UNUSED; PartEntry->PartInfo[0].PartitionType = PARTITION_ENTRY_UNUSED;
PartEntry->PartInfo[0].BootIndicator = FALSE; /* FIXME */ PartEntry->PartInfo[0].BootIndicator = FALSE; /* FIXME */
PartEntry->PartInfo[0].RewritePartition = TRUE; PartEntry->PartInfo[0].RewritePartition = TRUE;
PartEntry->PartInfo[1].RewritePartition = TRUE;
PartEntry->PartInfo[2].RewritePartition = TRUE;
PartEntry->PartInfo[3].RewritePartition = TRUE;
/* Check for previous partition entry */ /* Get previous and next partition entries */
if (PartEntry->ListEntry.Blink != &DiskEntry->PartListHead) PrevPartEntry = GetPrevPartitionedEntry (DiskEntry,
PartEntry);
NextPartEntry = GetNextPartitionedEntry (DiskEntry,
PartEntry);
if (PrevPartEntry != NULL && NextPartEntry != NULL)
{ {
PrevPartEntry = CONTAINING_RECORD (PartEntry->ListEntry.Blink, /* Current entry is in the middle of the list */
PARTENTRY,
ListEntry);
/* Copy previous container partition data to current entry */
RtlCopyMemory (&PartEntry->PartInfo[1],
&PrevPartEntry->PartInfo[1],
sizeof(PARTITION_INFORMATION));
PartEntry->PartInfo[1].RewritePartition = TRUE;
/* Update previous container partition data */
PrevPartEntry->PartInfo[1].StartingOffset.QuadPart =
PartEntry->PartInfo[0].StartingOffset.QuadPart - DiskEntry->TrackSize;
if (DiskEntry->PartListHead.Flink == &PrevPartEntry->ListEntry)
{
/* Special case - previous partition is first partition */
PrevPartEntry->PartInfo[1].PartitionLength.QuadPart =
DiskEntry->DiskSize - PrevPartEntry->PartInfo[1].StartingOffset.QuadPart;
}
else
{
PrevPartEntry->PartInfo[1].PartitionLength.QuadPart =
PartEntry->PartInfo[0].PartitionLength.QuadPart + DiskEntry->TrackSize;
}
PrevPartEntry->PartInfo[1].RewritePartition = TRUE;
}
else if (PrevPartEntry == NULL && NextPartEntry != NULL)
{
/* Current entry is the first entry */
/* FIXME: Update extended partition entries */ /* FIXME: Update extended partition entries */
}
else if (PrevPartEntry != NULL && NextPartEntry == NULL)
{
/* Current entry is the last entry */
PrevPartEntry->PartInfo[1].StartingOffset.QuadPart =
PartEntry->PartInfo[0].StartingOffset.QuadPart - DiskEntry->TrackSize;
if (DiskEntry->PartListHead.Flink == &PrevPartEntry->ListEntry)
{
/* Special case - previous partition is first partition */
PrevPartEntry->PartInfo[1].PartitionLength.QuadPart =
DiskEntry->DiskSize - PrevPartEntry->PartInfo[1].StartingOffset.QuadPart;
}
else
{
PrevPartEntry->PartInfo[1].PartitionLength.QuadPart =
PartEntry->PartInfo[0].PartitionLength.QuadPart + DiskEntry->TrackSize;
}
PrevPartEntry->PartInfo[1].PartitionType =
(DiskEntry->UseLba == TRUE) ? PARTITION_XINT13_EXTENDED : PARTITION_EXTENDED;
PrevPartEntry->PartInfo[1].BootIndicator = FALSE;
PrevPartEntry->PartInfo[1].RewritePartition = TRUE;
} }
PartEntry->AutoCreate = AutoCreate; PartEntry->AutoCreate = AutoCreate;
@ -1302,8 +1432,75 @@ CreateNewPartition (PPARTLIST List,
NewPartEntry->PartInfo[0].PartitionType = PARTITION_ENTRY_UNUSED; NewPartEntry->PartInfo[0].PartitionType = PARTITION_ENTRY_UNUSED;
NewPartEntry->PartInfo[0].BootIndicator = FALSE; /* FIXME */ NewPartEntry->PartInfo[0].BootIndicator = FALSE; /* FIXME */
NewPartEntry->PartInfo[0].RewritePartition = TRUE; NewPartEntry->PartInfo[0].RewritePartition = TRUE;
NewPartEntry->PartInfo[1].RewritePartition = TRUE;
NewPartEntry->PartInfo[2].RewritePartition = TRUE;
NewPartEntry->PartInfo[3].RewritePartition = TRUE;
/* Get previous and next partition entries */
PrevPartEntry = GetPrevPartitionedEntry (DiskEntry,
NewPartEntry);
NextPartEntry = GetNextPartitionedEntry (DiskEntry,
NewPartEntry);
if (PrevPartEntry != NULL && NextPartEntry != NULL)
{
/* Current entry is in the middle of the list */
/* Copy previous container partition data to current entry */
RtlCopyMemory (&NewPartEntry->PartInfo[1],
&PrevPartEntry->PartInfo[1],
sizeof(PARTITION_INFORMATION));
NewPartEntry->PartInfo[1].RewritePartition = TRUE;
/* Update previous container partition data */
PrevPartEntry->PartInfo[1].StartingOffset.QuadPart =
NewPartEntry->PartInfo[0].StartingOffset.QuadPart - DiskEntry->TrackSize;
if (DiskEntry->PartListHead.Flink == &PrevPartEntry->ListEntry)
{
/* Special case - previous partition is first partition */
PrevPartEntry->PartInfo[1].PartitionLength.QuadPart =
DiskEntry->DiskSize - PrevPartEntry->PartInfo[1].StartingOffset.QuadPart;
}
else
{
PrevPartEntry->PartInfo[1].PartitionLength.QuadPart =
NewPartEntry->PartInfo[0].PartitionLength.QuadPart + DiskEntry->TrackSize;
}
PrevPartEntry->PartInfo[1].RewritePartition = TRUE;
}
else if (PrevPartEntry == NULL && NextPartEntry != NULL)
{
/* Current entry is the first entry */
/* FIXME: Update extended partition entries */ /* FIXME: Update extended partition entries */
}
else if (PrevPartEntry != NULL && NextPartEntry == NULL)
{
/* Current entry is the last entry */
PrevPartEntry->PartInfo[1].StartingOffset.QuadPart =
NewPartEntry->PartInfo[0].StartingOffset.QuadPart - DiskEntry->TrackSize;
if (DiskEntry->PartListHead.Flink == &PrevPartEntry->ListEntry)
{
/* Special case - previous partition is first partition */
PrevPartEntry->PartInfo[1].PartitionLength.QuadPart =
DiskEntry->DiskSize - PrevPartEntry->PartInfo[1].StartingOffset.QuadPart;
}
else
{
PrevPartEntry->PartInfo[1].PartitionLength.QuadPart =
NewPartEntry->PartInfo[0].PartitionLength.QuadPart + DiskEntry->TrackSize;
}
PrevPartEntry->PartInfo[1].PartitionType =
(DiskEntry->UseLba == TRUE) ? PARTITION_XINT13_EXTENDED : PARTITION_EXTENDED;
PrevPartEntry->PartInfo[1].BootIndicator = FALSE;
PrevPartEntry->PartInfo[1].RewritePartition = TRUE;
}
/* Update offset and size of the remaining unpartitioned disk space */ /* Update offset and size of the remaining unpartitioned disk space */
PartEntry->UnpartitionedOffset += PartitionSize; PartEntry->UnpartitionedOffset += PartitionSize;
@ -1337,36 +1534,56 @@ DeleteCurrentPartition (PPARTLIST List)
DiskEntry = List->CurrentDisk; DiskEntry = List->CurrentDisk;
PartEntry = List->CurrentPartition; PartEntry = List->CurrentPartition;
/* Get pointer to previous partition entry */ /* Adjust container partition entries */
PrevPartEntry = NULL;
if (PartEntry->ListEntry.Blink != &DiskEntry->PartListHead) /* Get previous and next partition entries */
PrevPartEntry = GetPrevPartitionedEntry (DiskEntry,
PartEntry);
NextPartEntry = GetNextPartitionedEntry (DiskEntry,
PartEntry);
if (PrevPartEntry != NULL && NextPartEntry != NULL)
{ {
PrevPartEntry = CONTAINING_RECORD (PartEntry->ListEntry.Blink, /* Current entry is in the middle of the list */
PARTENTRY, /* Copy previous container partition data to current entry */
ListEntry); RtlCopyMemory (&PrevPartEntry->PartInfo[1],
&PartEntry->PartInfo[1],
sizeof(PARTITION_INFORMATION));
PrevPartEntry->PartInfo[1].RewritePartition = TRUE;
}
else if (PrevPartEntry == NULL && NextPartEntry != NULL)
{
/* Current entry is the first entry */
/* FIXME: Update extended partition entries */
}
else if (PrevPartEntry != NULL && NextPartEntry == NULL)
{
/* Current entry is the last entry */
RtlZeroMemory (&PrevPartEntry->PartInfo[1],
sizeof(PARTITION_INFORMATION));
PrevPartEntry->PartInfo[1].RewritePartition = TRUE;
} }
/* Get pointer to previous partition entry */
NextPartEntry = NULL;
if (PartEntry->ListEntry.Flink != &DiskEntry->PartListHead)
{
NextPartEntry = CONTAINING_RECORD (PartEntry->ListEntry.Flink,
PARTENTRY,
ListEntry);
}
if ((PrevPartEntry != NULL && PrevPartEntry->Unpartitioned == TRUE) && /* Adjust unpartitioned disk space entries */
(NextPartEntry != NULL && NextPartEntry->Unpartitioned == TRUE))
/* Get pointer to previous and next unpartitioned entries */
PrevPartEntry = GetPrevUnpartitionedEntry (DiskEntry,
PartEntry);
NextPartEntry = GetNextUnpartitionedEntry (DiskEntry,
PartEntry);
if (PrevPartEntry != NULL && NextPartEntry != NULL)
{ {
/* Merge previous, current and next entry */ /* Merge previous, current and next unpartitioned entry */
/* Adjust the previous entries length */ /* Adjust the previous entries length */
PrevPartEntry->UnpartitionedLength += PrevPartEntry->UnpartitionedLength +=
(PartEntry->PartInfo[0].PartitionLength.QuadPart + DiskEntry->TrackSize + (PartEntry->PartInfo[0].PartitionLength.QuadPart + DiskEntry->TrackSize +
NextPartEntry->UnpartitionedLength); NextPartEntry->UnpartitionedLength);
/* FIXME: Container entries ?? */
/* Remove the current entry */ /* Remove the current entry */
RemoveEntryList (&PartEntry->ListEntry); RemoveEntryList (&PartEntry->ListEntry);
RtlFreeHeap (ProcessHeap, RtlFreeHeap (ProcessHeap,
@ -1382,16 +1599,14 @@ DeleteCurrentPartition (PPARTLIST List)
/* Update current partition */ /* Update current partition */
List->CurrentPartition = PrevPartEntry; List->CurrentPartition = PrevPartEntry;
} }
else if (PrevPartEntry != NULL && PrevPartEntry->Unpartitioned == TRUE) else if (PrevPartEntry != NULL && NextPartEntry == NULL)
{ {
/* Merge current and previous entry */ /* Merge current and previous unpartitioned entry */
/* Adjust the previous entries length */ /* Adjust the previous entries length */
PrevPartEntry->UnpartitionedLength += PrevPartEntry->UnpartitionedLength +=
(PartEntry->PartInfo[0].PartitionLength.QuadPart + DiskEntry->TrackSize); (PartEntry->PartInfo[0].PartitionLength.QuadPart + DiskEntry->TrackSize);
/* FIXME: Container entries ?? */
/* Remove the current entry */ /* Remove the current entry */
RemoveEntryList (&PartEntry->ListEntry); RemoveEntryList (&PartEntry->ListEntry);
RtlFreeHeap (ProcessHeap, RtlFreeHeap (ProcessHeap,
@ -1401,9 +1616,9 @@ DeleteCurrentPartition (PPARTLIST List)
/* Update current partition */ /* Update current partition */
List->CurrentPartition = PrevPartEntry; List->CurrentPartition = PrevPartEntry;
} }
else if (NextPartEntry != NULL && NextPartEntry->Unpartitioned == TRUE) else if (PrevPartEntry == NULL && NextPartEntry != NULL)
{ {
/* Merge current and next entry */ /* Merge current and next unpartitioned entry */
/* Adjust the next entries offset and length */ /* Adjust the next entries offset and length */
NextPartEntry->UnpartitionedOffset = NextPartEntry->UnpartitionedOffset =
@ -1411,8 +1626,6 @@ DeleteCurrentPartition (PPARTLIST List)
NextPartEntry->UnpartitionedLength += NextPartEntry->UnpartitionedLength +=
(PartEntry->PartInfo[0].PartitionLength.QuadPart + DiskEntry->TrackSize); (PartEntry->PartInfo[0].PartitionLength.QuadPart + DiskEntry->TrackSize);
/* FIXME: Container entries ?? */
/* Remove the current entry */ /* Remove the current entry */
RemoveEntryList (&PartEntry->ListEntry); RemoveEntryList (&PartEntry->ListEntry);
RtlFreeHeap (ProcessHeap, RtlFreeHeap (ProcessHeap,
@ -1432,8 +1645,6 @@ DeleteCurrentPartition (PPARTLIST List)
PartEntry->UnpartitionedLength = PartEntry->UnpartitionedLength =
PartEntry->PartInfo[0].PartitionLength.QuadPart + DiskEntry->TrackSize; PartEntry->PartInfo[0].PartitionLength.QuadPart + DiskEntry->TrackSize;
/* FIXME: Container entries ?? */
/* Wipe the partition table */ /* Wipe the partition table */
RtlZeroMemory (&PartEntry->PartInfo, RtlZeroMemory (&PartEntry->PartInfo,
sizeof(PartEntry->PartInfo)); sizeof(PartEntry->PartInfo));
@ -1446,4 +1657,143 @@ DeleteCurrentPartition (PPARTLIST List)
AssignDriverLetters (List); AssignDriverLetters (List);
} }
BOOLEAN
WritePartitionsToDisk (PPARTLIST List)
{
#if 0
PDRIVE_LAYOUT_INFORMATION DriveLayout;
OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK Iosb;
WCHAR Buffer[MAX_PATH];
UNICODE_STRING Name;
HANDLE FileHandle;
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry;
PLIST_ENTRY Entry1;
PLIST_ENTRY Entry2;
ULONG PartitionCount;
ULONG DriveLayoutSize;
ULONG Index;
NTSTATUS Status;
if (List == NULL)
{
return TRUE;
}
Entry1 = List->DiskListHead.Flink;
while (Entry1 != &List->DiskListHead)
{
DiskEntry = CONTAINING_RECORD (Entry1,
DISKENTRY,
ListEntry);
if (DiskEntry->Modified == TRUE)
{
/* Count partitioned entries */
PartitionCount = 0;
Entry2 = DiskEntry->PartListHead.Flink;
while (Entry2 != &DiskEntry->PartListHead)
{
PartEntry = CONTAINING_RECORD (Entry2,
PARTENTRY,
ListEntry);
if (PartEntry->Unpartitioned == FALSE)
{
PartitionCount += 4;
}
Entry2 = Entry2->Flink;
}
if (PartitionCount > 0)
{
DriveLayoutSize = sizeof (DRIVE_LAYOUT_INFORMATION) +
((PartitionCount - 1) * sizeof (PARTITION_INFORMATION));
DriveLayout = (PDRIVE_LAYOUT_INFORMATION)RtlAllocateHeap (ProcessHeap,
0,
DriveLayoutSize);
if (DriveLayout == NULL)
{
DPRINT1 ("RtlAllocateHeap() failed\n");
return FALSE;
}
RtlZeroMemory (DriveLayout,
DriveLayoutSize);
DriveLayout->PartitionCount = PartitionCount;
Index = 0;
Entry2 = DiskEntry->PartListHead.Flink;
while (Entry2 != &DiskEntry->PartListHead)
{
PartEntry = CONTAINING_RECORD (Entry2,
PARTENTRY,
ListEntry);
if (PartEntry->Unpartitioned == FALSE)
{
RtlCopyMemory (&DriveLayout->PartitionEntry[Index],
&PartEntry->PartInfo[0],
4 * sizeof (PARTITION_INFORMATION));
Index += 4;
}
Entry2 = Entry2->Flink;
}
swprintf (Buffer,
L"\\Device\\Harddisk%d\\Partition0",
DiskEntry->DiskNumber);
RtlInitUnicodeString (&Name,
Buffer);
InitializeObjectAttributes (&ObjectAttributes,
&Name,
0,
NULL,
NULL);
Status = NtOpenFile (&FileHandle,
FILE_GENERIC_WRITE,
&ObjectAttributes,
&Iosb,
0,
FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS (Status))
{
DPRINT1 ("NtOpenFile() failed (Status %lx)\n", Status);
return FALSE;
}
Status = NtDeviceIoControlFile (FileHandle,
NULL,
NULL,
NULL,
&Iosb,
IOCTL_DISK_SET_DRIVE_LAYOUT,
DriveLayout,
DriveLayoutSize,
NULL,
0);
NtClose (FileHandle);
if (!NT_SUCCESS (Status))
{
DPRINT1 ("NtDeviceIoControlFile() failed (Status %lx)\n", Status);
return FALSE;
}
RtlFreeHeap (ProcessHeap,
0,
DriveLayout);
}
}
Entry1 = Entry1->Flink;
}
#endif
return TRUE;
}
/* EOF */ /* EOF */

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: partlist.h,v 1.16 2003/08/09 16:32:25 ekohl Exp $ /* $Id: partlist.h,v 1.17 2003/08/12 15:56:21 ekohl Exp $
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup * PROJECT: ReactOS text-mode setup
* FILE: subsys/system/usetup/partlist.h * FILE: subsys/system/usetup/partlist.h
@ -146,6 +146,9 @@ CreateNewPartition (PPARTLIST List,
VOID VOID
DeleteCurrentPartition (PPARTLIST List); DeleteCurrentPartition (PPARTLIST List);
BOOLEAN
WritePartitionsToDisk (PPARTLIST List);
#endif /* __PARTLIST_H__ */ #endif /* __PARTLIST_H__ */
/* EOF */ /* EOF */

View file

@ -708,10 +708,8 @@ SelectPartitionPage(PINPUT_RECORD Ir)
return(QUIT_PAGE); return(QUIT_PAGE);
} }
} }
else
{
DrawPartitionList (PartitionList); DrawPartitionList (PartitionList);
}
while(TRUE) while(TRUE)
{ {
@ -1563,7 +1561,6 @@ FormatPartitionPage (PINPUT_RECORD Ir)
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
PLIST_ENTRY Entry; PLIST_ENTRY Entry;
// NTSTATUS Status; // NTSTATUS Status;
// BOOLEAN Valid;
ULONG Line; ULONG Line;
@ -1610,9 +1607,17 @@ FormatPartitionPage (PINPUT_RECORD Ir)
case FsFat: case FsFat:
if (DiskEntry->UseLba == FALSE) if (DiskEntry->UseLba == FALSE)
{ {
/* FAT16 CHS partition (disk is smaller than 8.4GB) */ if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (32ULL * 1024ULL * 1024ULL))
{
/* FAT16 CHS partition (disk is smaller than 32MB) */
PartEntry->PartInfo[0].PartitionType = PARTITION_FAT_16; PartEntry->PartInfo[0].PartitionType = PARTITION_FAT_16;
} }
else
{
/* FAT16 CHS partition (disk is smaller than 8.4GB) */
PartEntry->PartInfo[0].PartitionType = PARTITION_HUGE;
}
}
else if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (2ULL * 1024ULL * 1024ULL * 1024ULL)) else if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (2ULL * 1024ULL * 1024ULL * 1024ULL))
{ {
/* FAT16 LBA partition (partition is smaller than 2GB) */ /* FAT16 LBA partition (partition is smaller than 2GB) */
@ -1652,13 +1657,13 @@ FormatPartitionPage (PINPUT_RECORD Ir)
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
PrintTextXY (6, Line, PrintTextXY (6, Line,
"%u: %u %12I64u %12I64u %u", "%u: %u %12I64u %12I64u %u %c",
i, i,
PartEntry->PartInfo[i].PartitionNumber, PartEntry->PartInfo[i].PartitionNumber,
PartEntry->PartInfo[i].StartingOffset.QuadPart, PartEntry->PartInfo[i].StartingOffset.QuadPart,
PartEntry->PartInfo[i].PartitionLength.QuadPart, PartEntry->PartInfo[i].PartitionLength.QuadPart,
PartEntry->PartInfo[i].PartitionType); PartEntry->PartInfo[i].PartitionType,
PartEntry->PartInfo[i].RewritePartition ? '*' : ' ');
Line++; Line++;
} }
@ -1670,19 +1675,23 @@ FormatPartitionPage (PINPUT_RECORD Ir)
} }
//#endif //#endif
if (WritePartitionsToDisk (PartitionList) == FALSE)
{
DPRINT ("WritePartitionsToDisk() failed\n");
#if 0 PopupError ("Setup failed to write partition tables.\n",
if (PartData.CreatePartition) "ENTER = Reboot computer");
while (TRUE)
{ {
Valid = CreateSelectedPartition (PartitionList, PartType, PartData.NewPartSize); ConInKey (Ir);
if (!Valid)
if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
{ {
DPRINT("CreateSelectedPartition() failed\n"); return QUIT_PAGE;
/* FIXME: show an error dialog */ }
return(QUIT_PAGE);
} }
} }
#endif
SetStatusText (" Press any key ..."); SetStatusText (" Press any key ...");
ConInKey(Ir); ConInKey(Ir);