From fe6bd3b5b769948cc65119d0e7b285d2a26325df Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 17 Oct 2007 01:01:49 +0000 Subject: [PATCH] * Moved GetNextSupportedType() and IsSubSystemFor() from BDiskSystem to BPartition and reimplemented them using the userland add-on backend instead of syscalls. As a side effect this solves the TODO I recently added in GetNextSupportedType(). * Reimplemented BDiskSystem::GetTypeForContentType() using the userland add-on backend instead of a syscall. * Moved GetTypeForContentType() and IsSubSystemFor() from BPartitionHandle to BDiskSystemAddOn. They were misplaced. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22592 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/storage/DiskSystem.h | 13 +++-- headers/private/storage/DiskSystemAddOn.h | 7 +-- headers/private/storage/Partition.h | 12 +++++ src/kits/storage/DiskSystem.cpp | 58 ++++++++--------------- src/kits/storage/DiskSystemAddOn.cpp | 32 ++++++------- src/kits/storage/Partition.cpp | 36 ++++++++++++++ src/kits/storage/PartitionDelegate.cpp | 32 +++++++++++++ src/kits/storage/PartitionDelegate.h | 5 ++ 8 files changed, 132 insertions(+), 63 deletions(-) diff --git a/headers/private/storage/DiskSystem.h b/headers/private/storage/DiskSystem.h index d8cec285f6..d03dee219c 100644 --- a/headers/private/storage/DiskSystem.h +++ b/headers/private/storage/DiskSystem.h @@ -9,9 +9,12 @@ #include #include + class BPartition; +class BString; struct user_disk_system_info; + class BDiskSystem { public: BDiskSystem(); @@ -40,21 +43,17 @@ public: bool SupportsDeletingChild() const; bool SupportsInitializing() const; - status_t GetNextSupportedType(BPartition *partition, int32 *cookie, - char *type) const; - // Returns all types the disk system supports for children of the - // supplied partition. - status_t GetTypeForContentType(const char *contentType, char *type) const; + status_t GetTypeForContentType(const char *contentType, + BString* type) const; bool IsPartitioningSystem() const; bool IsFileSystem() const; - bool IsSubSystemFor(BPartition *parent) const; BDiskSystem& operator=(const BDiskSystem& other); private: status_t _SetTo(disk_system_id id); - status_t _SetTo(user_disk_system_info *info); + status_t _SetTo(const user_disk_system_info *info); void _Unset(); friend class BDiskDeviceRoster; diff --git a/headers/private/storage/DiskSystemAddOn.h b/headers/private/storage/DiskSystemAddOn.h index fd718b332e..d39fb7ecfc 100644 --- a/headers/private/storage/DiskSystemAddOn.h +++ b/headers/private/storage/DiskSystemAddOn.h @@ -41,6 +41,10 @@ public: const char* name, const char* parameters, BPartitionHandle** handle); + virtual status_t GetTypeForContentType(const char* contentType, + BString* type); + virtual bool IsSubSystemFor(const BMutablePartition* child); + private: BString fName; uint32 fFlags; @@ -62,14 +66,11 @@ public: virtual bool SupportsInitializingChild( const BMutablePartition* child, const char* diskSystem); - virtual bool IsSubSystemFor(const BMutablePartition* child); virtual status_t GetNextSupportedType( const BMutablePartition* child, int32* cookie, BString* type); // child can be NULL - virtual status_t GetTypeForContentType(const char* contentType, - BString* type); virtual status_t GetPartitioningInfo(BPartitioningInfo* info); diff --git a/headers/private/storage/Partition.h b/headers/private/storage/Partition.h index bf4645f9db..b79b870815 100644 --- a/headers/private/storage/Partition.h +++ b/headers/private/storage/Partition.h @@ -128,6 +128,18 @@ public: BDiskDeviceParameterEditor** editor); status_t SetContentParameters(const char* parameters); + status_t GetNextSupportedType(int32 *cookie, + BString* type) const; + // Returns all partition types for this + // partition supported by the parent disk + // system. + status_t GetNextSupportedChildType(int32 *cookie, + BString* type) const; + // Returns all partition types for a child + // of this partition supported by its disk + // system. + bool IsSubSystem(const char* diskSystem) const; + bool CanInitialize(const char* diskSystem) const; status_t GetInitializationParameterEditor( const char* system, diff --git a/src/kits/storage/DiskSystem.cpp b/src/kits/storage/DiskSystem.cpp index 8043e6c15a..a4c8c34207 100644 --- a/src/kits/storage/DiskSystem.cpp +++ b/src/kits/storage/DiskSystem.cpp @@ -4,10 +4,14 @@ */ #include + +#include #include -#include #include +#include + +#include "DiskSystemAddOnManager.h" // constructor @@ -277,37 +281,28 @@ BDiskSystem::SupportsInitializing() const } -// GetNextSupportedType -status_t -BDiskSystem::GetNextSupportedType(BPartition* partition, int32* cookie, - char* type) const -{ -// TODO: We probably need a second method for and modify the partitioning -// system module hook a little. This method takes the parent partition of -// a partition to be created for which we want to get supported types. It -// should also be possible to invoke it for the partition whose type to change -// though. - if (InitCheck() != B_OK) - return InitCheck(); - if (!cookie || !type || !partition || !partition->_IsShadow() - || partition->_DiskSystem() != fID || !IsPartitioningSystem()) { - return B_BAD_VALUE; - } - - return _kern_get_next_supported_partition_type(partition->_ShadowID(), - partition->_ChangeCounter(), cookie, type); -} - - // GetTypeForContentType status_t -BDiskSystem::GetTypeForContentType(const char* contentType, char* type) const +BDiskSystem::GetTypeForContentType(const char* contentType, BString* type) const { if (InitCheck() != B_OK) return InitCheck(); + if (!contentType || !type || !IsPartitioningSystem()) return B_BAD_VALUE; - return _kern_get_partition_type_for_content_type(fID, contentType, type); + + // get the disk system add-on + DiskSystemAddOnManager* manager = DiskSystemAddOnManager::Default(); + BDiskSystemAddOn* addOn = manager->GetAddOn(fName.String()); + if (!addOn) + return B_ENTRY_NOT_FOUND; + + status_t result = addOn->GetTypeForContentType(contentType, type); + + // put the add-on + manager->PutAddOn(addOn); + + return result; } @@ -327,17 +322,6 @@ BDiskSystem::IsFileSystem() const } -// IsSubSystemFor -bool -BDiskSystem::IsSubSystemFor(BPartition* parent) const -{ - return (InitCheck() == B_OK - && parent && parent->_IsShadow() - && _kern_is_sub_disk_system_for(fID, parent->_ShadowID(), - parent->_ChangeCounter())); -} - - // = BDiskSystem& BDiskSystem::operator=(const BDiskSystem& other) @@ -371,7 +355,7 @@ BDiskSystem::_SetTo(disk_system_id id) // _SetTo status_t -BDiskSystem::_SetTo(user_disk_system_info* info) +BDiskSystem::_SetTo(const user_disk_system_info* info) { _Unset(); diff --git a/src/kits/storage/DiskSystemAddOn.cpp b/src/kits/storage/DiskSystemAddOn.cpp index cf5e49296a..33946cdfde 100644 --- a/src/kits/storage/DiskSystemAddOn.cpp +++ b/src/kits/storage/DiskSystemAddOn.cpp @@ -76,6 +76,22 @@ BDiskSystemAddOn::Initialize(BMutablePartition* partition, const char* name, } +// GetTypeForContentType +status_t +BDiskSystemAddOn::GetTypeForContentType(const char* contentType, BString* type) +{ + return B_NOT_SUPPORTED; +} + + +// IsSubSystemFor +bool +BDiskSystemAddOn::IsSubSystemFor(const BMutablePartition* child) +{ + return false; +} + + // #pragma mark - BPartitionHandle @@ -126,14 +142,6 @@ BPartitionHandle::SupportsInitializingChild(const BMutablePartition* child, } -// IsSubSystemFor -bool -BPartitionHandle::IsSubSystemFor(const BMutablePartition* child) -{ - return false; -} - - // GetNextSupportedType status_t BPartitionHandle::GetNextSupportedType(const BMutablePartition* child, @@ -143,14 +151,6 @@ BPartitionHandle::GetNextSupportedType(const BMutablePartition* child, } -// GetTypeForContentType -status_t -BPartitionHandle::GetTypeForContentType(const char* contentType, BString* type) -{ - return B_NOT_SUPPORTED; -} - - // GetPartitioningInfo status_t BPartitionHandle::GetPartitioningInfo(BPartitioningInfo* info) diff --git a/src/kits/storage/Partition.cpp b/src/kits/storage/Partition.cpp index d8e970d32f..084d3292e1 100644 --- a/src/kits/storage/Partition.cpp +++ b/src/kits/storage/Partition.cpp @@ -1059,6 +1059,42 @@ BPartition::SetContentParameters(const char* parameters) } +// GetNextSupportedType +status_t +BPartition::GetNextSupportedType(int32 *cookie, BString* type) const +{ + BPartition* parent = Parent(); + if (!parent || !fDelegate) + return false; + + return parent->fDelegate->GetNextSupportedChildType(fDelegate, cookie, + type); +} + + +// GetNextSupportedChildType +status_t +BPartition::GetNextSupportedChildType(int32 *cookie, BString* type) const +{ + if (!fDelegate) + return B_BAD_VALUE; + + return fDelegate->GetNextSupportedChildType(NULL, cookie, type); +} + + +// IsSubSystem +bool +BPartition::BPartition::IsSubSystem(const char* diskSystem) const +{ + BPartition* parent = Parent(); + if (!parent || !fDelegate) + return false; + + return parent->fDelegate->IsSubSystem(fDelegate, diskSystem); +} + + // CanInitialize bool BPartition::CanInitialize(const char* diskSystem) const diff --git a/src/kits/storage/PartitionDelegate.cpp b/src/kits/storage/PartitionDelegate.cpp index 0f2babbc5d..3c1299f870 100644 --- a/src/kits/storage/PartitionDelegate.cpp +++ b/src/kits/storage/PartitionDelegate.cpp @@ -353,6 +353,38 @@ BPartition::Delegate::SetParameters(Delegate* child, const char* parameters) } +// GetNextSupportedChildType +status_t +BPartition::Delegate::GetNextSupportedChildType(Delegate* child, int32 *cookie, + BString* type) const +{ + if (!fPartitionHandle) + return B_NO_INIT; + + return fPartitionHandle->GetNextSupportedType( + child ? &child->fMutablePartition : NULL, cookie, type); +} + + +// IsSubSystem +bool +BPartition::Delegate::IsSubSystem(Delegate* child, const char* diskSystem) const +{ + // get the disk system add-on + DiskSystemAddOnManager* manager = DiskSystemAddOnManager::Default(); + BDiskSystemAddOn* addOn = manager->GetAddOn(diskSystem); + if (!addOn) + return false; + + bool result = addOn->IsSubSystemFor(&child->fMutablePartition); + + // put the add-on + manager->PutAddOn(addOn); + + return result; +} + + // CanInitialize bool BPartition::Delegate::CanInitialize(const char* diskSystem) const diff --git a/src/kits/storage/PartitionDelegate.h b/src/kits/storage/PartitionDelegate.h index e1bde73986..62123d54d2 100644 --- a/src/kits/storage/PartitionDelegate.h +++ b/src/kits/storage/PartitionDelegate.h @@ -72,6 +72,11 @@ public: status_t SetParameters(Delegate* child, const char* parameters); + status_t GetNextSupportedChildType(Delegate* child, + int32 *cookie, BString* type) const; + bool IsSubSystem(Delegate* child, + const char* diskSystem) const; + bool CanInitialize(const char* diskSystem) const; status_t GetInitializationParameterEditor( const char* system,