From 501e32913a7d407c10ab01be2f895e99da07bf43 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Fri, 19 Jun 2015 19:01:39 +0000 Subject: [PATCH 1/1] [USETUP] Implement CreateLogicalPartition. Now we can create logical partitons, but they will not be written to a disk yet. svn path=/trunk/; revision=68197 --- reactos/base/setup/usetup/partlist.c | 67 ++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/reactos/base/setup/usetup/partlist.c b/reactos/base/setup/usetup/partlist.c index a8265353efc..606280f3e26 100644 --- a/reactos/base/setup/usetup/partlist.c +++ b/reactos/base/setup/usetup/partlist.c @@ -2621,9 +2621,9 @@ CreateLogicalPartition( PPARTLIST List, ULONGLONG SectorCount) { -// PDISKENTRY DiskEntry; + PDISKENTRY DiskEntry; PPARTENTRY PartEntry; -// PPARTENTRY NewPartEntry; + PPARTENTRY NewPartEntry; DPRINT1("CreateLogicalPartition(%I64u)\n", SectorCount); @@ -2635,10 +2635,71 @@ CreateLogicalPartition( return; } -// DiskEntry = List->CurrentDisk; + DiskEntry = List->CurrentDisk; PartEntry = List->CurrentPartition; DPRINT1("Current partition sector count: %I64u\n", PartEntry->SectorCount.QuadPart); + + if (Align(PartEntry->StartSector.QuadPart + SectorCount, DiskEntry->SectorAlignment) - PartEntry->StartSector.QuadPart == PartEntry->SectorCount.QuadPart) + { + DPRINT1("Convert existing partition entry\n"); + + /* Convert current entry to 'new (unformatted)' */ + PartEntry->IsPartitioned = TRUE; + PartEntry->PartitionType = PARTITION_ENTRY_UNUSED; + PartEntry->FormatState = Unformatted; + PartEntry->AutoCreate = FALSE; + PartEntry->New = TRUE; + PartEntry->BootIndicator = FALSE; + PartEntry->LogicalPartition = TRUE; + + DPRINT1("First Sector: %I64u\n", PartEntry->StartSector.QuadPart); + DPRINT1("Last Sector: %I64u\n", PartEntry->StartSector.QuadPart + PartEntry->SectorCount.QuadPart - 1); + DPRINT1("Total Sectors: %I64u\n", PartEntry->SectorCount.QuadPart); + } + else + { + DPRINT1("Add new partition entry\n"); + + /* Insert and initialize a new partition entry */ + NewPartEntry = RtlAllocateHeap(ProcessHeap, + HEAP_ZERO_MEMORY, + sizeof(PARTENTRY)); + if (NewPartEntry == NULL) + return; + + /* Insert the new entry into the list */ + InsertTailList(&PartEntry->ListEntry, + &NewPartEntry->ListEntry); + + NewPartEntry->DiskEntry = DiskEntry; + + NewPartEntry->IsPartitioned = TRUE; + NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart; + NewPartEntry->SectorCount.QuadPart = Align(NewPartEntry->StartSector.QuadPart + SectorCount, DiskEntry->SectorAlignment) - + NewPartEntry->StartSector.QuadPart; + NewPartEntry->PartitionType = PARTITION_ENTRY_UNUSED; + + DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart); + DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1); + DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); + + NewPartEntry->New = TRUE; + NewPartEntry->FormatState = Unformatted; + NewPartEntry->BootIndicator = FALSE; + NewPartEntry->LogicalPartition = TRUE; + + PartEntry->StartSector.QuadPart = NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart; + PartEntry->SectorCount.QuadPart -= (PartEntry->StartSector.QuadPart - NewPartEntry->StartSector.QuadPart); + } + + UpdateDiskLayout(DiskEntry); + + DiskEntry->Dirty = TRUE; + + UpdatePartitionNumbers(DiskEntry); + + AssignDriveLetters(List); } -- 2.17.1