* 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
This commit is contained in:
Axel Dörfler 2008-07-10 12:21:05 +00:00
parent 30e5affa9f
commit b4147ed317
2 changed files with 45 additions and 4 deletions

View File

@ -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;

View File

@ -21,11 +21,13 @@
#include <VectorSet.h>
#include <KernelExport.h>
#include <util/kernel_cpp.h>
#include <NodeMonitor.h>
#include <boot_device.h>
#include <kmodule.h>
#include <node_monitor.h>
#include <Notifications.h>
#include <util/kernel_cpp.h>
#include <vfs.h>
#include <dirent.h>
@ -92,6 +94,30 @@ struct KDiskDeviceManager::PartitionSet : VectorSet<KPartition*> {
};
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)) {