From cc6edbdf8fa8faaf374c1809134995317f003c4c Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 3 Aug 2003 18:27:33 +0000 Subject: [PATCH] * Added VisitEachDescendant(). * Added {Add,Clear}Flags() which are more comfortable than SetFlags() in most cases. * On construction the `busy' and `descendant busy' flags are set. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4220 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/disk_device_manager/KPartition.h | 5 ++ .../core/disk_device_manager/KPartition.cpp | 57 ++++++++++++++----- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/headers/private/kernel/disk_device_manager/KPartition.h b/headers/private/kernel/disk_device_manager/KPartition.h index 82e1b073e2..4dbda759f8 100644 --- a/headers/private/kernel/disk_device_manager/KPartition.h +++ b/headers/private/kernel/disk_device_manager/KPartition.h @@ -16,6 +16,7 @@ class UserDataWriter; class KDiskDevice; class KDiskSystem; +class KPartitionVisitor; class KPhysicalPartition; class KShadowPartition; @@ -70,6 +71,8 @@ public: uint32 Status() const; void SetFlags(uint32 flags); // comprises the ones below + void AddFlags(uint32 flags); + void ClearFlags(uint32 flags); uint32 Flags() const; bool ContainsFileSystem() const; bool ContainsPartitioningSystem() const; @@ -132,6 +135,8 @@ public: int32 CountChildren() const; int32 CountDescendants() const; + KPartition *VisitEachDescendant(KPartitionVisitor *visitor); + // Shadow Partition virtual status_t CreateShadowPartition(); // creates a complete tree diff --git a/src/kernel/core/disk_device_manager/KPartition.cpp b/src/kernel/core/disk_device_manager/KPartition.cpp index 011a3714f8..b4fa17c317 100644 --- a/src/kernel/core/disk_device_manager/KPartition.cpp +++ b/src/kernel/core/disk_device_manager/KPartition.cpp @@ -16,6 +16,7 @@ #include "KDiskDeviceUtils.h" #include "KDiskSystem.h" #include "KPartition.h" +#include "KPartitionVisitor.h" #include "UserDataWriter.h" using namespace std; @@ -46,7 +47,7 @@ KPartition::KPartition(partition_id id) fPartitionData.child_count = 0; fPartitionData.index = -1; fPartitionData.status = B_PARTITION_UNRECOGNIZED; - fPartitionData.flags = 0; + fPartitionData.flags = B_PARTITION_BUSY | B_PARTITION_DESCENDANT_BUSY; fPartitionData.volume = -1; fPartitionData.name = NULL; fPartitionData.content_name = NULL; @@ -199,9 +200,9 @@ void KPartition::SetBusy(bool busy) { if (busy) - fPartitionData.flags |= B_PARTITION_BUSY; + SetFlags(B_PARTITION_BUSY); else - fPartitionData.flags &= ~(uint32)B_PARTITION_BUSY; + ClearFlags(B_PARTITION_BUSY); } // IsBusy @@ -216,9 +217,9 @@ void KPartition::SetDescendantBusy(bool busy) { if (busy) - fPartitionData.flags |= B_PARTITION_DESCENDANT_BUSY; + SetFlags(B_PARTITION_DESCENDANT_BUSY); else - fPartitionData.flags &= ~(uint32)B_PARTITION_DESCENDANT_BUSY; + ClearFlags(B_PARTITION_DESCENDANT_BUSY); } // IsDescendantBusy @@ -319,6 +320,20 @@ KPartition::SetFlags(uint32 flags) fPartitionData.flags = flags; } +// AddFlags +void +KPartition::AddFlags(uint32 flags) +{ + fPartitionData.flags |= flags; +} + +// ClearFlags +void +KPartition::ClearFlags(uint32 flags) +{ + fPartitionData.flags &= ~flags; +} + // Flags uint32 KPartition::Flags() const @@ -476,9 +491,9 @@ KPartition::SetVolumeID(dev_t volumeID) { fPartitionData.volume = volumeID; if (VolumeID() >= 0) - SetFlags(Flags() | B_PARTITION_MOUNTED); + AddFlags(B_PARTITION_MOUNTED); else - SetFlags(Flags() & ~(uint32)B_PARTITION_MOUNTED); + ClearFlags(B_PARTITION_MOUNTED); } // VolumeID @@ -538,7 +553,7 @@ KPartition::SetDevice(KDiskDevice *device) { fDevice = device; if (fDevice && fDevice->IsReadOnlyMedia()) - SetFlags(Flags() | B_PARTITION_READ_ONLY); + AddFlags(B_PARTITION_READ_ONLY); } // Device @@ -666,6 +681,23 @@ KPartition::CountDescendants() const return count; } +// VisitEachDescendant +KPartition * +KPartition::VisitEachDescendant(KPartitionVisitor *visitor) +{ + if (!visitor) + return NULL; + if (visitor->VisitPre(this)) + return this; + for (int32 i = 0; KPartition *child = ChildAt(i); i++) { + if (KPartition *result = child->VisitEachDescendant(visitor)) + return result; + } + if (visitor->VisitPost(this)) + return this; + return NULL; +} + // CreateShadowPartition status_t KPartition::CreateShadowPartition() @@ -699,9 +731,9 @@ KPartition::SetDiskSystem(KDiskSystem *diskSystem) if (fDiskSystem) { fPartitionData.content_type = fDiskSystem->PrettyName(); if (fDiskSystem->IsFileSystem()) - SetFlags(Flags() | B_PARTITION_FILE_SYSTEM); + AddFlags(B_PARTITION_FILE_SYSTEM); else - SetFlags(Flags() | B_PARTITION_PARTITIONING_SYSTEM); + AddFlags(B_PARTITION_PARTITIONING_SYSTEM); } } @@ -826,10 +858,9 @@ KPartition::UninitializeContents(bool logChanges) // status SetStatus(B_PARTITION_UNINITIALIZED); // flags - SetFlags(Flags() & ~uint32(B_PARTITION_FILE_SYSTEM - | B_PARTITION_PARTITIONING_SYSTEM)); + ClearFlags(B_PARTITION_FILE_SYSTEM | B_PARTITION_PARTITIONING_SYSTEM); if (!Device()->IsReadOnlyMedia()) - SetFlags(Flags() & ~(uint32)B_PARTITION_READ_ONLY); + ClearFlags(B_PARTITION_READ_ONLY); // log changes if (logChanges) { Changed(flags, B_PARTITION_CHANGED_DEFRAGMENTATION