Several fixes necessary to get the partition scanning working.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3506 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2003-06-13 22:08:10 +00:00
parent 07d370e32a
commit 2609ebac90
8 changed files with 88 additions and 16 deletions

View File

@ -90,6 +90,9 @@ private:
status_t _AddFileSystem(const char *name);
status_t _AddDiskSystem(KDiskSystem *diskSystem);
bool _AddDevice(KDiskDevice *device);
bool _RemoveDevice(KDiskDevice *device);
status_t _Scan(const char *path);
status_t _ScanPartition(KPartition *partition);

View File

@ -111,11 +111,15 @@ protected:
status_t SetPrettyName(const char *name);
static int32 _NextID();
private:
disk_system_id fID;
char *fName;
char *fPrettyName;
int32 fLoadCounter;
static int32 fNextID;
};
} // namespace DiskDevice

View File

@ -78,9 +78,8 @@ partition_data *get_child_partition(partition_id partitionID, int32 index);
// partition write access
// (write lock required)
partition_data *create_child_partition(partition_id partitionID, int32 index,
partition_id *childID);
// childID is used for the return value, but is also an optional input
// parameter -- -1 to be ignored
partition_id childID);
// childID is an optional input parameter -- -1 to be ignored
bool delete_partition(partition_id partitionID);
void partition_modified(partition_id partitionID);
// tells the disk device manager, that the parition has been modified

View File

@ -19,6 +19,7 @@ KDiskDevice::KDiskDevice(partition_id id)
fShadowOwner(-1)
{
Unset();
fDevice = this;
}
// destructor

View File

