From 2438192b6cfcf6a50ade22941e7f8193c00f9f9a Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 15 Jul 2003 01:05:50 +0000 Subject: [PATCH] Added a deviceOnly flag to {Find,Register}Device(). Minor {Create,Delete}FileDevice() changes. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3975 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../disk_device_manager/KDiskDeviceManager.h | 7 +-- .../KDiskDeviceManager.cpp | 48 ++++++++++++++----- .../disk_device_manager.cpp | 2 +- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h b/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h index d765bf798f..5571c20023 100644 --- a/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h +++ b/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h @@ -38,20 +38,21 @@ public: // manager must be locked KDiskDevice *FindDevice(const char *path); - KDiskDevice *FindDevice(partition_id id); + KDiskDevice *FindDevice(partition_id id, bool deviceOnly = true); KPartition *FindPartition(const char *path, bool noShadow = false); KPartition *FindPartition(partition_id id, bool noShadow = false); KFileDiskDevice *FindFileDevice(const char *filePath); KDiskDevice *RegisterDevice(const char *path); - KDiskDevice *RegisterDevice(partition_id id); + KDiskDevice *RegisterDevice(partition_id id, bool deviceOnly = true); KDiskDevice *RegisterNextDevice(int32 *cookie); KPartition *RegisterPartition(const char *path, bool noShadow = false); KPartition *RegisterPartition(partition_id id, bool noShadow = false); KFileDiskDevice *RegisterFileDevice(const char *filePath); - status_t CreateFileDevice(const char *filePath, partition_id *device = 0); + partition_id CreateFileDevice(const char *filePath); status_t DeleteFileDevice(const char *filePath); + status_t DeleteFileDevice(partition_id id); // manager must be locked int32 CountDevices(); diff --git a/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp b/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp index fc7074b682..18497ea12a 100644 --- a/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp +++ b/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp @@ -121,10 +121,18 @@ KDiskDeviceManager::~KDiskDeviceManager() if (fPartitions->Count() > 0) { DBG(OUT("WARNING: There are still %ld unremoved partitions!\n", fPartitions->Count())); + for (PartitionMap::Iterator it = fPartitions->Begin(); + it != fPartitions->End(); ++it) { + DBG(OUT(" partition: %ld\n", it->Value()->ID())); + } } if (fObsoletePartitions->Count() > 0) { DBG(OUT("WARNING: There are still %ld obsolete partitions!\n", fObsoletePartitions->Count())); + for (PartitionSet::Iterator it = fObsoletePartitions->Begin(); + it != fObsoletePartitions->End(); ++it) { + DBG(OUT(" partition: %ld\n", (*it)->ID())); + } } // remove all disk systems for (int32 cookie = 0; @@ -214,10 +222,13 @@ KDiskDeviceManager::FindDevice(const char *path) // FindDevice KDiskDevice * -KDiskDeviceManager::FindDevice(partition_id id) +KDiskDeviceManager::FindDevice(partition_id id, bool deviceOnly) { - if (KPartition *partition = FindPartition(id)) - return partition->Device(); + if (KPartition *partition = FindPartition(id)) { + KDiskDevice *device = partition->Device(); + if (!deviceOnly || id == device->ID()) + return device; + } return NULL; } @@ -283,10 +294,10 @@ KDiskDeviceManager::RegisterDevice(const char *path) // RegisterDevice KDiskDevice * -KDiskDeviceManager::RegisterDevice(partition_id id) +KDiskDeviceManager::RegisterDevice(partition_id id, bool deviceOnly) { if (ManagerLocker locker = this) { - if (KDiskDevice *device = FindDevice(id)) { + if (KDiskDevice *device = FindDevice(id, deviceOnly)) { device->Register(); return device; } @@ -349,13 +360,13 @@ KDiskDeviceManager::RegisterFileDevice(const char *filePath) } // CreateFileDevice -status_t -KDiskDeviceManager::CreateFileDevice(const char *filePath, - partition_id *deviceID) +partition_id +KDiskDeviceManager::CreateFileDevice(const char *filePath) { if (!filePath) return B_BAD_VALUE; status_t error = B_ERROR; + partition_id deviceID = -1; KFileDiskDevice *device = NULL; if (ManagerLocker locker = this) { // check, if the device does already exist @@ -374,8 +385,7 @@ KDiskDeviceManager::CreateFileDevice(const char *filePath, delete device; return error; } - if (deviceID) - *deviceID = device->ID(); + deviceID = device->ID(); device->Register(); } // scan device @@ -383,7 +393,7 @@ KDiskDeviceManager::CreateFileDevice(const char *filePath, _ScanDevice(device); device->Unregister(); } - return error; + return (error == B_OK ? deviceID : error); } // DeleteFileDevice @@ -400,6 +410,22 @@ KDiskDeviceManager::DeleteFileDevice(const char *filePath) return B_ERROR; } +// DeleteFileDevice +status_t +KDiskDeviceManager::DeleteFileDevice(partition_id id) +{ + if (KDiskDevice *device = RegisterDevice(id)) { + PartitionRegistrar _(device, true); + if (!dynamic_cast(device) || id != device->ID()) + return B_ENTRY_NOT_FOUND; + if (DeviceWriteLocker locker = device) { + if (_RemoveDevice(device)) + return B_OK; + } + } + return B_ERROR; +} + // CountDevices int32 KDiskDeviceManager::CountDevices() 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 61d829d82e..8bd20f773b 100644 --- a/src/kernel/core/disk_device_manager/disk_device_manager.cpp +++ b/src/kernel/core/disk_device_manager/disk_device_manager.cpp @@ -105,7 +105,7 @@ disk_device_data * get_disk_device(partition_id partitionID) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); - KDiskDevice *device = manager->FindDevice(partitionID); + KDiskDevice *device = manager->FindDevice(partitionID, false); return (device ? device->DeviceData() : NULL); }