* Initialization of BPartition::Delegate is now two-phased. The first phase

builds the object hierarchy, the second will (in case of MutableDelegate)
  let the disk systems do their initialization. This way the disk systems
  already find a fully functional object hierarchy they can work with.
* Child creation also takes a partition name as a parameter, now.
* Implemented BMutablePartition child creation/deletion.
* The BDiskSystemAddOn/BPartitionHandle::Validate*() methods return a
  status_t instead of a bool, now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22540 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2007-10-13 21:29:33 +00:00
parent 103ca6a3ad
commit 350043e707
6 changed files with 208 additions and 84 deletions

View File

@ -34,7 +34,7 @@ public:
virtual status_t GetInitializationParameterEditor(
const BMutablePartition* partition,
BDiskDeviceParameterEditor** editor);
virtual bool ValidateInitialize(
virtual status_t ValidateInitialize(
const BMutablePartition* partition,
BString* name, const char* parameters);
virtual status_t Initialize(BMutablePartition* partition,
@ -77,30 +77,30 @@ public:
virtual status_t Defragment();
virtual status_t Repair(bool checkOnly);
virtual bool ValidateResize(off_t* size);
virtual bool ValidateResizeChild(
virtual status_t ValidateResize(off_t* size);
virtual status_t ValidateResizeChild(
const BMutablePartition* child,
off_t* size);
virtual status_t Resize(off_t size);
virtual status_t ResizeChild(BMutablePartition* child,
off_t size);
virtual bool ValidateMove(off_t* offset);
virtual bool ValidateMoveChild(
virtual status_t ValidateMove(off_t* offset);
virtual status_t ValidateMoveChild(
const BMutablePartition* child,
off_t* offset);
virtual status_t Move(off_t offset);
virtual status_t MoveChild(BMutablePartition* child,
off_t offset);
virtual bool ValidateSetContentName(BString* name);
virtual bool ValidateSetName(const BMutablePartition* child,
virtual status_t ValidateSetContentName(BString* name);
virtual status_t ValidateSetName(const BMutablePartition* child,
BString* name);
virtual status_t SetContentName(const char* name);
virtual status_t SetName(BMutablePartition* child,
const char* name);
virtual bool ValidateSetType(const BMutablePartition* child,
virtual status_t ValidateSetType(const BMutablePartition* child,
const char* type);
virtual status_t SetType(BMutablePartition* child,
const char* type);
@ -110,9 +110,9 @@ public:
virtual status_t GetParameterEditor(
const BMutablePartition* child,
BDiskDeviceParameterEditor** editor);
virtual bool ValidateSetContentParameters(
virtual status_t ValidateSetContentParameters(
const char* parameters);
virtual bool ValidateSetParameters(
virtual status_t ValidateSetParameters(
const BMutablePartition* child,
const char* parameters);
virtual status_t SetContentParameters(const char* parameters);
@ -122,11 +122,12 @@ public:
virtual status_t GetChildCreationParameterEditor(
const char* type,
BDiskDeviceParameterEditor** editor);
virtual bool ValidateCreateChild(off_t* offset,
virtual status_t ValidateCreateChild(off_t* offset,
off_t* size, const char* type,
const char* parameters);
BString* name, const char* parameters);
virtual status_t CreateChild(off_t offset, off_t size,
const char* type, const char* parameters,
const char* type, const char* name,
const char* parameters,
BMutablePartition** child);
virtual status_t DeleteChild(BMutablePartition* child);

View File

@ -55,10 +55,16 @@ public:
status_t CreateChild(int32 index,
BMutablePartition** child);
status_t CreateChild(int32 index, const char* type,
const char* name, const char* parameters,
BMutablePartition** child);
status_t DeleteChild(int32 index);
status_t DeleteChild(BMutablePartition* child);
BMutablePartition* Parent() const;
BMutablePartition* ChildAt(int32 index) const;
int32 CountChildren() const;
int32 IndexOfChild(BMutablePartition* child) const;
// for the partitioning system managing the parent
void* ChildCookie() const;
@ -69,7 +75,8 @@ private:
BPartition::MutableDelegate* delegate);
~BMutablePartition();
status_t Init(const user_partition_data* partitionData);
status_t Init(const user_partition_data* partitionData,
BMutablePartition* parent);
const user_partition_data* PartitionData() const;
@ -80,6 +87,7 @@ private:
BPartition::MutableDelegate* fDelegate;
user_partition_data* fData;
BMutablePartition* fParent;
BList fChildren;
void* fChildCookie;
};

View File

@ -59,11 +59,11 @@ BDiskSystemAddOn::GetInitializationParameterEditor(
// ValidateInitialize
bool
status_t
BDiskSystemAddOn::ValidateInitialize(const BMutablePartition* partition,
BString* name, const char* parameters)
{
return false;
return B_BAD_VALUE;
}
@ -176,19 +176,19 @@ BPartitionHandle::Repair(bool checkOnly)
// ValidateResize
bool
status_t
BPartitionHandle::ValidateResize(off_t* size)
{
return false;
return B_BAD_VALUE;
}
// ValidateResizeChild
bool
status_t
BPartitionHandle::ValidateResizeChild(const BMutablePartition* child,
off_t* size)
{
return false;
return B_BAD_VALUE;
}
@ -209,21 +209,21 @@ BPartitionHandle::ResizeChild(BMutablePartition* child, off_t size)
// ValidateMove
bool
status_t
BPartitionHandle::ValidateMove(off_t* offset)
{
// Usually moving a disk system is a no-op for the content disk system,
// so we default to true here.
return true;
return B_OK;
}
// ValidateMoveChild
bool
status_t
BPartitionHandle::ValidateMoveChild(const BMutablePartition* child,
off_t* offset)
{
return false;
return B_BAD_VALUE;
}
@ -246,19 +246,19 @@ BPartitionHandle::MoveChild(BMutablePartition* child, off_t offset)
// ValidateSetContentName
bool
status_t
BPartitionHandle::ValidateSetContentName(BString* name)
{
return false;
return B_BAD_VALUE;
}
// ValidateSetName
bool
status_t
BPartitionHandle::ValidateSetName(const BMutablePartition* child,
BString* name)
{
return false;
return B_BAD_VALUE;
}
@ -279,11 +279,11 @@ BPartitionHandle::SetName(BMutablePartition* child, const char* name)
// ValidateSetType
bool
status_t
BPartitionHandle::ValidateSetType(const BMutablePartition* child,
const char* type)
{
return false;
return B_BAD_VALUE;
}
@ -313,19 +313,19 @@ BPartitionHandle::GetParameterEditor(const BMutablePartition* child,
// ValidateSetContentParameters
bool
status_t
BPartitionHandle::ValidateSetContentParameters(const char* parameters)
{
return false;
return B_BAD_VALUE;
}
// ValidateSetParameters
bool
status_t
BPartitionHandle::ValidateSetParameters(const BMutablePartition* child,
const char* parameters)
{
return false;
return B_BAD_VALUE;
}
@ -356,18 +356,18 @@ BPartitionHandle::GetChildCreationParameterEditor(const char* type,
// ValidateCreateChild
bool
status_t
BPartitionHandle::ValidateCreateChild(off_t* offset, off_t* size,
const char* type, const char* parameters)
const char* type, BString* name, const char* parameters)
{
return false;
return B_BAD_VALUE;
}
// CreateChild
status_t
BPartitionHandle::CreateChild(off_t offset, off_t size, const char* type,
const char* parameters, BMutablePartition** child)
const char* name, const char* parameters, BMutablePartition** child)
{
return B_NOT_SUPPORTED;
}

View File

@ -10,8 +10,12 @@
#include <new>
#include <Partition.h>
#include <disk_device_manager/ddm_userland_interface.h>
#include "PartitionDelegate.h"
using std::nothrow;
@ -244,10 +248,68 @@ BMutablePartition::SetContentParameters(const char* parameters)
// CreateChild
status_t
BMutablePartition::CreateChild(int32 index, BMutablePartition** child)
BMutablePartition::CreateChild(int32 index, BMutablePartition** _child)
{
// TODO: ...
return B_ERROR;
if (index < 0)
index = fChildren.CountItems();
else if (index > fChildren.CountItems())
return B_BAD_VALUE;
// create the BPartition
BPartition* partition = new(nothrow) BPartition;
if (!partition)
return B_NO_MEMORY;
// create the MutableDelegate
BPartition::MutableDelegate* delegate
= new(nothrow) BPartition::MutableDelegate(partition);
if (!delegate) {
delete partition;
return B_NO_MEMORY;
}
partition->fDelegate = delegate;
// TODO: Any further initialization required?
// add the child
BMutablePartition* child = delegate->MutablePartition();
if (!fChildren.AddItem(child, index)) {
delete partition;
return B_NO_MEMORY;
}
child->fParent = this;
*_child = child;
return B_OK;
}
// CreateChild
status_t
BMutablePartition::CreateChild(int32 index, const char* type, const char* name,
const char* parameters, BMutablePartition** _child)
{
// create the child
BMutablePartition* child;
status_t error = CreateChild(index, &child);
if (error != B_OK)
return error;
// set the name, type, and parameters
error = SetType(type);
if (error == B_OK)
error = SetName(name);
if (error == B_OK)
error = SetParameters(parameters);
// cleanup on error
if (error != B_OK) {
DeleteChild(child);
return error;
}
*_child = child;
return B_OK;
}
@ -255,8 +317,29 @@ BMutablePartition::CreateChild(int32 index, BMutablePartition** child)
status_t
BMutablePartition::DeleteChild(int32 index)
{
// TODO: ...
return B_ERROR;
BMutablePartition* child = (BMutablePartition*)fChildren.RemoveItem(index);
if (!child)
return B_BAD_VALUE;
delete child->fDelegate->Partition();
return B_OK;
}
// DeleteChild
status_t
BMutablePartition::DeleteChild(BMutablePartition* child)
{
return DeleteChild(IndexOfChild(child));
}
// Parent
BMutablePartition*
BMutablePartition::Parent() const
{
return fParent;
}
@ -276,6 +359,16 @@ BMutablePartition::CountChildren() const
}
// IndexOfChild
int32
BMutablePartition::IndexOfChild(BMutablePartition* child) const
{
if (!child)
return -1;
return fChildren.IndexOf(child);
}
// ChildCookie
void*
BMutablePartition::ChildCookie() const
@ -296,6 +389,7 @@ BMutablePartition::SetChildCookie(void* cookie)
BMutablePartition::BMutablePartition(BPartition::MutableDelegate* delegate)
: fDelegate(delegate),
fData(NULL),
fParent(NULL),
fChildCookie(NULL)
{
}
@ -303,8 +397,17 @@ BMutablePartition::BMutablePartition(BPartition::MutableDelegate* delegate)
// Init
status_t
BMutablePartition::Init(const user_partition_data* partitionData)
BMutablePartition::Init(const user_partition_data* partitionData,
BMutablePartition* parent)
{
fParent = parent;
// add to the parent's child list
if (fParent) {
if (!fParent->fChildren.AddItem(this))
return B_NO_MEMORY;
}
// allocate data structure
fData = new(nothrow) user_partition_data;
if (!fData)

View File

@ -61,14 +61,21 @@ BPartition::MutableDelegate::MutablePartition() const
}
// Init
// InitHierarchy
status_t
BPartition::MutableDelegate::Init(const user_partition_data* partitionData)
BPartition::MutableDelegate::InitHierarchy(
const user_partition_data* partitionData, Delegate* _parent)
{
status_t error = fMutablePartition.Init(partitionData);
if (error != B_OK)
return error;
MutableDelegate* parent = dynamic_cast<MutableDelegate*>(_parent);
return fMutablePartition.Init(partitionData,
parent ? &parent->fMutablePartition : NULL);
}
// InitAfterHierarchy
status_t
BPartition::MutableDelegate::InitAfterHierarchy()
{
if (!fMutablePartition.ContentType())
return B_OK;
@ -80,13 +87,13 @@ BPartition::MutableDelegate::Init(const user_partition_data* partitionData)
return B_ENTRY_NOT_FOUND;
BPartitionHandle* handle;
error = addOn->CreatePartitionHandle(&fMutablePartition, &handle);
status_t error = addOn->CreatePartitionHandle(&fMutablePartition, &handle);
if (error != B_OK) {
manager->PutAddOn(addOn);
return error;
}
// everything went fine --keep the disk system add-on reference and the
// everything went fine -- keep the disk system add-on reference and the
// handle
fDiskSystem = addOn;
fPartitionHandle = handle;
@ -169,7 +176,7 @@ BPartition::MutableDelegate::ValidateResize(off_t* size) const
if (!fPartitionHandle)
return B_NO_INIT;
return fPartitionHandle->ValidateResize(size) ? B_OK : B_BAD_VALUE;
return fPartitionHandle->ValidateResize(size);
}
@ -184,7 +191,7 @@ BPartition::MutableDelegate::ValidateResizeChild(Delegate* _child,
return B_NO_INIT;
return fPartitionHandle->ValidateResizeChild(&child->fMutablePartition,
size) ? B_OK : B_BAD_VALUE;
size);
}
@ -219,7 +226,7 @@ BPartition::MutableDelegate::ValidateMove(off_t* offset) const
if (!fPartitionHandle)
return B_NO_INIT;
return fPartitionHandle->ValidateMove(offset) ? B_OK : B_BAD_VALUE;
return fPartitionHandle->ValidateMove(offset);
}
@ -234,7 +241,7 @@ BPartition::MutableDelegate::ValidateMoveChild(Delegate* _child,
return B_NO_INIT;
return fPartitionHandle->ValidateMoveChild(&child->fMutablePartition,
offset) ? B_OK : B_BAD_VALUE;
offset);
}
@ -269,7 +276,7 @@ BPartition::MutableDelegate::ValidateSetContentName(BString* name) const
if (!fPartitionHandle)
return B_NO_INIT;
return fPartitionHandle->ValidateSetContentName(name) ? B_OK : B_BAD_VALUE;
return fPartitionHandle->ValidateSetContentName(name);
}
@ -283,8 +290,7 @@ BPartition::MutableDelegate::ValidateSetName(Delegate* _child,
if (!fPartitionHandle || !child)
return B_NO_INIT;
return fPartitionHandle->ValidateSetName(&child->fMutablePartition, name)
? B_OK : B_BAD_VALUE;
return fPartitionHandle->ValidateSetName(&child->fMutablePartition, name);
}
@ -322,8 +328,7 @@ BPartition::MutableDelegate::ValidateSetType(Delegate* _child,
if (!fPartitionHandle || !child)
return B_NO_INIT;
return fPartitionHandle->ValidateSetType(&child->fMutablePartition, type)
? B_OK : B_BAD_VALUE;
return fPartitionHandle->ValidateSetType(&child->fMutablePartition, type);
}
@ -444,13 +449,13 @@ BPartition::MutableDelegate::ValidateInitialize(const char* diskSystem,
if (!addOn)
return B_ENTRY_NOT_FOUND;
bool result = addOn->ValidateInitialize(&fMutablePartition,
status_t result = addOn->ValidateInitialize(&fMutablePartition,
name, parameters);
// put the add-on
manager->PutAddOn(addOn);
return result ? B_OK : B_BAD_VALUE;
return result;
}
@ -513,26 +518,27 @@ BPartition::MutableDelegate::GetChildCreationParameterEditor(const char* type,
// ValidateCreateChild
status_t
BPartition::MutableDelegate::ValidateCreateChild(off_t* start, off_t* size,
const char* type, const char* parameters) const
const char* type, BString* name, const char* parameters) const
{
if (!fPartitionHandle)
return B_NO_INIT;
return fPartitionHandle->ValidateCreateChild(start, size, type, parameters)
? B_OK : B_BAD_VALUE;
return fPartitionHandle->ValidateCreateChild(start, size, type, name,
parameters);
}
// CreateChild
status_t
BPartition::MutableDelegate::CreateChild(off_t start, off_t size,
const char* type, const char* parameters, BPartition** child)
const char* type, const char* name, const char* parameters,
BPartition** child)
{
if (!fPartitionHandle)
return B_NO_INIT;
BMutablePartition* mutableChild;
status_t error = fPartitionHandle->CreateChild(start, size, type,
status_t error = fPartitionHandle->CreateChild(start, size, type, name,
parameters, &mutableChild);
if (error != B_OK)
return error;

View File

@ -18,8 +18,10 @@ public:
Delegate(BPartition* partition);
virtual ~Delegate();
virtual status_t Init(const user_partition_data* partitionData)
= 0;
virtual status_t InitHierarchy(
const user_partition_data* partitionData,
Delegate* parent) = 0;
virtual status_t InitAfterHierarchy() = 0;
BPartition* Partition() const { return fPartition; }
@ -89,10 +91,11 @@ public:
BDiskDeviceParameterEditor** editor)
const = 0;
virtual status_t ValidateCreateChild(off_t* start, off_t* size,
const char* type,
const char* type, BString* name,
const char* parameters) const = 0;
virtual status_t CreateChild(off_t start, off_t size,
const char* type, const char* parameters,
const char* type, const char* name,
const char* parameters,
BPartition** child) = 0;
virtual status_t DeleteChild(Delegate* child) = 0;
@ -103,7 +106,7 @@ protected:
};
class BPartition::MutableDelegate : BPartition::Delegate {
class BPartition::MutableDelegate : public BPartition::Delegate {
public:
MutableDelegate(BPartition* partition);
virtual ~MutableDelegate();
@ -111,7 +114,10 @@ public:
BMutablePartition* MutablePartition();
const BMutablePartition* MutablePartition() const;
virtual status_t Init(const user_partition_data* partitionData);
virtual status_t InitHierarchy(
const user_partition_data* partitionData,
Delegate* parent);
virtual status_t InitAfterHierarchy();
virtual const user_partition_data* PartitionData() const;
@ -127,17 +133,17 @@ public:
virtual status_t Defragment();
virtual status_t Repair(bool checkOnly);
virtual status_t ValidateResize(off_t* size) const = 0;
virtual status_t ValidateResize(off_t* size) const;
virtual status_t ValidateResizeChild(Delegate* child,
off_t* size) const = 0;
virtual status_t Resize(off_t size) = 0;
virtual status_t ResizeChild(Delegate* child, off_t size) = 0;
off_t* size) const;
virtual status_t Resize(off_t size);
virtual status_t ResizeChild(Delegate* child, off_t size);
virtual status_t ValidateMove(off_t* offset) const = 0;
virtual status_t ValidateMove(off_t* offset) const;
virtual status_t ValidateMoveChild(Delegate* child,
off_t* offset) const = 0;
virtual status_t Move(off_t offset) = 0;
virtual status_t MoveChild(Delegate* child, off_t offset) = 0;
off_t* offset) const;
virtual status_t Move(off_t offset);
virtual status_t MoveChild(Delegate* child, off_t offset);
virtual status_t ValidateSetContentName(BString* name) const;
virtual status_t ValidateSetName(Delegate* child,
@ -174,11 +180,11 @@ public:
const char* system,
BDiskDeviceParameterEditor** editor) const;
virtual status_t ValidateCreateChild(off_t* start, off_t* size,
const char* type,
const char* type, BString* name,
const char* parameters) const;
virtual status_t CreateChild(off_t start, off_t size,
const char* type, const char* parameters,
BPartition** child);
const char* type, const char* name,
const char* parameters, BPartition** child);
virtual status_t DeleteChild(Delegate* child);