Added basic disk system management.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3477 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2003-06-11 21:59:27 +00:00
parent e2242e6916
commit 450c7dd609
2 changed files with 149 additions and 34 deletions

View File

@ -36,6 +36,12 @@ public:
// Disk Device / Partition Management // Disk Device / Partition Management
// manager must be locked
KDiskDevice *FindDevice(const char *path, bool noShadow = true);
KDiskDevice *FindDevice(partition_id id, bool noShadow = true);
KPartition *FindPartition(const char *path, bool noShadow = true);
KPartition *FindPartition(partition_id id, bool noShadow = true);
KDiskDevice *RegisterDevice(const char *path, bool noShadow = true); KDiskDevice *RegisterDevice(const char *path, bool noShadow = true);
KDiskDevice *RegisterDevice(partition_id id, bool noShadow = true); KDiskDevice *RegisterDevice(partition_id id, bool noShadow = true);
KPartition *RegisterPartition(const char *path, bool noShadow = true); KPartition *RegisterPartition(const char *path, bool noShadow = true);
@ -74,11 +80,14 @@ public:
// by the registrar. // by the registrar.
private: private:
KPartition *_FindPartition(partition_id id) const; status_t _AddPartitioningSystem(const char *name);
status_t _AddFileSystem(const char *name);
status_t _AddDiskSystem(KDiskSystem *diskSystem);
BLocker fLock; BLocker fLock;
List<KDiskDevice*> fDevices; // TODO: Optimize! List<KDiskDevice*> fDevices; // TODO: Optimize!
List<KPartition*> fPartitions; // List<KPartition*> fPartitions; //
List<KDiskSystem*> fDiskSystems; //
static KDiskDeviceManager *fDefaultManager; static KDiskDeviceManager *fDefaultManager;
}; };

View File

