* Got rid of the B_PARTITION_DESCENDANT_BUSY flag.

* Added CheckAndMarkBusy() and UnmarkBusy() methods to KPartition.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22801 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2007-11-02 00:29:46 +00:00
parent 8354dac78e
commit 53715fe060
6 changed files with 59 additions and 33 deletions
-1
View File
@@ -21,7 +21,6 @@ enum {
B_PARTITION_READ_ONLY = 0x08, B_PARTITION_READ_ONLY = 0x08,
B_PARTITION_MOUNTED = 0x10, // needed? B_PARTITION_MOUNTED = 0x10, // needed?
B_PARTITION_BUSY = 0x20, B_PARTITION_BUSY = 0x20,
B_PARTITION_DESCENDANT_BUSY = 0x40,
}; };
// partition statuses // partition statuses
@@ -52,12 +52,8 @@ public:
void SetBusy(bool busy); void SetBusy(bool busy);
bool IsBusy() const; bool IsBusy() const;
// == jobs which may affect this partition are scheduled/in progress bool CheckAndMarkBusy(bool includeDescendants);
void SetDescendantBusy(bool busy); void UnmarkBusy(bool includeDescendants);
bool IsDescendantBusy() const;
// == jobs which may affect a descendant of this partition are
// scheduled/in progress; IsBusy() => IsDescendantBusy()
// In the userland API, both can probably be mapped to one flag.
void SetOffset(off_t offset); void SetOffset(off_t offset);
off_t Offset() const; // 0 for devices off_t Offset() const; // 0 for devices
+1 -2
View File
@@ -197,8 +197,7 @@ BPartition::IsMounted() const
bool bool
BPartition::IsBusy() const BPartition::IsBusy() const
{ {
return _PartitionData()->flags return _PartitionData()->flags & B_PARTITION_BUSY;
& (B_PARTITION_BUSY | B_PARTITION_DESCENDANT_BUSY);
} }
@@ -1032,16 +1032,7 @@ KDiskDeviceManager::_ScanPartition(KPartition *partition, bool async)
// TODO: This is not quite correct here. Partitions are created marked "busy", // TODO: This is not quite correct here. Partitions are created marked "busy",
// hence the one creating it should be responsible for clearing the flag, not // hence the one creating it should be responsible for clearing the flag, not
// us. // us.
struct UnmarkBusyVisitor : KPartitionVisitor { partition->UnmarkBusy(true);
virtual bool VisitPre(KPartition* partition)
{
partition->ClearFlags(B_PARTITION_BUSY
| B_PARTITION_DESCENDANT_BUSY);
return false;
}
} visitor;
partition->VisitEachDescendant(&visitor);
return error; return error;
} }
@@ -58,7 +58,7 @@ KPartition::KPartition(partition_id id)
fPartitionData.child_count = 0; fPartitionData.child_count = 0;
fPartitionData.index = -1; fPartitionData.index = -1;
fPartitionData.status = B_PARTITION_UNRECOGNIZED; fPartitionData.status = B_PARTITION_UNRECOGNIZED;
fPartitionData.flags = B_PARTITION_BUSY | B_PARTITION_DESCENDANT_BUSY; fPartitionData.flags = B_PARTITION_BUSY;
fPartitionData.volume = -1; fPartitionData.volume = -1;
fPartitionData.mount_cookie = NULL; fPartitionData.mount_cookie = NULL;
fPartitionData.name = NULL; fPartitionData.name = NULL;
@@ -238,6 +238,7 @@ KPartition::SetBusy(bool busy)
ClearFlags(B_PARTITION_BUSY); ClearFlags(B_PARTITION_BUSY);
} }
// IsBusy // IsBusy
bool bool
KPartition::IsBusy() const KPartition::IsBusy() const
@@ -245,23 +246,63 @@ KPartition::IsBusy() const
return (fPartitionData.flags & B_PARTITION_BUSY); return (fPartitionData.flags & B_PARTITION_BUSY);
} }
// SetDescendantBusy
void // CheckAndMarkBusy
KPartition::SetDescendantBusy(bool busy) bool
KPartition::CheckAndMarkBusy(bool includeDescendants)
{ {
if (busy) if (includeDescendants) {
SetFlags(B_PARTITION_DESCENDANT_BUSY); // check
else struct IsBusyVisitor : KPartitionVisitor {
ClearFlags(B_PARTITION_DESCENDANT_BUSY); virtual bool VisitPre(KPartition* partition)
{
return partition->IsBusy();
}
} checkVisitor;
if (VisitEachDescendant(&checkVisitor))
return false;
// mark busy
struct MarkBusyVisitor : KPartitionVisitor {
virtual bool VisitPre(KPartition* partition)
{
partition->AddFlags(B_PARTITION_BUSY);
return false;
}
} markVisitor;
VisitEachDescendant(&markVisitor);
} else {
if (IsBusy())
return false;
SetBusy(true);
}
return true;
} }
// IsDescendantBusy
bool // UnmarkBusy
KPartition::IsDescendantBusy() const void
KPartition::UnmarkBusy(bool includeDescendants)
{ {
return (fPartitionData.flags & B_PARTITION_DESCENDANT_BUSY); if (includeDescendants) {
struct UnmarkBusyVisitor : KPartitionVisitor {
virtual bool VisitPre(KPartition* partition)
{
partition->ClearFlags(B_PARTITION_BUSY);
return false;
}
} visitor;
VisitEachDescendant(&visitor);
} else
SetBusy(false);
} }
// SetOffset // SetOffset
void void
KPartition::SetOffset(off_t offset) KPartition::SetOffset(off_t offset)
+2 -2
View File
@@ -5387,7 +5387,7 @@ fs_mount(char *path, const char *device, const char *fsName, uint32 flags,
if (partition) { if (partition) {
// make sure, that the partition is not busy // make sure, that the partition is not busy
if (partition->IsBusy() || partition->IsDescendantBusy()) { if (partition->IsBusy()) {
TRACE(("fs_mount(): Partition is busy.\n")); TRACE(("fs_mount(): Partition is busy.\n"));
return B_BUSY; return B_BUSY;
} }
@@ -5601,7 +5601,7 @@ fs_unmount(char *path, uint32 flags, bool kernel)
// make sure, that the partition is not busy // make sure, that the partition is not busy
if (partition) { if (partition) {
if (partition->IsBusy() || partition->IsDescendantBusy()) { if (partition->IsBusy()) {
TRACE(("fs_unmount(): Partition is busy.\n")); TRACE(("fs_unmount(): Partition is busy.\n"));
return B_BUSY; return B_BUSY;
} }