* Reimplemented BDiskDevice::IsModified()/
{Prepare,Commit,Cancel}Modifications() using the userland add-on backend. IsModified() and CommitModifications() are little more than stubs ATM. * Made BPartition::VisitEachChild()/VisitEachDescendant() const. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22602 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
e4289a54e3
commit
27d7c36659
@ -76,9 +76,10 @@ public:
|
|||||||
status_t GetPartitioningInfo(
|
status_t GetPartitioningInfo(
|
||||||
BPartitioningInfo* info) const;
|
BPartitioningInfo* info) const;
|
||||||
|
|
||||||
BPartition* VisitEachChild(BDiskDeviceVisitor* visitor);
|
BPartition* VisitEachChild(BDiskDeviceVisitor* visitor)
|
||||||
|
const;
|
||||||
virtual BPartition* VisitEachDescendant(
|
virtual BPartition* VisitEachDescendant(
|
||||||
BDiskDeviceVisitor* visitor);
|
BDiskDeviceVisitor* visitor) const;
|
||||||
|
|
||||||
// Self Modification
|
// Self Modification
|
||||||
|
|
||||||
@ -205,6 +206,11 @@ private:
|
|||||||
bool _SupportsChildOperation(const BPartition* child,
|
bool _SupportsChildOperation(const BPartition* child,
|
||||||
uint32 flag) const;
|
uint32 flag) const;
|
||||||
|
|
||||||
|
status_t _CreateDelegates();
|
||||||
|
status_t _InitDelegates();
|
||||||
|
void _DeleteDelegates();
|
||||||
|
bool _IsModified() const;
|
||||||
|
|
||||||
friend class BDiskDevice;
|
friend class BDiskDevice;
|
||||||
friend class BDiskSystem;
|
friend class BDiskSystem;
|
||||||
friend class BMutablePartition;
|
friend class BMutablePartition;
|
||||||
|
@ -188,8 +188,22 @@ BDiskDevice::GetPath(BPath* path) const
|
|||||||
bool
|
bool
|
||||||
BDiskDevice::IsModified() const
|
BDiskDevice::IsModified() const
|
||||||
{
|
{
|
||||||
return (InitCheck() == B_OK && _IsShadow()
|
if (InitCheck() != B_OK)
|
||||||
&& _kern_is_disk_device_modified(ID()));
|
return false;
|
||||||
|
|
||||||
|
struct IsModifiedVisitor : public BDiskDeviceVisitor {
|
||||||
|
virtual bool Visit(BDiskDevice *device)
|
||||||
|
{
|
||||||
|
return Visit(device, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool Visit(BPartition *partition, int32 level)
|
||||||
|
{
|
||||||
|
return partition->_IsModified();
|
||||||
|
}
|
||||||
|
} visitor;
|
||||||
|
|
||||||
|
return (VisitEachDescendant(&visitor) != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -209,20 +223,19 @@ BDiskDevice::PrepareModifications()
|
|||||||
status_t error = InitCheck();
|
status_t error = InitCheck();
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
if (_IsShadow())
|
if (fDelegate)
|
||||||
return B_ERROR;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
// ask kernel to prepare for modifications
|
// recursively create the delegates
|
||||||
error = _kern_prepare_disk_device_modifications(ID());
|
error = _CreateDelegates();
|
||||||
|
|
||||||
|
// init them
|
||||||
|
if (error == B_OK)
|
||||||
|
error = _InitDelegates();
|
||||||
|
|
||||||
|
// delete all of them, if something went wrong
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
_DeleteDelegates();
|
||||||
|
|
||||||
// update
|
|
||||||
error = _Update(true, NULL);
|
|
||||||
if (error != B_OK) {
|
|
||||||
// bad -- cancelling the modifications is all we can do
|
|
||||||
_kern_cancel_disk_device_modifications(ID());
|
|
||||||
}
|
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@ -242,15 +255,14 @@ BDiskDevice::CommitModifications(bool synchronously,
|
|||||||
status_t error = InitCheck();
|
status_t error = InitCheck();
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
if (!_IsShadow())
|
|
||||||
|
if (!fDelegate)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
// TODO: Get port and token from the progressMessenger
|
// TODO: Implement!
|
||||||
// TODO: Respect "synchronously"!
|
|
||||||
port_id port = -1;
|
_DeleteDelegates();
|
||||||
int32 token = -1;
|
|
||||||
error = _kern_commit_disk_device_modifications(ID(), port, token,
|
|
||||||
receiveCompleteProgressUpdates);
|
|
||||||
if (error == B_OK)
|
if (error == B_OK)
|
||||||
error = _SetTo(ID(), true, false, 0);
|
error = _SetTo(ID(), true, false, 0);
|
||||||
|
|
||||||
@ -269,10 +281,12 @@ BDiskDevice::CancelModifications()
|
|||||||
status_t error = InitCheck();
|
status_t error = InitCheck();
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
if (!_IsShadow())
|
|
||||||
|
if (!fDelegate)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
error = _kern_cancel_disk_device_modifications(ID());
|
_DeleteDelegates();
|
||||||
|
|
||||||
if (error == B_OK)
|
if (error == B_OK)
|
||||||
error = _SetTo(ID(), true, false, 0);
|
error = _SetTo(ID(), true, false, 0);
|
||||||
|
|
||||||
@ -317,8 +331,7 @@ BDiskDevice::_GetData(partition_id id, bool deviceOnly, bool shadow,
|
|||||||
status_t error = B_OK;
|
status_t error = B_OK;
|
||||||
do {
|
do {
|
||||||
error = _kern_get_disk_device_data(id, deviceOnly, shadow,
|
error = _kern_get_disk_device_data(id, deviceOnly, shadow,
|
||||||
(user_disk_device_data*)buffer,
|
(user_disk_device_data*)buffer, bufferSize, &neededSize);
|
||||||
bufferSize, &neededSize);
|
|
||||||
if (error == B_BUFFER_OVERFLOW) {
|
if (error == B_BUFFER_OVERFLOW) {
|
||||||
// buffer to small re-allocate it
|
// buffer to small re-allocate it
|
||||||
if (buffer)
|
if (buffer)
|
||||||
@ -346,7 +359,7 @@ BDiskDevice::_GetData(partition_id id, bool deviceOnly, bool shadow,
|
|||||||
// _SetTo
|
// _SetTo
|
||||||
status_t
|
status_t
|
||||||
BDiskDevice::_SetTo(partition_id id, bool deviceOnly, bool shadow,
|
BDiskDevice::_SetTo(partition_id id, bool deviceOnly, bool shadow,
|
||||||
size_t neededSize)
|
size_t neededSize)
|
||||||
{
|
{
|
||||||
Unset();
|
Unset();
|
||||||
|
|
||||||
|
@ -641,7 +641,7 @@ BPartition::GetPartitioningInfo(BPartitioningInfo* info) const
|
|||||||
|
|
||||||
// VisitEachChild
|
// VisitEachChild
|
||||||
BPartition*
|
BPartition*
|
||||||
BPartition::VisitEachChild(BDiskDeviceVisitor* visitor)
|
BPartition::VisitEachChild(BDiskDeviceVisitor* visitor) const
|
||||||
{
|
{
|
||||||
if (visitor) {
|
if (visitor) {
|
||||||
int32 level = _Level();
|
int32 level = _Level();
|
||||||
@ -656,10 +656,10 @@ BPartition::VisitEachChild(BDiskDeviceVisitor* visitor)
|
|||||||
|
|
||||||
// VisitEachDescendant
|
// VisitEachDescendant
|
||||||
BPartition*
|
BPartition*
|
||||||
BPartition::VisitEachDescendant(BDiskDeviceVisitor* visitor)
|
BPartition::VisitEachDescendant(BDiskDeviceVisitor* visitor) const
|
||||||
{
|
{
|
||||||
if (visitor)
|
if (visitor)
|
||||||
return _VisitEachDescendant(visitor);
|
return const_cast<BPartition*>(this)->_VisitEachDescendant(visitor);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1500,3 +1500,85 @@ BPartition::_SupportsChildOperation(const BPartition* child, uint32 flag) const
|
|||||||
return supported & flag;
|
return supported & flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// _CreateDelegates
|
||||||
|
status_t
|
||||||
|
BPartition::_CreateDelegates()
|
||||||
|
{
|
||||||
|
if (fDelegate || !fPartitionData)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
// create and init delegate
|
||||||
|
fDelegate = new(nothrow) Delegate(this);
|
||||||
|
if (!fDelegate)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
status_t error = fDelegate->InitHierarchy(fPartitionData,
|
||||||
|
fParent ? fParent->fDelegate : NULL);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
// create child delegates
|
||||||
|
int32 count = fPartitionData->child_count;
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
|
BPartition* child = (BPartition*)fPartitionData->children[i]->user_data;
|
||||||
|
error = child->_CreateDelegates();
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// _InitDelegates
|
||||||
|
status_t
|
||||||
|
BPartition::_InitDelegates()
|
||||||
|
{
|
||||||
|
// init delegate
|
||||||
|
status_t error = fDelegate->InitAfterHierarchy();
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
// recursively init child delegates
|
||||||
|
int32 count = CountChildren();
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
|
error = ChildAt(i)->_InitDelegates();
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// _DeleteDelegates
|
||||||
|
void
|
||||||
|
BPartition::_DeleteDelegates()
|
||||||
|
{
|
||||||
|
// recursively delete child delegates
|
||||||
|
int32 count = CountChildren();
|
||||||
|
for (int32 i = count - 1; i >= 0; i--)
|
||||||
|
ChildAt(i)->_DeleteDelegates();
|
||||||
|
|
||||||
|
// delete delegate
|
||||||
|
delete fDelegate;
|
||||||
|
fDelegate = NULL;
|
||||||
|
|
||||||
|
// Commit suicide, if the delegate was our only link to reality (i.e.
|
||||||
|
// there's no physically existing partition we represent).
|
||||||
|
if (fPartitionData == NULL)
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// _IsModified
|
||||||
|
bool
|
||||||
|
BPartition::_IsModified() const
|
||||||
|
{
|
||||||
|
if (!fDelegate)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// TODO: Implement!
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user