* 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,114 +3,116 @@
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
* Ingo Weinhold <ingo_weinhold@gmx.de>
*/
#ifndef _K_DISK_DEVICE_SYSTEM_H
#define _K_DISK_DEVICE_SYSTEM_H
#include "disk_device_manager.h"
struct user_disk_system_info;
namespace BPrivate {
namespace DiskDevice {
//class KDiskDeviceJob;
class KPartition;
//! \brief Common ancestor for disk system add-on wrappers
class KDiskSystem {
public:
KDiskSystem(const char *name);
virtual ~KDiskSystem();
KDiskSystem(const char *name);
virtual ~KDiskSystem();
virtual status_t Init();
virtual status_t Init();
// void SetID(disk_system_id id);
disk_system_id ID() const;
const char *Name() const;
const char *PrettyName();
uint32 Flags() const;
// void SetID(disk_system_id id);
disk_system_id ID() const;
bool IsFileSystem() const;
bool IsPartitioningSystem() const;
const char* Name() const;
const char* PrettyName();
uint32 Flags() const;
void GetInfo(user_disk_system_info *info);
bool IsFileSystem() const;
bool IsPartitioningSystem() const;
void GetInfo(user_disk_system_info* info);
// manager will be locked
status_t Load(); // load/unload -- can be nested
void Unload(); //
bool IsLoaded() const;
status_t Load(); // load/unload -- can be nested
void Unload(); //
bool IsLoaded() const;
// Scanning
// Device must be write locked.
virtual float Identify(KPartition *partition, void **cookie);
virtual status_t Scan(KPartition *partition, void *cookie);
virtual void FreeIdentifyCookie(KPartition *partition, void *cookie);
virtual void FreeCookie(KPartition *partition);
virtual void FreeContentCookie(KPartition *partition);
virtual float Identify(KPartition* partition, void** cookie);
virtual status_t Scan(KPartition* partition, void* cookie);
virtual void FreeIdentifyCookie(KPartition* partition,
void* cookie);
virtual void FreeCookie(KPartition* partition);
virtual void FreeContentCookie(KPartition* partition);
// 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, KDiskDeviceJob *job);
virtual status_t Repair(KPartition *partition, bool checkOnly,
KDiskDeviceJob *job);
virtual status_t Resize(KPartition *partition, off_t size,
KDiskDeviceJob *job);
virtual status_t ResizeChild(KPartition *child, off_t size,
KDiskDeviceJob *job);
virtual status_t Move(KPartition *partition, off_t offset,
KDiskDeviceJob *job);
virtual status_t MoveChild(KPartition *child, off_t offset,
KDiskDeviceJob *job);
virtual status_t SetName(KPartition *partition, char *name,
KDiskDeviceJob *job);
virtual status_t SetContentName(KPartition *partition, char *name,
KDiskDeviceJob *job);
virtual status_t SetType(KPartition *partition, char *type,
KDiskDeviceJob *job);
virtual status_t SetParameters(KPartition *partition,
const char *parameters,
KDiskDeviceJob *job);
virtual status_t SetContentParameters(KPartition *partition,
const char *parameters,
KDiskDeviceJob *job);
virtual status_t Initialize(KPartition *partition, const char *name,
const char *parameters, KDiskDeviceJob *job);
virtual status_t CreateChild(KPartition *partition, off_t offset,
off_t size, const char *type,
const char *parameters, KDiskDeviceJob *job,
KPartition **child = NULL,
partition_id childID = -1);
virtual status_t DeleteChild(KPartition *child, KDiskDeviceJob *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
virtual status_t Defragment(KPartition* partition,
disk_job_id job);
virtual status_t Repair(KPartition* partition, bool checkOnly,
disk_job_id job);
virtual status_t Resize(KPartition* partition, off_t size,
disk_job_id job);
virtual status_t ResizeChild(KPartition* child, off_t size,
disk_job_id job);
virtual status_t Move(KPartition* partition, off_t offset,
disk_job_id job);
virtual status_t MoveChild(KPartition* child, off_t offset,
disk_job_id job);
virtual status_t SetName(KPartition* partition, const char* name,
disk_job_id job);
virtual status_t SetContentName(KPartition* partition,
const char* name, disk_job_id job);
virtual status_t SetType(KPartition* partition, const char* type,
disk_job_id job);
virtual status_t SetParameters(KPartition* partition,
const char* parameters, disk_job_id job);
virtual status_t SetContentParameters(KPartition* partition,
const char* parameters, disk_job_id 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,
off_t size, const char* type,
const char* name, const char* parameters,
disk_job_id job, KPartition** child = NULL,
partition_id childID = -1);
virtual status_t DeleteChild(KPartition* child, disk_job_id job);
protected:
virtual status_t LoadModule();
virtual void UnloadModule();
virtual status_t LoadModule();
virtual void UnloadModule();
status_t SetPrettyName(const char *name);
void SetFlags(uint32 flags);
status_t SetPrettyName(const char* name);
void SetFlags(uint32 flags);
static int32 _NextID();
static int32 _NextID();
private:
disk_system_id fID;
char *fName;
char *fPrettyName;
uint32 fFlags;
int32 fLoadCounter;
disk_system_id fID;
char* fName;
char* fPrettyName;
uint32 fFlags;
int32 fLoadCounter;
static int32 fNextID;
static int32 fNextID;
};
} // namespace DiskDevice
} // namespace BPrivate

View File

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

View File

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

View File

@ -190,11 +190,9 @@ KDiskSystem::FreeContentCookie(KPartition *partition)
}
#if 0
// Defragment
status_t
KDiskSystem::Defragment(KPartition *partition, KDiskDeviceJob *job)
KDiskSystem::Defragment(KPartition* partition, disk_job_id job)
{
// to be implemented by derived classes
return B_ERROR;
@ -203,8 +201,7 @@ KDiskSystem::Defragment(KPartition *partition, KDiskDeviceJob *job)
// Repair
status_t
KDiskSystem::Repair(KPartition *partition, bool checkOnly,
KDiskDeviceJob *job)
KDiskSystem::Repair(KPartition* partition, bool checkOnly, disk_job_id job)
{
// to be implemented by derived classes
return B_ERROR;
@ -213,7 +210,7 @@ KDiskSystem::Repair(KPartition *partition, bool checkOnly,
// Resize
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
return B_ERROR;
@ -222,7 +219,7 @@ KDiskSystem::Resize(KPartition *partition, off_t size, KDiskDeviceJob *job)
// ResizeChild
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
return B_ERROR;
@ -231,7 +228,7 @@ KDiskSystem::ResizeChild(KPartition *child, off_t size, KDiskDeviceJob *job)
// Move
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
return B_ERROR;
@ -240,7 +237,7 @@ KDiskSystem::Move(KPartition *partition, off_t offset, KDiskDeviceJob *job)
// MoveChild
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
return B_ERROR;
@ -249,7 +246,7 @@ KDiskSystem::MoveChild(KPartition *child, off_t offset, KDiskDeviceJob *job)
// SetName
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
return B_ERROR;
@ -258,8 +255,8 @@ KDiskSystem::SetName(KPartition *partition, char *name, KDiskDeviceJob *job)
// SetContentName
status_t
KDiskSystem::SetContentName(KPartition *partition, char *name,
KDiskDeviceJob *job)
KDiskSystem::SetContentName(KPartition* partition, const char* name,
disk_job_id job)
{
// to be implemented by derived classes
return B_ERROR;
@ -268,7 +265,7 @@ KDiskSystem::SetContentName(KPartition *partition, char *name,
// SetType
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
return B_ERROR;
@ -277,8 +274,8 @@ KDiskSystem::SetType(KPartition *partition, char *type, KDiskDeviceJob *job)
// SetParameters
status_t
KDiskSystem::SetParameters(KPartition *partition, const char *parameters,
KDiskDeviceJob *job)
KDiskSystem::SetParameters(KPartition* partition, const char* parameters,
disk_job_id job)
{
// to be implemented by derived classes
return B_ERROR;
@ -287,8 +284,8 @@ KDiskSystem::SetParameters(KPartition *partition, const char *parameters,
// SetContentParameters
status_t
KDiskSystem::SetContentParameters(KPartition *partition,
const char *parameters, KDiskDeviceJob *job)
KDiskSystem::SetContentParameters(KPartition* partition,
const char* parameters, disk_job_id job)
{
// to be implemented by derived classes
return B_ERROR;
@ -297,8 +294,8 @@ KDiskSystem::SetContentParameters(KPartition *partition,
// Initialize
status_t
KDiskSystem::Initialize(KPartition *partition, const char *name,
const char *parameters, KDiskDeviceJob *job)
KDiskSystem::Initialize(KPartition* partition, const char* name,
const char* parameters, disk_job_id job)
{
// to be implemented by derived classes
return B_ERROR;
@ -307,10 +304,9 @@ KDiskSystem::Initialize(KPartition *partition, const char *name,
// CreateChild
status_t
KDiskSystem::CreateChild(KPartition *partition, off_t offset, off_t size,
const char *type, const char *parameters,
KDiskDeviceJob *job, KPartition **child,
partition_id childID)
KDiskSystem::CreateChild(KPartition* partition, off_t offset, off_t size,
const char* type, const char* name, const char* parameters, disk_job_id job,
KPartition **child, partition_id childID)
{
// to be implemented by derived classes
return B_ERROR;
@ -319,14 +315,12 @@ KDiskSystem::CreateChild(KPartition *partition, off_t offset, off_t size,
// DeleteChild
status_t
KDiskSystem::DeleteChild(KPartition *child, KDiskDeviceJob *job)
KDiskSystem::DeleteChild(KPartition* child, disk_job_id job)
{
// to be implemented by derived classes
return B_ERROR;
}
#endif // 0
// LoadModule
status_t

View File

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

View File

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