From b4147ed31765aef192b3115482f4ec6ff5875f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 10 Jul 2008 12:21:05 +0000 Subject: [PATCH] * RescanDiskSystems() now locks the disk device manager, as it clobbers the disk system lists. * Added module watching; on module changes, it will now automatically rescan the disk systems. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26368 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../disk_device_manager/KDiskDeviceManager.h | 2 + .../KDiskDeviceManager.cpp | 47 +++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h b/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h index 110080dda5..cf4a62d964 100644 --- a/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h +++ b/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h @@ -102,6 +102,7 @@ private: struct DiskSystemMap; struct PartitionMap; struct PartitionSet; + class DiskSystemWatcher; class DeviceWatcher; static status_t _CheckMediaStatusDaemon(void* self); @@ -132,6 +133,7 @@ private: PartitionSet *fObsoletePartitions; thread_id fMediaChecker; volatile bool fTerminating; + DiskSystemWatcher *fDiskSystemWatcher; DeviceWatcher *fDeviceWatcher; static KDiskDeviceManager *sDefaultManager; diff --git a/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp b/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp index da0583b8aa..4dae5b2a62 100644 --- a/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp +++ b/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp @@ -21,11 +21,13 @@ #include #include -#include - #include + +#include +#include #include #include +#include #include #include @@ -92,6 +94,30 @@ struct KDiskDeviceManager::PartitionSet : VectorSet { }; +class KDiskDeviceManager::DiskSystemWatcher : public NotificationListener { +public: + DiskSystemWatcher(KDiskDeviceManager* manager) + : + fManager(manager) + { + } + + virtual ~DiskSystemWatcher() + { + } + + virtual void EventOccured(NotificationService& service, + const KMessage* event) + { + if (event->GetInt32("opcode", -1) != B_ENTRY_REMOVED) + fManager->RescanDiskSystems(); + } + +private: + KDiskDeviceManager* fManager; +}; + + // DeviceWatcher class KDiskDeviceManager::DeviceWatcher : public NotificationListener { public: @@ -170,6 +196,7 @@ KDiskDeviceManager::KDiskDeviceManager() fObsoletePartitions(new(nothrow) PartitionSet), fMediaChecker(-1), fTerminating(false), + fDiskSystemWatcher(NULL), fDeviceWatcher(new(nothrow) DeviceWatcher(this)) { if (InitCheck() != B_OK) @@ -905,9 +932,17 @@ KDiskDeviceManager::StartMonitoring() { // do another scan, this will populate the devfs directories InitialDeviceScan(); + + // start monitoring the disk systems + fDiskSystemWatcher = new(std::nothrow) DiskSystemWatcher(this); + if (fDiskSystemWatcher != NULL) { + start_watching_modules(kFileSystemPrefix, *fDiskSystemWatcher); + start_watching_modules(kPartitioningSystemPrefix, + *fDiskSystemWatcher); + } + // start monitoring all dirs under /dev/disk - status_t result = _AddRemoveMonitoring("/dev/disk", true); - return result; + return _AddRemoveMonitoring("/dev/disk", true); } @@ -959,10 +994,14 @@ KDiskDeviceManager::RescanDiskSystems() { DiskSystemMap addedSystems; + Lock(); + // rescan for partitioning and file systems _RescanDiskSystems(addedSystems, false); _RescanDiskSystems(addedSystems, true); + Unlock(); + // rescan existing devices with the new disk systems int32 cookie = 0; while (KDiskDevice *device = RegisterNextDevice(&cookie)) {