@ -1,24 +1,53 @@
// KDiskDeviceManager.cpp // KDiskDeviceManager.cpp
#include <module.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "KDiskDevice.h" #include "KDiskDevice.h"
#include "KDiskDeviceManager.h" #include "KDiskDeviceManager.h"
#include "KDiskDeviceUtils.h" #include "KDiskDeviceUtils.h"
#include "KDiskSystem.h"
#include "KFileSystem.h"
#include "KPartition.h" #include "KPartition.h"
#include "KPartitioningSystem.h"
// TODO: Remove when not longer needed. // TODO: Remove when not longer needed.
using BPrivate::DiskDevice::KDiskDeviceJob; using BPrivate::DiskDevice::KDiskDeviceJob;
using BPrivate::DiskDevice::KDiskDeviceJobQueue; using BPrivate::DiskDevice::KDiskDeviceJobQueue;
using BPrivate::DiskDevice::KDiskSystem;
// directories for partitioning and file system modules
static const char *kPartitioningSystemPrefix = "partitioning_systems";
static const char *kFileSystemPrefix = "file_systems";
// constructor // constructor
KDiskDeviceManager::KDiskDeviceManager() KDiskDeviceManager::KDiskDeviceManager()
: fLock("disk device manager"), : fLock("disk device manager"),
fDevices(20), fDevices(20),
fPartitions(100) fPartitions(100),
fDiskSystems(20)
{ {
// add partitioning systems
if (void *list = open_module_list(kPartitioningSystemPrefix)) {
char moduleName[B_PATH_NAME_LENGTH];
for (size_t bufferSize = sizeof(moduleName);
read_next_module_name(list, moduleName, &bufferSize) == B_OK;
bufferSize = sizeof(moduleName)) {
_AddPartitioningSystem(moduleName);
}
close_module_list(list);
}
// add file systems
if (void *list = open_module_list(kFileSystemPrefix)) {
char moduleName[B_PATH_NAME_LENGTH];
for (size_t bufferSize = sizeof(moduleName);
read_next_module_name(list, moduleName, &bufferSize) == B_OK;
bufferSize = sizeof(moduleName)) {
_AddFileSystem(moduleName);
}
close_module_list(list);
}
// TODO: Watch the disk systems and the relevant directories.
} }
// destructor // destructor
@ -81,19 +110,67 @@ KDiskDeviceManager::Unlock()
fLock.Unlock(); fLock.Unlock();
} }
// FindDevice
KDiskDevice *
KDiskDeviceManager::FindDevice(const char *path, bool noShadow)
{
// TODO: Handle shadows correctly!
for (int32 i = 0; KDiskDevice *device = fDevices.ItemAt(i); i++) {
if (device->Path() && !strcmp(path, device->Path()))
return device;
}
return NULL;
}
// FindDevice
KDiskDevice *
KDiskDeviceManager::FindDevice(partition_id id, bool noShadow)
{
// TODO: Handle shadows correctly!
if (KPartition *partition = FindPartition(id))
return partition->Device();
return NULL;
}
// FindPartition
KPartition *
KDiskDeviceManager::FindPartition(const char *path, bool noShadow)
{
// TODO: Handle shadows correctly!
// TODO: Optimize!
for (int32 i = 0; KPartition *partition = fPartitions.ItemAt(i); i++) {
char partitionPath[B_PATH_NAME_LENGTH];
if (partition->GetPath(partitionPath) == B_OK
&& !strcmp(path, partitionPath)) {
return partition;
}
}
return NULL;
}
// FindPartition
KPartition *
KDiskDeviceManager::FindPartition(partition_id id, bool noShadow)
{
// TODO: Handle shadows correctly!
for (int32 i = 0; KPartition *partition = fPartitions.ItemAt(i); i++) {
if (partition->ID() == id)
return partition;
}
return NULL;
}
// RegisterDevice // RegisterDevice
KDiskDevice * KDiskDevice *
KDiskDeviceManager::RegisterDevice(const char *path, bool noShadow) KDiskDeviceManager::RegisterDevice(const char *path, bool noShadow)
{ {
// TODO: Handle shadows correctly! // TODO: Handle shadows correctly!
if (ManagerLocker locker = this) { if (ManagerLocker locker = this) {
for (int32 i = 0; KDiskDevice *device = fDevices.ItemAt(i); i++) { if (KDiskDevice *device = FindDevice(path, noShadow)) {
if (device->Path() && !strcmp(path, device->Path())) {
device->Register(); device->Register();
return device; return device;
} }
} }
}
return NULL; return NULL;
} }
@ -103,8 +180,7 @@ KDiskDeviceManager::RegisterDevice(partition_id id, bool noShadow)
{ {
// TODO: Handle shadows correctly! // TODO: Handle shadows correctly!
if (ManagerLocker locker = this) { if (ManagerLocker locker = this) {
if (KPartition *partition = _FindPartition(id)) { if (KDiskDevice *device = FindDevice(id, noShadow)) {
KDiskDevice *device = partition->Device();
device->Register(); device->Register();
return device; return device;
} }
@ -116,18 +192,12 @@ KDiskDeviceManager::RegisterDevice(partition_id id, bool noShadow)
KPartition * KPartition *
KDiskDeviceManager::RegisterPartition(const char *path, bool noShadow) KDiskDeviceManager::RegisterPartition(const char *path, bool noShadow)
{ {
// TODO: Handle shadows correctly!
// TODO: Optimize!
if (ManagerLocker locker = this) { if (ManagerLocker locker = this) {
for (int32 i = 0; KPartition *partition = fPartitions.ItemAt(i); i++) { if (KPartition *partition = FindPartition(path, noShadow)) {
char partitionPath[B_PATH_NAME_LENGTH];
if (partition->GetPath(partitionPath) == B_OK
&& !strcmp(path, partitionPath)) {
partition->Register(); partition->Register();
return partition; return partition;
} }
} }
}
return NULL; return NULL;
} }
@ -135,9 +205,8 @@ KDiskDeviceManager::RegisterPartition(const char *path, bool noShadow)
KPartition * KPartition *
KDiskDeviceManager::RegisterPartition(partition_id id, bool noShadow) KDiskDeviceManager::RegisterPartition(partition_id id, bool noShadow)
{ {
// TODO: Handle shadows correctly!
if (ManagerLocker locker = this) { if (ManagerLocker locker = this) {
if (KPartition *partition = _FindPartition(id)) { if (KPartition *partition = FindPartition(id, noShadow)) {
partition->Register(); partition->Register();
return partition; return partition;
} }
@ -229,7 +298,10 @@ KDiskDeviceManager::JobQueueAt(int32 index)
KDiskSystem * KDiskSystem *
KDiskDeviceManager::DiskSystemWithName(const char *name) KDiskDeviceManager::DiskSystemWithName(const char *name)
{ {
// not implemented for (int32 i = 0; KDiskSystem *diskSystem = fDiskSystems.ItemAt(i); i++) {
if (!strcmp(name, diskSystem->Name()))
return diskSystem;
}
return NULL; return NULL;
} }
@ -237,7 +309,10 @@ KDiskDeviceManager::DiskSystemWithName(const char *name)
KDiskSystem * KDiskSystem *
KDiskDeviceManager::DiskSystemWithID(disk_system_id id) KDiskDeviceManager::DiskSystemWithID(disk_system_id id)
{ {
// not implemented for (int32 i = 0; KDiskSystem *diskSystem = fDiskSystems.ItemAt(i); i++) {
if (diskSystem->ID() == id)
return diskSystem;
}
return NULL; return NULL;
} }
@ -245,28 +320,59 @@ KDiskDeviceManager::DiskSystemWithID(disk_system_id id)
int32 int32
KDiskDeviceManager::CountDiskSystems() KDiskDeviceManager::CountDiskSystems()
{ {
// not implemented return fDiskSystems.CountItems();
return 0;
} }
// DiskSystemAt // DiskSystemAt
KDiskSystem * KDiskSystem *
KDiskDeviceManager::DiskSystemAt(int32 index) KDiskDeviceManager::DiskSystemAt(int32 index)
{ {
// not implemented return fDiskSystems.ItemAt(index);
return NULL;
} }
// _FindPartition // _AddPartitioningSystem
KPartition * status_t
KDiskDeviceManager::_FindPartition(partition_id id) const KDiskDeviceManager::_AddPartitioningSystem(const char *name)
{ {
for (int32 i = 0; KPartition *partition = fPartitions.ItemAt(i); i++) { if (!name)
if (partition->ID() == id) return B_BAD_VALUE;
return partition; KDiskSystem *diskSystem = new(nothrow) KPartitioningSystem(name);
} if (!diskSystem)
return B_NO_MEMORY;
return _AddDiskSystem(diskSystem);
} }
// _AddFileSystem
status_t
KDiskDeviceManager::_AddFileSystem(const char *name)
{
// TODO: Uncomment when KFileSystem is implemented.
/*
if (!name)
return B_BAD_VALUE;
KDiskSystem *diskSystem = new(nothrow) KFileSystem(name);
if (!diskSystem)
return B_NO_MEMORY;
return _AddDiskSystem(diskSystem);
*/
return B_ERROR;
}
// _AddDiskSystem
status_t
KDiskDeviceManager::_AddDiskSystem(KDiskSystem *diskSystem)
{
if (!diskSystem)
return B_BAD_VALUE;
status_t error = diskSystem->Init();
if (error == B_OK && !fDiskSystems.AddItem(diskSystem))
error = B_NO_MEMORY;
if (error != B_OK)
delete diskSystem;
return error;
}
// singleton instance // singleton instance
KDiskDeviceManager *KDiskDeviceManager::fDefaultManager = NULL; KDiskDeviceManager *KDiskDeviceManager::fDefaultManager = NULL;