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
This commit is contained in:
Ingo Weinhold
2007-11-05 00:30:14 +00:00
parent a56a0c276a
commit 2128ea4f31
2 changed files with 41 additions and 22 deletions
@@ -52,6 +52,7 @@ public:
void SetBusy(bool busy);
bool IsBusy() const;
bool IsBusy(bool includeDescendants);
bool CheckAndMarkBusy(bool includeDescendants);
void UnmarkBusy(bool includeDescendants);
@@ -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)