From af4ad10c3e45b32850f1043af392821e6ba7f341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 5 Feb 2008 15:23:19 +0000 Subject: [PATCH] I took the liberty of implementing GetNextSupportedType(), which is needed to be able to call BPartition::GetNextSupportedChildType(). For the PartitionMapAddOn, the types should be either primary or extended, depending on the number of empty primary partitions and the existance of one extended partition. DriveSetup shows "Intel Primary Partition" and "Intel Extended Partition" in the Create menu now. Ingo, please review, maybe I didn't understand the plan correctly. Also, I tried to follow the code path, which is quite nested, and am pretty confused.. For example, I didn't find the place where the CreateChildJob is finally created. Is this missing yet? git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23876 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../disk_systems/intel/PartitionMapAddOn.cpp | 60 +++++++++++++++++++ .../disk_systems/intel/PartitionMapAddOn.h | 4 ++ 2 files changed, 64 insertions(+) diff --git a/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp b/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp index f420134012..295e18363d 100644 --- a/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp +++ b/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp @@ -245,6 +245,66 @@ PartitionMapHandle::SupportedChildOperations(const BMutablePartition* child, } +// GetNextSupportedType +status_t +PartitionMapHandle::GetNextSupportedType(const BMutablePartition* child, + int32* cookie, BString* type) +{ + // TODO: What are we supposed to do with the child? + + // we support creating two types, primary and extended + if (*cookie < 0 || *cookie > 1) + return B_ENTRY_NOT_FOUND; + + // check if there are any spaces at all + // TODO: check if the spaces have enough size at all + BPartitioningInfo info; + status_t ret = GetPartitioningInfo(&info); + if (ret < B_OK) + return ret; + + if (info.CountPartitionableSpaces() == 0) + return B_ENTRY_NOT_FOUND; + + // adjust the cookie here already so that we don't have + // to worry about it when returning early below + *cookie = *cookie + 1; + + if (*cookie == 1) { + // On first iteration, check if we can create more primary + // partitions. If this is not possible, we cannot create + // any extended partitions either. + for (int32 i = 0; i < 4; i++) { + PrimaryPartition* primary = fPartitionMap.PrimaryPartitionAt(i); + if (primary->IsEmpty()) { + *type = kPartitionTypeIntelPrimary; + return B_OK; + } + } + } else if (*cookie == 2) { + // On second iteration, check if we can create more primary + // partitions. Also check if there already is an extended + // partition, only if there is at least one empty and no + // extended partition, we can create an extended partition. + bool foundExtended = false; + bool foundEmpty = false; + for (int32 i = 0; i < 4; i++) { + PrimaryPartition* primary = fPartitionMap.PrimaryPartitionAt(i); + if (primary->IsEmpty()) + foundEmpty = true; + else if (primary->IsExtended()) + foundExtended = true; + } + if (foundEmpty && !foundExtended) { + *type = kPartitionTypeIntelExtended; + return B_OK; + } + } + + return B_ENTRY_NOT_FOUND; +} + + // GetPartitioningInfo status_t PartitionMapHandle::GetPartitioningInfo(BPartitioningInfo* info) diff --git a/src/add-ons/disk_systems/intel/PartitionMapAddOn.h b/src/add-ons/disk_systems/intel/PartitionMapAddOn.h index 04077a79b7..617dc23802 100644 --- a/src/add-ons/disk_systems/intel/PartitionMapAddOn.h +++ b/src/add-ons/disk_systems/intel/PartitionMapAddOn.h @@ -46,6 +46,10 @@ public: const BMutablePartition* child, uint32 mask); + virtual status_t GetNextSupportedType( + const BMutablePartition* child, + int32* cookie, BString* type); + virtual status_t GetPartitioningInfo(BPartitioningInfo* info); virtual status_t GetChildCreationParameterEditor(