* 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
+11 -4
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2007, Ingo Weinhold, [email protected]. * Copyright 2007, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _MUTABLE_PARTITION_H #ifndef _MUTABLE_PARTITION_H
@@ -14,6 +14,8 @@ struct user_partition_data;
class BMutablePartition { class BMutablePartition {
public: public:
void UninitializeContents();
off_t Offset() const; off_t Offset() const;
void SetOffset(off_t offset); void SetOffset(off_t offset);
@@ -27,11 +29,14 @@ public:
void SetBlockSize(off_t blockSize); void SetBlockSize(off_t blockSize);
uint32 Status() const; uint32 Status() const;
void SetStatus(uint32 status);
uint32 Flags() const; uint32 Flags() const;
void SetFlags(uint32 flags); void SetFlags(uint32 flags);
void ClearFlags(uint32 flags);
dev_t Volume() const; dev_t VolumeID() const;
void SetVolumeID(dev_t volumeID);
int32 Index() const; int32 Index() const;
@@ -42,10 +47,10 @@ public:
status_t SetContentName(const char* name); status_t SetContentName(const char* name);
const char* Type() const; const char* Type() const;
status_t SetType(const char* type) const; status_t SetType(const char* type);
const char* ContentType() const; const char* ContentType() const;
status_t SetContentType(const char* type) const; status_t SetContentType(const char* type);
const char* Parameters() const; const char* Parameters() const;
status_t SetParameters(const char* parameters); status_t SetParameters(const char* parameters);
@@ -60,6 +65,7 @@ public:
BMutablePartition** child); BMutablePartition** child);
status_t DeleteChild(int32 index); status_t DeleteChild(int32 index);
status_t DeleteChild(BMutablePartition* child); status_t DeleteChild(BMutablePartition* child);
void DeleteAllChildren();
BMutablePartition* Parent() const; BMutablePartition* Parent() const;
BMutablePartition* ChildAt(int32 index) const; BMutablePartition* ChildAt(int32 index) const;
@@ -68,6 +74,7 @@ public:
void SetChangeFlags(uint32 flags); void SetChangeFlags(uint32 flags);
uint32 ChangeFlags() const; uint32 ChangeFlags() const;
void Changed(uint32 flags, uint32 clearFlags = 0);
// for the partitioning system managing the parent // for the partitioning system managing the parent
void* ChildCookie() const; void* ChildCookie() const;
@@ -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 } // namespace BPrivate
using BPrivate::set_string; using BPrivate::set_string;
using BPrivate::compare_string;
#endif // _DISK_DEVICE_UTILS_H #endif // _DISK_DEVICE_UTILS_H
+151 -16
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2007, Ingo Weinhold, [email protected]. * Copyright 2007, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -21,6 +21,24 @@
using std::nothrow; 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 // Offset
off_t off_t
BMutablePartition::Offset() const BMutablePartition::Offset() const
@@ -33,7 +51,10 @@ BMutablePartition::Offset() const
void void
BMutablePartition::SetOffset(off_t offset) 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 void
BMutablePartition::SetSize(off_t size) 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 void
BMutablePartition::SetContentSize(off_t size) 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 void
BMutablePartition::SetBlockSize(off_t blockSize) 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 // Flags
uint32 uint32
BMutablePartition::Flags() const BMutablePartition::Flags() const
@@ -105,18 +146,43 @@ BMutablePartition::Flags() const
void void
BMutablePartition::SetFlags(uint32 flags) 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 dev_t
BMutablePartition::Volume() const BMutablePartition::VolumeID() const
{ {
return fData->volume; return fData->volume;
} }
// SetVolumeID
void
BMutablePartition::SetVolumeID(dev_t volumeID)
{
if (fData->volume != volumeID) {
fData->volume = volumeID;
Changed(B_PARTITION_CHANGED_VOLUME);
}
}
// Index // Index
int32 int32
BMutablePartition::Index() const BMutablePartition::Index() const
@@ -137,7 +203,14 @@ BMutablePartition::Name() const
status_t status_t
BMutablePartition::SetName(const char* name) 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 status_t
BMutablePartition::SetContentName(const char* name) 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 // SetType
status_t 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 // SetContentType
status_t 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 status_t
BMutablePartition::SetParameters(const char* parameters) 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 status_t
BMutablePartition::SetContentParameters(const char* parameters) 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; *_child = child;
Changed(B_PARTITION_CHANGED_CHILDREN);
return B_OK; return B_OK;
} }
@@ -284,6 +394,8 @@ BMutablePartition::CreateChild(int32 index, const char* type, const char* name,
} }
*_child = child; *_child = child;
Changed(B_PARTITION_CHANGED_CHILDREN);
return B_OK; return B_OK;
} }
@@ -301,6 +413,7 @@ BMutablePartition::DeleteChild(int32 index)
// referenced. // referenced.
child->fDelegate->Partition()->_DeleteDelegates(); child->fDelegate->Partition()->_DeleteDelegates();
Changed(B_PARTITION_CHANGED_CHILDREN);
return B_OK; 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 // Parent
BMutablePartition* BMutablePartition*
BMutablePartition::Parent() const 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 // ChildCookie
void* void*
BMutablePartition::ChildCookie() const BMutablePartition::ChildCookie() const
@@ -494,7 +494,7 @@ BPartition::Delegate::Uninitialize()
if (fPartitionHandle) { if (fPartitionHandle) {
_FreeHandle(); _FreeHandle();
// TODO: Uninitialize fMutablePartition! fMutablePartition.UninitializeContents();
} }
return B_OK; return B_OK;