* The BMutablePartition setters adjust the change flags accordingly.

* PartitionDelegate::Uninitialize() uninitializes the mutable partition. 


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22779 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2007-10-31 17:02:52 +00:00
parent b289dec88c
commit 3ca9267ce3
4 changed files with 175 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2007, Ingo Weinhold, bonefish@users.sf.net.
* Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _MUTABLE_PARTITION_H
@ -14,6 +14,8 @@ struct user_partition_data;
class BMutablePartition {
public:
void UninitializeContents();
off_t Offset() const;
void SetOffset(off_t offset);
@ -27,11 +29,14 @@ public:
void SetBlockSize(off_t blockSize);
uint32 Status() const;
void SetStatus(uint32 status);
uint32 Flags() const;
void SetFlags(uint32 flags);
void ClearFlags(uint32 flags);
dev_t Volume() const;
dev_t VolumeID() const;
void SetVolumeID(dev_t volumeID);
int32 Index() const;
@ -42,10 +47,10 @@ public:
status_t SetContentName(const char* name);
const char* Type() const;
status_t SetType(const char* type) const;
status_t SetType(const char* type);
const char* ContentType() const;
status_t SetContentType(const char* type) const;
status_t SetContentType(const char* type);
const char* Parameters() const;
status_t SetParameters(const char* parameters);
@ -60,6 +65,7 @@ public:
BMutablePartition** child);
status_t DeleteChild(int32 index);
status_t DeleteChild(BMutablePartition* child);
void DeleteAllChildren();
BMutablePartition* Parent() const;
BMutablePartition* ChildAt(int32 index) const;
@ -68,6 +74,7 @@ public:
void SetChangeFlags(uint32 flags);
uint32 ChangeFlags() const;
void Changed(uint32 flags, uint32 clearFlags = 0);
// for the partitioning system managing the parent
void* ChildCookie() const;

View File

@ -40,8 +40,20 @@ set_string(char*& location, const char* newString)
}
static inline int
compare_string(const char* a, const char* b)
{
if (a == NULL)
return (b == NULL ? 0 : -1);
if (b == NULL)
return 1;
return strcmp(a, b);
}
} // namespace BPrivate
using BPrivate::set_string;
using BPrivate::compare_string;
#endif // _DISK_DEVICE_UTILS_H

View File