@ -16,6 +16,11 @@
#include "KPartition.h"
#include "KPartitioningSystem.h"
// debugging
//#define DBG(x)
#define DBG(x) x
#define OUT printf
// TODO: Remove when not longer needed.
using BPrivate::DiskDevice::KDiskDeviceJob;
using BPrivate::DiskDevice::KDiskDeviceJobQueue;
@ -37,6 +42,7 @@ KDiskDeviceManager::KDiskDeviceManager()
for (size_t bufferSize = sizeof(moduleName);
read_next_module_name(list, moduleName, &bufferSize) == B_OK;
bufferSize = sizeof(moduleName)) {
DBG(OUT("partitioning system: %s\n", moduleName));
_AddPartitioningSystem(moduleName);
}
close_module_list(list);
@ -47,6 +53,7 @@ KDiskDeviceManager::KDiskDeviceManager()
for (size_t bufferSize = sizeof(moduleName);
read_next_module_name(list, moduleName, &bufferSize) == B_OK;
bufferSize = sizeof(moduleName)) {
DBG(OUT("file system: %s\n", moduleName));
_AddFileSystem(moduleName);
}
close_module_list(list);
@ -403,10 +410,12 @@ KDiskDeviceManager::InitialDeviceScan()
while (KDiskDevice *device = RegisterNextDevice(&cookie)) {
if (device->WriteLock()) {
// scan the device
error = _ScanPartition(device);
if (error != B_OK) {
// ...
error = B_OK;
if (device->HasMedia()) {
error = _ScanPartition(device);
if (error != B_OK) {
// ...
error = B_OK;
}
}
device->WriteUnlock();
}
@ -441,7 +450,7 @@ KDiskDeviceManager::_AddFileSystem(const char *name)
return B_NO_MEMORY;
return _AddDiskSystem(diskSystem);
*/
return B_ERROR;
return B_ERROR;
}
// _AddDiskSystem
@ -450,14 +459,37 @@ KDiskDeviceManager::_AddDiskSystem(KDiskSystem *diskSystem)
{
if (!diskSystem)
return B_BAD_VALUE;
DBG(OUT("KDiskDeviceManager::_AddDiskSystem(%s)\n", diskSystem->Name()));
status_t error = diskSystem->Init();
if (error != B_OK)
DBG(OUT(" initialization failed: %s\n", strerror(error)));
if (error == B_OK && !fDiskSystems.AddItem(diskSystem))
error = B_NO_MEMORY;
if (error != B_OK)
delete diskSystem;
DBG(OUT("KDiskDeviceManager::_AddDiskSystem() done: %s\n", strerror(error)));
return error;
}
// _AddDevice
bool
KDiskDeviceManager::_AddDevice(KDiskDevice *device)
{
if (!device || !PartitionAdded(device))
return false;
if (fDevices.AddItem(device))
return true;
PartitionRemoved(device);
return false;
}
// _RemoveDevice
bool
KDiskDeviceManager::_RemoveDevice(KDiskDevice *device)
{
return (device && PartitionRemoved(device) && fDevices.RemoveItem(device));
}
// _Scan
status_t
KDiskDeviceManager::_Scan(const char *path)
@ -489,6 +521,7 @@ KDiskDeviceManager::_Scan(const char *path)
int32 leafLen = strlen("/raw");
if (len <= leafLen || strcmp(path + len - leafLen, "/raw"))
return B_ERROR;
DBG(OUT(" found device: %s\n", path));
// create a KDiskDevice for it
KDiskDevice *device = new(nothrow) KDiskDevice;
if (!device)
@ -496,7 +529,7 @@ KDiskDeviceManager::_Scan(const char *path)
// init the KDiskDevice
status_t error = device->SetTo(path);
// add the device
if (error == B_OK && !fDevices.AddItem(device))
if (error == B_OK && !_AddDevice(device))
error = B_NO_MEMORY;
// cleanup on error
if (error != B_OK)
@ -512,14 +545,19 @@ KDiskDeviceManager::_ScanPartition(KPartition *partition)
// the partition's device must be write-locked
if (!partition)
return B_BAD_VALUE;
char partitionPath[B_PATH_NAME_LENGTH];
partition->GetPath(partitionPath);
DBG(OUT("KDiskDeviceManager::_ScanPartition(%s)\n", partitionPath));
// find the disk system that returns the best priority for this partition
float bestPriority = -1;
KDiskSystem *bestDiskSystem = NULL;
void *bestCookie = NULL;
int32 itCookie;
int32 itCookie = 0;
while (KDiskSystem *diskSystem = LoadNextDiskSystem(&itCookie)) {
DBG(OUT(" trying: %s\n", diskSystem->Name()));
void *cookie = NULL;
float priority = diskSystem->Identify(partition, &cookie);
DBG(OUT(" returned: %f\n", priority));
if (priority >= 0 && priority > bestPriority) {
// new best disk system
if (bestDiskSystem) {
@ -539,8 +577,11 @@ KDiskDeviceManager::_ScanPartition(KPartition *partition)
// now, if we have found a disk system, let it scan the partition
status_t error = B_OK;
if (bestDiskSystem) {
DBG(OUT(" scanning with: %s\n", bestDiskSystem->Name()));
error = bestDiskSystem->Scan(partition, bestCookie);
if (error == B_OK) {
// TODO: Maybe better move setting the partition's and children's disk system
// in K{File,Partitioning}System::Scan()?
partition->SetDiskSystem(bestDiskSystem);
for (int32 i = 0; KPartition *child = partition->ChildAt(i); i++) {
child->SetParentDiskSystem(bestDiskSystem);
@ -548,6 +589,7 @@ KDiskDeviceManager::_ScanPartition(KPartition *partition)
}
} else {
// TODO: Handle the error.
DBG(OUT(" scanning failed: %s\n", strerror(error)));
}
// now we can safely unload the disk system -- it has been loaded by
// the partition(s) and thus will not really be unloaded

View File

@ -8,11 +8,12 @@
// constructor
KDiskSystem::KDiskSystem(const char *name)
: fID(-1),
: fID(_NextID()),
fName(NULL),
fPrettyName(NULL),
fLoadCounter(0)
{
set_string(fName, name);
}
// destructor
@ -25,8 +26,7 @@ KDiskSystem::~KDiskSystem()
status_t
KDiskSystem::Init()
{
// to be implemented by derived classes
return B_OK;
return (fName ? B_OK : B_NO_MEMORY);
}
// SetID
@ -411,3 +411,14 @@ KDiskSystem::SetPrettyName(const char *name)
return set_string(fPrettyName, name);
}
// _NextID
int32
KDiskSystem::_NextID()
{
return atomic_add(&fNextID, 1);
}
// fNextID
int32 KDiskSystem::fNextID = 0;

View File

@ -11,7 +11,8 @@
// constructor
KPartitioningSystem::KPartitioningSystem(const char *name)
: KDiskSystem(name)
: KDiskSystem(name),
fModule(NULL)
{
}

View File

@ -1,10 +1,17 @@
// disk_device_manager.cpp
#include <stdio.h>
#include "disk_device_manager.h"
#include "KDiskDevice.h"
#include "KDiskDeviceManager.h"
#include "KPartition.h"
// debugging
//#define DBG(x)
#define DBG(x) x
#define OUT printf
// write_lock_disk_device
disk_device_data *
write_lock_disk_device(partition_id partitionID)
@ -125,14 +132,18 @@ get_child_partition(partition_id partitionID, int32 index)
// create_child_partition
partition_data *
create_child_partition(partition_id partitionID, int32 index,
partition_id *childID)
partition_id childID)
{
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
if (KPartition *partition = manager->FindPartition(partitionID)) {
KPartition *child = NULL;
if (partition->CreateChild(*childID, index, &child) == B_OK)
if (partition->CreateChild(childID, index, &child) == B_OK)
return child->PartitionData();
else
DBG(OUT(" creating child (%ld, %ld) failed\n", partitionID, index));
}
else
DBG(OUT(" partition %ld not found\n", partitionID));
return NULL;
}