diff --git a/headers/private/storage/Partition.h b/headers/private/storage/Partition.h index 53737e8e12..037ca07ca9 100644 --- a/headers/private/storage/Partition.h +++ b/headers/private/storage/Partition.h @@ -24,6 +24,10 @@ class BVolume; struct user_partition_data; +namespace BPrivate { + class DiskDeviceJobGenerator; +} + class BPartition { public: // Partition Info @@ -71,6 +75,7 @@ public: BPartition* Parent() const; BPartition* ChildAt(int32 index) const; int32 CountChildren() const; + int32 CountDescendants() const; BPartition* FindDescendant(partition_id id) const; status_t GetPartitioningInfo( @@ -187,7 +192,9 @@ private: bool* updated); void _RemoveChild(int32 index); - int32 _CountDescendants() const; + BPartition* _ChildAt(int32 index) const; + int32 _CountChildren() const; + int32 _Level() const; virtual bool _AcceptVisitor(BDiskDeviceVisitor* visitor, int32 level); @@ -212,6 +219,7 @@ private: friend class BDiskDevice; friend class BDiskSystem; friend class BMutablePartition; + friend class BPrivate::DiskDeviceJobGenerator; BDiskDevice* fDevice; BPartition* fParent; diff --git a/src/kits/storage/disk_device/Partition.cpp b/src/kits/storage/disk_device/Partition.cpp index 56cc27ef57..e25ac70113 100644 --- a/src/kits/storage/disk_device/Partition.cpp +++ b/src/kits/storage/disk_device/Partition.cpp @@ -602,9 +602,7 @@ BPartition::ChildAt(int32 index) const return child ? child->Partition() : NULL; } - if (index < 0 || index >= fPartitionData->child_count) - return NULL; - return (BPartition*)fPartitionData->children[index]->user_data; + return _ChildAt(index); } @@ -615,7 +613,18 @@ BPartition::CountChildren() const if (fDelegate) return fDelegate->CountChildren(); - return fPartitionData->child_count; + return _CountChildren(); +} + + +// CountDescendants +int32 +BPartition::CountDescendants() const +{ + int32 count = 1; + for (int32 i = 0; BPartition* child = ChildAt(i); i++) + count += child->CountDescendants(); + return count; } @@ -624,7 +633,7 @@ BPartition* BPartition::FindDescendant(partition_id id) const { IDFinderVisitor visitor(id); - return const_cast(this)->VisitEachDescendant(&visitor); + return VisitEachDescendant(&visitor); } @@ -1283,6 +1292,7 @@ BPartition::_Unset() fDevice = NULL; fParent = NULL; fPartitionData = NULL; + fDelegate = NULL; } @@ -1397,14 +1407,21 @@ BPartition::_RemoveChild(int32 index) } -// _CountDescendants -int32 -BPartition::_CountDescendants() const +// _ChildAt +BPartition* +BPartition::_ChildAt(int32 index) const { - int32 count = 1; - for (int32 i = 0; BPartition* child = ChildAt(i); i++) - count += child->_CountDescendants(); - return count; + if (index < 0 || index >= fPartitionData->child_count) + return NULL; + return (BPartition*)fPartitionData->children[index]->user_data; +} + + +// _CountChildren +int32 +BPartition::_CountChildren() const +{ + return fPartitionData->child_count; } @@ -1511,9 +1528,9 @@ BPartition::_CreateDelegates() return error; // create child delegates - int32 count = fPartitionData->child_count; + int32 count = _CountChildren(); for (int32 i = 0; i < count; i++) { - BPartition* child = (BPartition*)fPartitionData->children[i]->user_data; + BPartition* child = _ChildAt(i); error = child->_CreateDelegates(); if (error != B_OK) return error;