diff --git a/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h b/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h index d203596727..edd7f4a119 100644 --- a/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h +++ b/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h @@ -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); diff --git a/headers/private/kernel/disk_device_manager/KDiskSystem.h b/headers/private/kernel/disk_device_manager/KDiskSystem.h index f58af9fc1f..39b7d05124 100644 --- a/headers/private/kernel/disk_device_manager/KDiskSystem.h +++ b/headers/private/kernel/disk_device_manager/KDiskSystem.h @@ -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 diff --git a/headers/private/kernel/disk_device_manager/disk_device_manager.h b/headers/private/kernel/disk_device_manager/disk_device_manager.h index 51020db3eb..2f798e6046 100644 --- a/headers/private/kernel/disk_device_manager/disk_device_manager.h +++ b/headers/private/kernel/disk_device_manager/disk_device_manager.h @@ -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 diff --git a/src/kernel/core/disk_device_manager/KDiskDevice.cpp b/src/kernel/core/disk_device_manager/KDiskDevice.cpp index 8fe80b4404..8996f7278b 100644 --- a/src/kernel/core/disk_device_manager/KDiskDevice.cpp +++ b/src/kernel/core/disk_device_manager/KDiskDevice.cpp @@ -19,6 +19,7 @@ KDiskDevice::KDiskDevice(partition_id id) fShadowOwner(-1) { Unset(); + fDevice = this; } // destructor diff --git a/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp b/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp index 4901b78613..34bea4f366 100644 --- a/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp +++ b/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp @@ -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 diff --git a/src/kernel/core/disk_device_manager/KDiskSystem.cpp b/src/kernel/core/disk_device_manager/KDiskSystem.cpp index 2ddaeb8908..a26bde442b 100644 --- a/src/kernel/core/disk_device_manager/KDiskSystem.cpp +++ b/src/kernel/core/disk_device_manager/KDiskSystem.cpp @@ -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; + diff --git a/src/kernel/core/disk_device_manager/KPartitioningSystem.cpp b/src/kernel/core/disk_device_manager/KPartitioningSystem.cpp index b325c26ca2..eaebbc2eff 100644 --- a/src/kernel/core/disk_device_manager/KPartitioningSystem.cpp +++ b/src/kernel/core/disk_device_manager/KPartitioningSystem.cpp @@ -11,7 +11,8 @@ // constructor KPartitioningSystem::KPartitioningSystem(const char *name) - : KDiskSystem(name) + : KDiskSystem(name), + fModule(NULL) { } diff --git a/src/kernel/core/disk_device_manager/disk_device_manager.cpp b/src/kernel/core/disk_device_manager/disk_device_manager.cpp index 4382bcd3cd..0b72e8c664 100644 --- a/src/kernel/core/disk_device_manager/disk_device_manager.cpp +++ b/src/kernel/core/disk_device_manager/disk_device_manager.cpp @@ -1,10 +1,17 @@ // disk_device_manager.cpp +#include + #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; }