@ -1,5 +1,5 @@
/*
* Copyright 2007, Ingo Weinhold, bonefish@users.sf.net.
* Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
@ -21,6 +21,24 @@
using std::nothrow;
// UninitializeContents
void
BMutablePartition::UninitializeContents()
{
DeleteAllChildren();
SetVolumeID(-1);
SetContentName(NULL);
SetContentParameters(NULL);
SetContentSize(0);
SetBlockSize(Parent()->BlockSize());
SetContentType(NULL);
SetStatus(B_PARTITION_UNINITIALIZED);
ClearFlags(B_PARTITION_FILE_SYSTEM | B_PARTITION_PARTITIONING_SYSTEM);
// if (!Device()->IsReadOnlyMedia())
// ClearFlags(B_PARTITION_READ_ONLY);
}
// Offset
off_t
BMutablePartition::Offset() const
@ -33,7 +51,10 @@ BMutablePartition::Offset() const
void
BMutablePartition::SetOffset(off_t offset)
{
fData->offset = offset;
if (fData->offset != offset) {
fData->offset = offset;
Changed(B_PARTITION_CHANGED_OFFSET);
}
}
@ -49,7 +70,10 @@ BMutablePartition::Size() const
void
BMutablePartition::SetSize(off_t size)
{
fData->size = size;
if (fData->size != size) {
fData->size = size;
Changed(B_PARTITION_CHANGED_SIZE);
}
}
@ -65,7 +89,10 @@ BMutablePartition::ContentSize() const
void
BMutablePartition::SetContentSize(off_t size)
{
fData->content_size = size;
if (fData->content_size != size) {
fData->content_size = size;
Changed(B_PARTITION_CHANGED_CONTENT_SIZE);
}
}
@ -81,7 +108,10 @@ BMutablePartition::BlockSize() const
void
BMutablePartition::SetBlockSize(off_t blockSize)
{
fData->block_size = blockSize;
if (fData->block_size != blockSize) {
fData->block_size = blockSize;
Changed(B_PARTITION_CHANGED_BLOCK_SIZE);
}
}
@ -93,6 +123,17 @@ BMutablePartition::Status() const
}
// SetStatus
void
BMutablePartition::SetStatus(uint32 status)
{
if (fData->status != status) {
fData->status = status;
Changed(B_PARTITION_CHANGED_STATUS);
}
}
// Flags
uint32
BMutablePartition::Flags() const
@ -105,18 +146,43 @@ BMutablePartition::Flags() const
void
BMutablePartition::SetFlags(uint32 flags)
{
fData->flags = flags;
if (fData->flags != flags) {
fData->flags = flags;
Changed(B_PARTITION_CHANGED_FLAGS);
}
}
// Volume
// ClearFlags
void
BMutablePartition::ClearFlags(uint32 flags)
{
if (flags & fData->flags) {
fData->flags &= ~flags;
Changed(B_PARTITION_CHANGED_FLAGS);
}
}
// VolumeID
dev_t
BMutablePartition::Volume() const
BMutablePartition::VolumeID() const
{
return fData->volume;
}
// SetVolumeID
void
BMutablePartition::SetVolumeID(dev_t volumeID)
{
if (fData->volume != volumeID) {
fData->volume = volumeID;
Changed(B_PARTITION_CHANGED_VOLUME);
}
}
// Index
int32
BMutablePartition::Index() const
@ -137,7 +203,14 @@ BMutablePartition::Name() const
status_t
BMutablePartition::SetName(const char* name)
{
return set_string(fData->name, name);
if (compare_string(name, fData->name) == 0)
return B_OK;
if (set_string(fData->name, name) != B_OK)
return B_NO_MEMORY;
Changed(B_PARTITION_CHANGED_NAME);
return B_OK;
}
@ -153,7 +226,14 @@ BMutablePartition::ContentName() const
status_t
BMutablePartition::SetContentName(const char* name)
{
return set_string(fData->content_name, name);
if (compare_string(name, fData->content_name) == 0)
return B_OK;
if (set_string(fData->content_name, name) != B_OK)
return B_NO_MEMORY;
Changed(B_PARTITION_CHANGED_CONTENT_NAME);
return B_OK;
}
@ -167,9 +247,16 @@ BMutablePartition::Type() const
// SetType
status_t
BMutablePartition::SetType(const char* type) const
BMutablePartition::SetType(const char* type)
{
return set_string(fData->type, type);
if (compare_string(type, fData->type) == 0)
return B_OK;
if (set_string(fData->type, type) != B_OK)
return B_NO_MEMORY;
Changed(B_PARTITION_CHANGED_TYPE);
return B_OK;
}
@ -183,9 +270,17 @@ BMutablePartition::ContentType() const
// SetContentType
status_t
BMutablePartition::SetContentType(const char* type) const
BMutablePartition::SetContentType(const char* type)
{
return set_string(fData->content_type, type);
if (compare_string(type, fData->content_type) == 0)
return B_OK;
if (set_string(fData->content_type, type) != B_OK)
return B_NO_MEMORY;
Changed(B_PARTITION_CHANGED_CONTENT_TYPE
| B_PARTITION_CHANGED_INITIALIZATION);
return B_OK;
}
@ -201,7 +296,14 @@ BMutablePartition::Parameters() const
status_t
BMutablePartition::SetParameters(const char* parameters)
{
return set_string(fData->parameters, parameters);
if (compare_string(parameters, fData->parameters) == 0)
return B_OK;
if (set_string(fData->parameters, parameters) != B_OK)
return B_NO_MEMORY;
Changed(B_PARTITION_CHANGED_PARAMETERS);
return B_OK;
}
@ -217,7 +319,14 @@ BMutablePartition::ContentParameters() const
status_t
BMutablePartition::SetContentParameters(const char* parameters)
{
return set_string(fData->content_parameters, parameters);
if (compare_string(parameters, fData->content_parameters) == 0)
return B_OK;
if (set_string(fData->content_parameters, parameters) != B_OK)
return B_NO_MEMORY;
Changed(B_PARTITION_CHANGED_CONTENT_PARAMETERS);
return B_OK;
}
@ -255,6 +364,7 @@ BMutablePartition::CreateChild(int32 index, BMutablePartition** _child)
*_child = child;
Changed(B_PARTITION_CHANGED_CHILDREN);
return B_OK;
}
@ -284,6 +394,8 @@ BMutablePartition::CreateChild(int32 index, const char* type, const char* name,
}
*_child = child;
Changed(B_PARTITION_CHANGED_CHILDREN);
return B_OK;
}
@ -301,6 +413,7 @@ BMutablePartition::DeleteChild(int32 index)
// referenced.
child->fDelegate->Partition()->_DeleteDelegates();
Changed(B_PARTITION_CHANGED_CHILDREN);
return B_OK;
}
@ -313,6 +426,16 @@ BMutablePartition::DeleteChild(BMutablePartition* child)
}
// DeleteAllChildren
void
BMutablePartition::DeleteAllChildren()
{
int32 count = CountChildren();
for (int32 i = count - 1; i >= 0; i--)
DeleteChild(i);
}
// Parent
BMutablePartition*
BMutablePartition::Parent() const
@ -363,6 +486,18 @@ BMutablePartition::ChangeFlags() const
}
// Changed
void
BMutablePartition::Changed(uint32 flags, uint32 clearFlags)
{
fChangeFlags &= ~clearFlags;
fChangeFlags |= flags;
if (Parent())
Parent()->Changed(B_PARTITION_CHANGED_DESCENDANTS);
}
// ChildCookie
void*
BMutablePartition::ChildCookie() const

View File

@ -494,7 +494,7 @@ BPartition::Delegate::Uninitialize()
if (fPartitionHandle) {
_FreeHandle();
// TODO: Uninitialize fMutablePartition!
fMutablePartition.UninitializeContents();
}
return B_OK;