* Added back and partially reimplemented the

K{Disk,File,Partitioning}System writing methods. It is now required
  that the caller has marked the concerned partitions busy, hence we can
  (read-)access them without needing a lock. The module interfaces will
  will be changed to take advantage of the fact as well. The methods take a
  disk_job_id instead of a KDiskDeviceJob* now, though I haven't quite
  decided, whether we need it at all or just want to add a special
  handling in the cases where notifications during the operation make
  sense.
* Reimplemented the disk device write support syscalls (save
  _user_move_partition() for which other module hooks are needed). They
  call the KDiskSystem methods, now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22832 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2007-11-05 00:42:47 +00:00
parent 2128ea4f31
commit 7b45b55be1
7 changed files with 1072 additions and 770 deletions

View File

@ -3,21 +3,24 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Ingo Weinhold <bonefish@cs.tu-berlin.de> * Ingo Weinhold <ingo_weinhold@gmx.de>
*/ */
#ifndef _K_DISK_DEVICE_SYSTEM_H #ifndef _K_DISK_DEVICE_SYSTEM_H
#define _K_DISK_DEVICE_SYSTEM_H #define _K_DISK_DEVICE_SYSTEM_H
#include "disk_device_manager.h" #include "disk_device_manager.h"
struct user_disk_system_info; struct user_disk_system_info;
namespace BPrivate { namespace BPrivate {
namespace DiskDevice { namespace DiskDevice {
//class KDiskDeviceJob;
class KPartition; class KPartition;
//! \brief Common ancestor for disk system add-on wrappers //! \brief Common ancestor for disk system add-on wrappers
class KDiskSystem { class KDiskSystem {
public: public:
@ -28,6 +31,7 @@ public:
// void SetID(disk_system_id id); // void SetID(disk_system_id id);
disk_system_id ID() const; disk_system_id ID() const;
const char* Name() const; const char* Name() const;
const char* PrettyName(); const char* PrettyName();
uint32 Flags() const; uint32 Flags() const;
@ -47,50 +51,47 @@ public:
virtual float Identify(KPartition* partition, void** cookie); virtual float Identify(KPartition* partition, void** cookie);
virtual status_t Scan(KPartition* partition, void* cookie); virtual status_t Scan(KPartition* partition, void* cookie);
virtual void FreeIdentifyCookie(KPartition *partition, void *cookie); virtual void FreeIdentifyCookie(KPartition* partition,
void* cookie);
virtual void FreeCookie(KPartition* partition); virtual void FreeCookie(KPartition* partition);
virtual void FreeContentCookie(KPartition* partition); virtual void FreeContentCookie(KPartition* partition);
// Writing // Writing
// Device should not be locked. // Device should not be locked, but all affected partitions are marked
// busy, meaning that no one else is allowed to modify it (and we only,
// if we get a write lock).
#if 0 virtual status_t Defragment(KPartition* partition,
virtual status_t Defragment(KPartition *partition, KDiskDeviceJob *job); disk_job_id job);
virtual status_t Repair(KPartition* partition, bool checkOnly, virtual status_t Repair(KPartition* partition, bool checkOnly,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t Resize(KPartition* partition, off_t size, virtual status_t Resize(KPartition* partition, off_t size,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t ResizeChild(KPartition* child, off_t size, virtual status_t ResizeChild(KPartition* child, off_t size,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t Move(KPartition* partition, off_t offset, virtual status_t Move(KPartition* partition, off_t offset,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t MoveChild(KPartition* child, off_t offset, virtual status_t MoveChild(KPartition* child, off_t offset,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t SetName(KPartition *partition, char *name, virtual status_t SetName(KPartition* partition, const char* name,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t SetContentName(KPartition *partition, char *name, virtual status_t SetContentName(KPartition* partition,
KDiskDeviceJob *job); const char* name, disk_job_id job);
virtual status_t SetType(KPartition *partition, char *type, virtual status_t SetType(KPartition* partition, const char* type,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t SetParameters(KPartition* partition, virtual status_t SetParameters(KPartition* partition,
const char *parameters, const char* parameters, disk_job_id job);
KDiskDeviceJob *job);
virtual status_t SetContentParameters(KPartition* partition, virtual status_t SetContentParameters(KPartition* partition,
const char *parameters, const char* parameters, disk_job_id job);
KDiskDeviceJob *job); virtual status_t Initialize(KPartition* partition,
virtual status_t Initialize(KPartition *partition, const char *name, const char* name, const char* parameters,
const char *parameters, KDiskDeviceJob *job); disk_job_id job);
virtual status_t CreateChild(KPartition* partition, off_t offset, virtual status_t CreateChild(KPartition* partition, off_t offset,
off_t size, const char* type, off_t size, const char* type,
const char *parameters, KDiskDeviceJob *job, const char* name, const char* parameters,
KPartition **child = NULL, disk_job_id job, KPartition** child = NULL,
partition_id childID = -1); partition_id childID = -1);
virtual status_t DeleteChild(KPartition *child, KDiskDeviceJob *job); virtual status_t DeleteChild(KPartition* child, disk_job_id job);
// The KPartition* parameters for the writing methods are a bit `volatile',
// since the device will not be locked, when they are called. The KPartition
// is registered though, so that it is at least guaranteed that the object
// won't go away.
#endif // 0
protected: protected:
virtual status_t LoadModule(); virtual status_t LoadModule();
@ -111,6 +112,7 @@ private:
static int32 fNextID; static int32 fNextID;
}; };
} // namespace DiskDevice } // namespace DiskDevice
} // namespace BPrivate } // namespace BPrivate

View File

@ -6,18 +6,20 @@
* Ingo Weinhold <bonefish@cs.tu-berlin.de> * Ingo Weinhold <bonefish@cs.tu-berlin.de>
* *
* KFileSystem implements the KDiskSystem interface for file systems. * KFileSystem implements the KDiskSystem interface for file systems.
* It works with the FS API.
*/ */
#ifndef _K_FILE_DISK_DEVICE_SYSTEM_H #ifndef _K_FILE_DISK_DEVICE_SYSTEM_H
#define _K_FILE_DISK_DEVICE_SYSTEM_H #define _K_FILE_DISK_DEVICE_SYSTEM_H
#include "KDiskSystem.h" #include "KDiskSystem.h"
struct file_system_module_info; struct file_system_module_info;
namespace BPrivate { namespace BPrivate {
namespace DiskDevice { namespace DiskDevice {
//! \brief Wrapper for the C interface of a filesystem add-on. //! \brief Wrapper for the C interface of a filesystem add-on.
class KFileSystem : public KDiskSystem { class KFileSystem : public KDiskSystem {
public: public:
@ -30,27 +32,27 @@ public:
virtual float Identify(KPartition* partition, void** cookie); virtual float Identify(KPartition* partition, void** cookie);
virtual status_t Scan(KPartition* partition, void* cookie); virtual status_t Scan(KPartition* partition, void* cookie);
virtual void FreeIdentifyCookie(KPartition *partition, void *cookie); virtual void FreeIdentifyCookie(KPartition* partition,
void* cookie);
virtual void FreeContentCookie(KPartition* partition); virtual void FreeContentCookie(KPartition* partition);
// Writing // Writing
#if 0 virtual status_t Defragment(KPartition* partition,
virtual status_t Defragment(KPartition *partition, KDiskDeviceJob *job); disk_job_id job);
virtual status_t Repair(KPartition* partition, bool checkOnly, virtual status_t Repair(KPartition* partition, bool checkOnly,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t Resize(KPartition* partition, off_t size, virtual status_t Resize(KPartition* partition, off_t size,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t Move(KPartition* partition, off_t offset, virtual status_t Move(KPartition* partition, off_t offset,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t SetContentName(KPartition *partition, char *name, virtual status_t SetContentName(KPartition* partition,
KDiskDeviceJob *job); const char* name, disk_job_id job);
virtual status_t SetContentParameters(KPartition* partition, virtual status_t SetContentParameters(KPartition* partition,
const char *parameters, const char* parameters, disk_job_id job);
KDiskDeviceJob *job); virtual status_t Initialize(KPartition* partition,
virtual status_t Initialize(KPartition *partition, const char *name, const char* name, const char* parameters,
const char *parameters, KDiskDeviceJob *job); disk_job_id job);
#endif // 0
protected: protected:
virtual status_t LoadModule(); virtual status_t LoadModule();
@ -60,6 +62,7 @@ private:
file_system_module_info* fModule; file_system_module_info* fModule;
}; };
} // namespace DiskDevice } // namespace DiskDevice
} // namespace BPrivate } // namespace BPrivate

View File

@ -10,11 +10,14 @@
#include "KDiskSystem.h" #include "KDiskSystem.h"
struct partition_module_info; struct partition_module_info;
namespace BPrivate { namespace BPrivate {
namespace DiskDevice { namespace DiskDevice {
/** /**
* \brief Wrapper for the C interface of a partitioning system add-on. * \brief Wrapper for the C interface of a partitioning system add-on.
* *
@ -31,44 +34,42 @@ public:
virtual float Identify(KPartition* partition, void** cookie); virtual float Identify(KPartition* partition, void** cookie);
virtual status_t Scan(KPartition* partition, void* cookie); virtual status_t Scan(KPartition* partition, void* cookie);
virtual void FreeIdentifyCookie(KPartition *partition, void *cookie); virtual void FreeIdentifyCookie(KPartition* partition,
void* cookie);
virtual void FreeCookie(KPartition* partition); virtual void FreeCookie(KPartition* partition);
virtual void FreeContentCookie(KPartition* partition); virtual void FreeContentCookie(KPartition* partition);
// Writing // Writing
#if 0
virtual status_t Repair(KPartition* partition, bool checkOnly, virtual status_t Repair(KPartition* partition, bool checkOnly,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t Resize(KPartition* partition, off_t size, virtual status_t Resize(KPartition* partition, off_t size,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t ResizeChild(KPartition* child, off_t size, virtual status_t ResizeChild(KPartition* child, off_t size,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t Move(KPartition* partition, off_t offset, virtual status_t Move(KPartition* partition, off_t offset,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t MoveChild(KPartition* child, off_t offset, virtual status_t MoveChild(KPartition* child, off_t offset,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t SetName(KPartition *partition, char *name, virtual status_t SetName(KPartition* partition, const char* name,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t SetContentName(KPartition *partition, char *name, virtual status_t SetContentName(KPartition* partition,
KDiskDeviceJob *job); const char* name, disk_job_id job);
virtual status_t SetType(KPartition *partition, char *type, virtual status_t SetType(KPartition* partition, const char* type,
KDiskDeviceJob *job); disk_job_id job);
virtual status_t SetParameters(KPartition* partition, virtual status_t SetParameters(KPartition* partition,
const char *parameters, const char* parameters, disk_job_id job);
KDiskDeviceJob *job);
virtual status_t SetContentParameters(KPartition* partition, virtual status_t SetContentParameters(KPartition* partition,
const char *parameters, const char* parameters, disk_job_id job);
KDiskDeviceJob *job); virtual status_t Initialize(KPartition* partition,
const char* name, const char* parameters,
disk_job_id job);
virtual status_t CreateChild(KPartition* partition, off_t offset, virtual status_t CreateChild(KPartition* partition, off_t offset,
off_t size, const char* type, off_t size, const char* type,
const char *parameters, KDiskDeviceJob *job, const char* name, const char* parameters,
KPartition **child = NULL, disk_job_id job, KPartition** child = NULL,
partition_id childID = -1); partition_id childID = -1);
virtual status_t DeleteChild(KPartition *child, KDiskDeviceJob *job); virtual status_t DeleteChild(KPartition* child, disk_job_id job);
virtual status_t Initialize(KPartition *partition, const char *name,
const char *parameters, KDiskDeviceJob *job);
#endif // 0
protected: protected:
virtual status_t LoadModule(); virtual status_t LoadModule();
@ -78,6 +79,7 @@ private:
partition_module_info* fModule; partition_module_info* fModule;
}; };
} // namespace DiskDevice } // namespace DiskDevice
} // namespace BPrivate } // namespace BPrivate

View File

@ -190,11 +190,9 @@ KDiskSystem::FreeContentCookie(KPartition *partition)
} }
#if 0
// Defragment // Defragment
status_t status_t
KDiskSystem::Defragment(KPartition *partition, KDiskDeviceJob *job) KDiskSystem::Defragment(KPartition* partition, disk_job_id job)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
@ -203,8 +201,7 @@ KDiskSystem::Defragment(KPartition *partition, KDiskDeviceJob *job)
// Repair // Repair
status_t status_t
KDiskSystem::Repair(KPartition *partition, bool checkOnly, KDiskSystem::Repair(KPartition* partition, bool checkOnly, disk_job_id job)
KDiskDeviceJob *job)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
@ -213,7 +210,7 @@ KDiskSystem::Repair(KPartition *partition, bool checkOnly,
// Resize // Resize
status_t status_t
KDiskSystem::Resize(KPartition *partition, off_t size, KDiskDeviceJob *job) KDiskSystem::Resize(KPartition* partition, off_t size, disk_job_id job)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
@ -222,7 +219,7 @@ KDiskSystem::Resize(KPartition *partition, off_t size, KDiskDeviceJob *job)
// ResizeChild // ResizeChild
status_t status_t
KDiskSystem::ResizeChild(KPartition *child, off_t size, KDiskDeviceJob *job) KDiskSystem::ResizeChild(KPartition* child, off_t size, disk_job_id job)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
@ -231,7 +228,7 @@ KDiskSystem::ResizeChild(KPartition *child, off_t size, KDiskDeviceJob *job)
// Move // Move
status_t status_t
KDiskSystem::Move(KPartition *partition, off_t offset, KDiskDeviceJob *job) KDiskSystem::Move(KPartition* partition, off_t offset, disk_job_id job)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
@ -240,7 +237,7 @@ KDiskSystem::Move(KPartition *partition, off_t offset, KDiskDeviceJob *job)
// MoveChild // MoveChild
status_t status_t
KDiskSystem::MoveChild(KPartition *child, off_t offset, KDiskDeviceJob *job) KDiskSystem::MoveChild(KPartition* child, off_t offset, disk_job_id job)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
@ -249,7 +246,7 @@ KDiskSystem::MoveChild(KPartition *child, off_t offset, KDiskDeviceJob *job)
// SetName // SetName
status_t status_t
KDiskSystem::SetName(KPartition *partition, char *name, KDiskDeviceJob *job) KDiskSystem::SetName(KPartition* partition, const char* name, disk_job_id job)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
@ -258,8 +255,8 @@ KDiskSystem::SetName(KPartition *partition, char *name, KDiskDeviceJob *job)
// SetContentName // SetContentName
status_t status_t
KDiskSystem::SetContentName(KPartition *partition, char *name, KDiskSystem::SetContentName(KPartition* partition, const char* name,
KDiskDeviceJob *job) disk_job_id job)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
@ -268,7 +265,7 @@ KDiskSystem::SetContentName(KPartition *partition, char *name,
// SetType // SetType
status_t status_t
KDiskSystem::SetType(KPartition *partition, char *type, KDiskDeviceJob *job) KDiskSystem::SetType(KPartition* partition, const char *type, disk_job_id job)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
@ -278,7 +275,7 @@ KDiskSystem::SetType(KPartition *partition, char *type, KDiskDeviceJob *job)
// SetParameters // SetParameters
status_t status_t
KDiskSystem::SetParameters(KPartition* partition, const char* parameters, KDiskSystem::SetParameters(KPartition* partition, const char* parameters,
KDiskDeviceJob *job) disk_job_id job)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
@ -288,7 +285,7 @@ KDiskSystem::SetParameters(KPartition *partition, const char *parameters,
// SetContentParameters // SetContentParameters
status_t status_t
KDiskSystem::SetContentParameters(KPartition* partition, KDiskSystem::SetContentParameters(KPartition* partition,
const char *parameters, KDiskDeviceJob *job) const char* parameters, disk_job_id job)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
@ -298,7 +295,7 @@ KDiskSystem::SetContentParameters(KPartition *partition,
// Initialize // Initialize
status_t status_t
KDiskSystem::Initialize(KPartition* partition, const char* name, KDiskSystem::Initialize(KPartition* partition, const char* name,
const char *parameters, KDiskDeviceJob *job) const char* parameters, disk_job_id job)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
@ -308,9 +305,8 @@ KDiskSystem::Initialize(KPartition *partition, const char *name,
// CreateChild // CreateChild
status_t status_t
KDiskSystem::CreateChild(KPartition* partition, off_t offset, off_t size, KDiskSystem::CreateChild(KPartition* partition, off_t offset, off_t size,
const char *type, const char *parameters, const char* type, const char* name, const char* parameters, disk_job_id job,
KDiskDeviceJob *job, KPartition **child, KPartition **child, partition_id childID)
partition_id childID)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
@ -319,14 +315,12 @@ KDiskSystem::CreateChild(KPartition *partition, off_t offset, off_t size,
// DeleteChild // DeleteChild
status_t status_t
KDiskSystem::DeleteChild(KPartition *child, KDiskDeviceJob *job) KDiskSystem::DeleteChild(KPartition* child, disk_job_id job)
{ {
// to be implemented by derived classes // to be implemented by derived classes
return B_ERROR; return B_ERROR;
} }
#endif // 0
// LoadModule // LoadModule
status_t status_t

View File

@ -97,11 +97,9 @@ KFileSystem::FreeContentCookie(KPartition *partition)
} }
#if 0
// Defragment // Defragment
status_t status_t
KFileSystem::Defragment(KPartition *partition, KDiskDeviceJob *job) KFileSystem::Defragment(KPartition* partition, disk_job_id job)
{ {
// to be implemented // to be implemented
return B_ERROR; return B_ERROR;
@ -110,7 +108,7 @@ KFileSystem::Defragment(KPartition *partition, KDiskDeviceJob *job)
// Repair // Repair
status_t status_t
KFileSystem::Repair(KPartition *partition, bool checkOnly, KDiskDeviceJob *job) KFileSystem::Repair(KPartition* partition, bool checkOnly, disk_job_id job)
{ {
// to be implemented // to be implemented
return B_ERROR; return B_ERROR;
@ -119,7 +117,7 @@ KFileSystem::Repair(KPartition *partition, bool checkOnly, KDiskDeviceJob *job)
// Resize // Resize
status_t status_t
KFileSystem::Resize(KPartition *partition, off_t size, KDiskDeviceJob *job) KFileSystem::Resize(KPartition* partition, off_t size, disk_job_id job)
{ {
// to be implemented // to be implemented
return B_ERROR; return B_ERROR;
@ -128,7 +126,7 @@ KFileSystem::Resize(KPartition *partition, off_t size, KDiskDeviceJob *job)
// Move // Move
status_t status_t
KFileSystem::Move(KPartition *partition, off_t offset, KDiskDeviceJob *job) KFileSystem::Move(KPartition* partition, off_t offset, disk_job_id job)
{ {
// to be implemented // to be implemented
return B_ERROR; return B_ERROR;
@ -137,58 +135,50 @@ KFileSystem::Move(KPartition *partition, off_t offset, KDiskDeviceJob *job)
// SetContentName // SetContentName
status_t status_t
KFileSystem::SetContentName(KPartition *partition, char *name, KFileSystem::SetContentName(KPartition* partition, const char* name,
KDiskDeviceJob *job) disk_job_id job)
{ {
// to be implemented // to be implemented
return B_ERROR; return B_ERROR;
} }
// SetContentParameters
status_t status_t
KFileSystem::SetContentParameters(KPartition* partition, KFileSystem::SetContentParameters(KPartition* partition,
const char *parameters, KDiskDeviceJob *job) const char* parameters, disk_job_id job)
{ {
// to be implemented // to be implemented
return B_ERROR; return B_ERROR;
} }
// Initialize
status_t status_t
KFileSystem::Initialize(KPartition* partition, const char* name, KFileSystem::Initialize(KPartition* partition, const char* name,
const char *parameters, KDiskDeviceJob *job) const char* parameters, disk_job_id job)
{ {
// check parameters // check parameters
if (!partition || !job || !fModule) if (!partition || !fModule)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->initialize) if (!fModule->initialize)
return B_NOT_SUPPORTED; return B_NOT_SUPPORTED;
// open partition device (we need a temporary read-lock) // open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
if (!manager->ReadLockPartition(partition->ID()))
return B_ERROR;
DeviceReadLocker locker(partition->Device(), true);
int fd = -1; int fd = -1;
status_t result = partition->Open(O_RDWR, &fd); status_t result = partition->Open(O_RDWR, &fd);
if (result != B_OK) if (result != B_OK)
return result; return result;
off_t partitionSize = partition->Size(); // let the module do its job
locker.Unlock();
// call the module hook
result = fModule->initialize(fd, partition->ID(), name, parameters, result = fModule->initialize(fd, partition->ID(), name, parameters,
partitionSize, job->ID()); partition->Size(), job);
// cleanup and return
close(fd); close(fd);
return result; return result;
} }
#endif // 0
// LoadModule // LoadModule
status_t status_t

View File

@ -127,13 +127,11 @@ KPartitioningSystem::FreeContentCookie(KPartition *partition)
} }
#if 0
// Repair // Repair
//! Repairs a partition //! Repairs a partition
status_t status_t
KPartitioningSystem::Repair(KPartition* partition, bool checkOnly, KPartitioningSystem::Repair(KPartition* partition, bool checkOnly,
KDiskDeviceJob *job) disk_job_id job)
{ {
// to be implemented // to be implemented
return B_ERROR; return B_ERROR;
@ -143,34 +141,22 @@ KPartitioningSystem::Repair(KPartition *partition, bool checkOnly,
// Resize // Resize
//! Resizes a partition //! Resizes a partition
status_t status_t
KPartitioningSystem::Resize(KPartition *partition, off_t size, KPartitioningSystem::Resize(KPartition* partition, off_t size, disk_job_id job)
KDiskDeviceJob *job)
{ {
// check parameters // check parameters
if (!partition || !job || size < 0) if (!partition || size < 0 || !fModule)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->resize) if (!fModule->resize)
return B_ENTRY_NOT_FOUND; return B_NOT_SUPPORTED;
// lock partition and open partition device // open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID());
if (!_partition)
return B_ERROR;
int fd = -1; int fd = -1;
{
PartitionRegistrar registrar(_partition, true);
PartitionRegistrar deviceRegistrar(_partition->Device(), true);
DeviceWriteLocker locker(_partition->Device(), true);
if (partition != _partition)
return B_ERROR;
status_t result = partition->Open(O_RDWR, &fd); status_t result = partition->Open(O_RDWR, &fd);
if (result != B_OK) if (result != B_OK)
return result; return result;
}
// let the module do its job // let the module do its job
status_t result = fModule->resize(fd, partition->ID(), size, job->ID()); result = fModule->resize(fd, partition->ID(), size, job);
// cleanup and return // cleanup and return
close(fd); close(fd);
@ -181,35 +167,22 @@ KPartitioningSystem::Resize(KPartition *partition, off_t size,
// ResizeChild // ResizeChild
//! Resizes child of a partition //! Resizes child of a partition
status_t status_t
KPartitioningSystem::ResizeChild(KPartition *child, off_t size, KPartitioningSystem::ResizeChild(KPartition* child, off_t size, disk_job_id job)
KDiskDeviceJob *job)
{ {
// check parameters // check parameters
if (!child || !job || !child->Parent() || size < 0) if (!child || !child->Parent() || size < 0 || !fModule)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->resize_child) if (!fModule->resize_child)
return B_ENTRY_NOT_FOUND; return B_NOT_SUPPORTED;
// lock partition and open (parent) partition device // open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(child->ID());
KPartition *_parent = manager->WriteLockPartition(child->Parent()->ID());
if (!_partition)
return B_ERROR;
int fd = -1; int fd = -1;
{
PartitionRegistrar registrar(_partition, true);
PartitionRegistrar deviceRegistrar(_partition->Device(), true);
DeviceWriteLocker locker(_partition->Device(), true);
if (child != _partition)
return B_ERROR;
status_t result = child->Parent()->Open(O_RDWR, &fd); status_t result = child->Parent()->Open(O_RDWR, &fd);
if (result != B_OK) if (result != B_OK)
return result; return result;
}
// let the module do its job // let the module do its job
status_t result = fModule->resize_child(fd, child->ID(), size, job->ID()); result = fModule->resize_child(fd, child->ID(), size, job);
// cleanup and return // cleanup and return
close(fd); close(fd);
@ -220,34 +193,22 @@ KPartitioningSystem::ResizeChild(KPartition *child, off_t size,
// Move // Move
//! Moves a partition //! Moves a partition
status_t status_t
KPartitioningSystem::Move(KPartition *partition, off_t offset, KPartitioningSystem::Move(KPartition* partition, off_t offset, disk_job_id job)
KDiskDeviceJob *job)
{ {
// check parameters // check parameters
if (!partition || !job) if (!partition)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->move) if (!fModule->move)
return B_ENTRY_NOT_FOUND; return B_NOT_SUPPORTED;
// lock partition and open partition device // open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID());
if (!_partition)
return B_ERROR;
int fd = -1; int fd = -1;
{
PartitionRegistrar registrar(_partition, true);
PartitionRegistrar deviceRegistrar(_partition->Device(), true);
DeviceWriteLocker locker(_partition->Device(), true);
if (partition != _partition)
return B_ERROR;
status_t result = partition->Open(O_RDWR, &fd); status_t result = partition->Open(O_RDWR, &fd);
if (result != B_OK) if (result != B_OK)
return result; return result;
}
// let the module do its job // let the module do its job
status_t result = fModule->move(fd, partition->ID(), offset, job->ID()); result = fModule->move(fd, partition->ID(), offset, job);
// cleanup and return // cleanup and return
close(fd); close(fd);
@ -258,36 +219,23 @@ KPartitioningSystem::Move(KPartition *partition, off_t offset,
// MoveChild // MoveChild
//! Moves child of a partition //! Moves child of a partition
status_t status_t
KPartitioningSystem::MoveChild(KPartition *child, off_t offset, KPartitioningSystem::MoveChild(KPartition* child, off_t offset, disk_job_id job)
KDiskDeviceJob *job)
{ {
// check parameters // check parameters
if (!child || !job || !child->Parent()) if (!child || !child->Parent() || !fModule)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->move_child) if (!fModule->move_child)
return B_ENTRY_NOT_FOUND; return B_NOT_SUPPORTED;
// lock partition and open (parent) partition device // open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(child->ID());
KPartition *_parent = manager->WriteLockPartition(child->Parent()->ID());
if (!_partition)
return B_ERROR;
int fd = -1; int fd = -1;
{
PartitionRegistrar registrar(_partition, true);
PartitionRegistrar deviceRegistrar(_partition->Device(), true);
DeviceWriteLocker locker(_partition->Device(), true);
if (child != _partition)
return B_ERROR;
status_t result = child->Parent()->Open(O_RDWR, &fd); status_t result = child->Parent()->Open(O_RDWR, &fd);
if (result != B_OK) if (result != B_OK)
return result; return result;
}
// let the module do its job // let the module do its job
status_t result = fModule->move_child(fd, child->Parent()->ID(), result = fModule->move_child(fd, child->Parent()->ID(), child->ID(), offset,
child->ID(), offset, job->ID()); job);
// cleanup and return // cleanup and return
close(fd); close(fd);
@ -298,34 +246,24 @@ KPartitioningSystem::MoveChild(KPartition *child, off_t offset,
// SetName // SetName
//! Sets name of a partition //! Sets name of a partition
status_t status_t
KPartitioningSystem::SetName(KPartition *partition, char *name, KPartitioningSystem::SetName(KPartition* child, const char* name,
KDiskDeviceJob *job) disk_job_id job)
{ {
// check parameters // check parameters
if (!partition || !job || !name) if (!child || !child->Parent() || !fModule)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->set_name) if (!fModule->set_name)
return B_ENTRY_NOT_FOUND; return B_NOT_SUPPORTED;
// lock partition and open partition device // open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID());
if (!_partition)
return B_ERROR;
int fd = -1; int fd = -1;
{ status_t result = child->Parent()->Open(O_RDWR, &fd);
PartitionRegistrar registrar(_partition, true);
PartitionRegistrar deviceRegistrar(_partition->Device(), true);
DeviceWriteLocker locker(_partition->Device(), true);
if (partition != _partition)
return B_ERROR;
status_t result = partition->Open(O_RDWR, &fd);
if (result != B_OK) if (result != B_OK)
return result; return result;
}
// let the module do its job // let the module do its job
status_t result = fModule->set_name(fd, partition->ID(), name, job->ID()); result = fModule->set_name(fd, child->ID(), name, job);
// TODO: Change hook interface!
// cleanup and return // cleanup and return
close(fd); close(fd);
@ -336,35 +274,23 @@ KPartitioningSystem::SetName(KPartition *partition, char *name,
// SetContentName // SetContentName
//! Sets name of the content of a partition //! Sets name of the content of a partition
status_t status_t
KPartitioningSystem::SetContentName(KPartition *partition, char *name, KPartitioningSystem::SetContentName(KPartition* partition, const char* name,
KDiskDeviceJob *job) disk_job_id job)
{ {
// check parameters // check parameters
if (!partition || !job || !name) if (!partition || !fModule)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->set_content_name) if (!fModule->set_content_name)
return B_ENTRY_NOT_FOUND; return B_NOT_SUPPORTED;
// lock partition and open partition device // open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID());
if (!_partition)
return B_ERROR;
int fd = -1; int fd = -1;
{
PartitionRegistrar registrar(_partition, true);
PartitionRegistrar deviceRegistrar(_partition->Device(), true);
DeviceWriteLocker locker(_partition->Device(), true);
if (partition != _partition)
return B_ERROR;
status_t result = partition->Open(O_RDWR, &fd); status_t result = partition->Open(O_RDWR, &fd);
if (result != B_OK) if (result != B_OK)
return result; return result;
}
// let the module do its job // let the module do its job
status_t result = fModule->set_content_name(fd, partition->ID(), name, result = fModule->set_content_name(fd, partition->ID(), name, job);
job->ID());
// cleanup and return // cleanup and return
close(fd); close(fd);
@ -375,34 +301,24 @@ KPartitioningSystem::SetContentName(KPartition *partition, char *name,
// SetType // SetType
//! Sets type of a partition //! Sets type of a partition
status_t status_t
KPartitioningSystem::SetType(KPartition *partition, char *type, KPartitioningSystem::SetType(KPartition* child, const char* type,
KDiskDeviceJob *job) disk_job_id job)
{ {
// check parameters // check parameters
if (!partition || !job || !type) if (!child || !child->Parent() || !type || !fModule)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->set_type) if (!fModule->set_type)
return B_ENTRY_NOT_FOUND; return B_NOT_SUPPORTED;
// lock partition and open partition device // open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID());
if (!_partition)
return B_ERROR;
int fd = -1; int fd = -1;
{ status_t result = child->Parent()->Open(O_RDWR, &fd);
PartitionRegistrar registrar(_partition, true);
PartitionRegistrar deviceRegistrar(_partition->Device(), true);
DeviceWriteLocker locker(_partition->Device(), true);
if (partition != _partition)
return B_ERROR;
status_t result = partition->Open(O_RDWR, &fd);
if (result != B_OK) if (result != B_OK)
return result; return result;
}
// let the module do its job // let the module do its job
status_t result = fModule->set_type(fd, partition->ID(), type, job->ID()); result = fModule->set_type(fd, child->Parent()->ID(), type, job);
// TODO: Change hook interface!
// cleanup and return // cleanup and return
close(fd); close(fd);
@ -413,35 +329,24 @@ KPartitioningSystem::SetType(KPartition *partition, char *type,
// SetParameters // SetParameters
//! Sets parameters of a partition //! Sets parameters of a partition
status_t status_t
KPartitioningSystem::SetParameters(KPartition *partition, KPartitioningSystem::SetParameters(KPartition* child, const char* parameters,
const char *parameters, KDiskDeviceJob *job) disk_job_id job)
{ {
// check parameters // check parameters
if (!partition || !job || !parameters) if (!child || !child->Parent() || !fModule)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->set_parameters) if (!fModule->set_parameters)
return B_ENTRY_NOT_FOUND; return B_NOT_SUPPORTED;
// lock partition and open partition device // open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID());
if (!_partition)
return B_ERROR;
int fd = -1; int fd = -1;
{ status_t result = child->Parent()->Open(O_RDWR, &fd);
PartitionRegistrar registrar(_partition, true);
PartitionRegistrar deviceRegistrar(_partition->Device(), true);
DeviceWriteLocker locker(_partition->Device(), true);
if (partition != _partition)
return B_ERROR;
status_t result = partition->Open(O_RDWR, &fd);
if (result != B_OK) if (result != B_OK)
return result; return result;
}
// let the module do its job // let the module do its job
status_t result = fModule->set_parameters(fd, partition->ID(), parameters, result = fModule->set_parameters(fd, child->ID(), parameters, job);
job->ID()); // TODO: Change hook interface!
// cleanup and return // cleanup and return
close(fd); close(fd);
@ -453,34 +358,23 @@ KPartitioningSystem::SetParameters(KPartition *partition,
//! Sets parameters of the content of a partition //! Sets parameters of the content of a partition
status_t status_t
KPartitioningSystem::SetContentParameters(KPartition* partition, KPartitioningSystem::SetContentParameters(KPartition* partition,
const char *parameters, KDiskDeviceJob *job) const char* parameters, disk_job_id job)
{ {
// check parameters // check parameters
if (!partition || !job || !parameters) if (!partition || !fModule)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->set_content_parameters) if (!fModule->set_content_parameters)
return B_ENTRY_NOT_FOUND; return B_NOT_SUPPORTED;
// lock partition and open partition device // open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID());
if (!_partition)
return B_ERROR;
int fd = -1; int fd = -1;
{
PartitionRegistrar registrar(_partition, true);
PartitionRegistrar deviceRegistrar(_partition->Device(), true);
DeviceWriteLocker locker(_partition->Device(), true);
if (partition != _partition)
return B_ERROR;
status_t result = partition->Open(O_RDWR, &fd); status_t result = partition->Open(O_RDWR, &fd);
if (result != B_OK) if (result != B_OK)
return result; return result;
}
// let the module do its job // let the module do its job
status_t result = fModule->set_content_parameters(fd, partition->ID(), result = fModule->set_content_parameters(fd, partition->ID(), parameters,
parameters, job->ID()); job);
// cleanup and return // cleanup and return
close(fd); close(fd);
@ -492,38 +386,23 @@ KPartitioningSystem::SetContentParameters(KPartition *partition,
//! Initializes a partition with this partitioning system //! Initializes a partition with this partitioning system
status_t status_t
KPartitioningSystem::Initialize(KPartition* partition, const char* name, KPartitioningSystem::Initialize(KPartition* partition, const char* name,
const char *parameters, KDiskDeviceJob *job) const char* parameters, disk_job_id job)
{ {
// check parameters // check parameters
if (!partition || !job /*|| !parameters*/) if (!partition || !fModule)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->initialize) if (!fModule->initialize)
return B_ENTRY_NOT_FOUND; return B_NOT_SUPPORTED;
// lock partition and open partition device // open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
// TODO: This looks overly complicated.
KPartition *_partition = manager->WriteLockPartition(partition->ID());
if (!_partition)
return B_ERROR;
int fd = -1; int fd = -1;
off_t partitionSize;
{
PartitionRegistrar registrar(_partition, true);
PartitionRegistrar deviceRegistrar(_partition->Device(), true);
DeviceWriteLocker locker(_partition->Device(), true);
if (partition != _partition)
return B_ERROR;
status_t result = partition->Open(O_RDWR, &fd); status_t result = partition->Open(O_RDWR, &fd);
if (result != B_OK) if (result != B_OK)
return result; return result;
partitionSize = partition->Size();
}
// let the module do its job // let the module do its job
status_t result = fModule->initialize(fd, partition->ID(), name, parameters, result = fModule->initialize(fd, partition->ID(), name, parameters,
partitionSize, job->ID()); partition->Size(), job);
// cleanup and return // cleanup and return
close(fd); close(fd);
@ -535,38 +414,28 @@ KPartitioningSystem::Initialize(KPartition *partition, const char *name,
//! Creates a child partition //! Creates a child partition
status_t status_t
KPartitioningSystem::CreateChild(KPartition* partition, off_t offset, KPartitioningSystem::CreateChild(KPartition* partition, off_t offset,
off_t size, const char *type, const char *parameters, KDiskDeviceJob *job, off_t size, const char* type, const char* name, const char* parameters,
KPartition **child, partition_id childID) disk_job_id job, KPartition** child, partition_id childID)
{ {
// check parameters // check parameters
if (!partition || !job || !type /*|| !parameters*/ || !child) if (!partition || !type || !parameters || !child || !fModule)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->create_child) if (!fModule->create_child)
return B_ENTRY_NOT_FOUND; return B_NOT_SUPPORTED;
// lock partition and open partition device // open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID());
if (!_partition)
return B_ERROR;
int fd = -1; int fd = -1;
{
PartitionRegistrar registrar(_partition, true);
PartitionRegistrar deviceRegistrar(_partition->Device(), true);
DeviceWriteLocker locker(_partition->Device(), true);
if (partition != _partition)
return B_ERROR;
status_t result = partition->Open(O_RDWR, &fd); status_t result = partition->Open(O_RDWR, &fd);
if (result != B_OK) if (result != B_OK)
return result; return result;
}
// let the module do its job // let the module do its job
status_t result = fModule->create_child(fd, partition->ID(), offset, size, result = fModule->create_child(fd, partition->ID(), offset, size,
type, parameters, job->ID(), &childID); type, parameters, job, &childID);
// TODO: Added name parameter to create_child() hook.
// find and return the child // find and return the child
*child = manager->FindPartition(childID, false); *child = KDiskDeviceManager::Default()->FindPartition(childID);
// cleanup and return // cleanup and return
close(fd); close(fd);
@ -577,14 +446,12 @@ KPartitioningSystem::CreateChild(KPartition *partition, off_t offset,
// DeleteChild // DeleteChild
//! Deletes a child partition //! Deletes a child partition
status_t status_t
KPartitioningSystem::DeleteChild(KPartition *child, KDiskDeviceJob *job) KPartitioningSystem::DeleteChild(KPartition* child, disk_job_id job)
{ {
// to be implemented // to be implemented
return B_ERROR; return B_ERROR;
} }
#endif // 0
// LoadModule // LoadModule
status_t status_t