From 2128ea4f31e90c6ee53abab1637540b81a3e381a Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 5 Nov 2007 00:30:14 +0000 Subject: [PATCH] Added IsBusy(bool) version, which optionally also checks the descendants. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22831 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/disk_device_manager/KPartition.h | 1 + .../kernel/disk_device_manager/KPartition.cpp | 62 ++++++++++++------- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/headers/private/kernel/disk_device_manager/KPartition.h b/headers/private/kernel/disk_device_manager/KPartition.h index d9162aa6f3..e4e131c42f 100644 --- a/headers/private/kernel/disk_device_manager/KPartition.h +++ b/headers/private/kernel/disk_device_manager/KPartition.h @@ -52,6 +52,7 @@ public: void SetBusy(bool busy); bool IsBusy() const; + bool IsBusy(bool includeDescendants); bool CheckAndMarkBusy(bool includeDescendants); void UnmarkBusy(bool includeDescendants); diff --git a/src/system/kernel/disk_device_manager/KPartition.cpp b/src/system/kernel/disk_device_manager/KPartition.cpp index c698f4fee0..262d6ccd79 100644 --- a/src/system/kernel/disk_device_manager/KPartition.cpp +++ b/src/system/kernel/disk_device_manager/KPartition.cpp @@ -247,23 +247,32 @@ KPartition::IsBusy() const } +// IsBusy +bool +KPartition::IsBusy(bool includeDescendants) +{ + if (!includeDescendants) + return IsBusy(); + + struct IsBusyVisitor : KPartitionVisitor { + virtual bool VisitPre(KPartition* partition) + { + return partition->IsBusy(); + } + } checkVisitor; + + return VisitEachDescendant(&checkVisitor) != NULL; +} + + // CheckAndMarkBusy bool KPartition::CheckAndMarkBusy(bool includeDescendants) { + if (IsBusy(includeDescendants)) + return false; + if (includeDescendants) { - // check - struct IsBusyVisitor : KPartitionVisitor { - virtual bool VisitPre(KPartition* partition) - { - return partition->IsBusy(); - } - } checkVisitor; - - if (VisitEachDescendant(&checkVisitor)) - return false; - - // mark busy struct MarkBusyVisitor : KPartitionVisitor { virtual bool VisitPre(KPartition* partition) { @@ -273,12 +282,8 @@ KPartition::CheckAndMarkBusy(bool includeDescendants) } markVisitor; VisitEachDescendant(&markVisitor); - } else { - if (IsBusy()) - return false; - + } else SetBusy(true); - } return true; } @@ -1014,65 +1019,78 @@ KPartition::ChangeCounter() const return fChangeCounter; } + // UninitializeContents status_t KPartition::UninitializeContents(bool logChanges) { if (DiskSystem()) { uint32 flags = B_PARTITION_CHANGED_INITIALIZATION - | B_PARTITION_CHANGED_CONTENT_TYPE - | B_PARTITION_CHANGED_STATUS - | B_PARTITION_CHANGED_FLAGS; + | B_PARTITION_CHANGED_CONTENT_TYPE + | B_PARTITION_CHANGED_STATUS + | B_PARTITION_CHANGED_FLAGS; + // children if (CountChildren() > 0) { if (!RemoveAllChildren()) return B_ERROR; flags |= B_PARTITION_CHANGED_CHILDREN; } + // volume if (VolumeID() >= 0) { +// TODO: Unmount? SetVolumeID(-1); flags |= B_PARTITION_CHANGED_VOLUME; } + // content name if (ContentName()) { SetContentName(NULL); flags |= B_PARTITION_CHANGED_CONTENT_NAME; } + // content parameters if (ContentParameters()) { SetContentParameters(NULL); flags |= B_PARTITION_CHANGED_CONTENT_PARAMETERS; } + // content size if (ContentSize() > 0) { SetContentSize(0); flags |= B_PARTITION_CHANGED_CONTENT_SIZE; } + // block size if (Parent() && Parent()->BlockSize() != BlockSize()) { SetBlockSize(Parent()->BlockSize()); flags |= B_PARTITION_CHANGED_BLOCK_SIZE; } + // disk system DiskSystem()->FreeContentCookie(this); SetDiskSystem(NULL); + // status SetStatus(B_PARTITION_UNINITIALIZED); + // flags ClearFlags(B_PARTITION_FILE_SYSTEM | B_PARTITION_PARTITIONING_SYSTEM); if (!Device()->IsReadOnlyMedia()) ClearFlags(B_PARTITION_READ_ONLY); + // log changes if (logChanges) { Changed(flags, B_PARTITION_CHANGED_DEFRAGMENTATION - | B_PARTITION_CHANGED_CHECK - | B_PARTITION_CHANGED_REPAIR); + | B_PARTITION_CHANGED_CHECK | B_PARTITION_CHANGED_REPAIR); } } + return B_OK; } + // SetAlgorithmData void KPartition::SetAlgorithmData(uint32 data)