The disk device manager now periodically checks for media changes - all it does

is dump its findings, but it's an (untested) start.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22598 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2007-10-17 17:05:48 +00:00
parent 10ffdaa294
commit 8047441723
3 changed files with 66 additions and 7 deletions

View File

@ -1,5 +1,7 @@
// KDiskDevice.h
/*
* Copyright 2003-2007, Ingo Weinhold, bonefish@cs.tu-berlin.de. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _K_DISK_DEVICE_H
#define _K_DISK_DEVICE_H
@ -50,6 +52,8 @@ public:
bool IsRemovable() const;
bool HasMedia() const;
virtual status_t GetMediaStatus(status_t *mediaStatus);
status_t SetPath(const char *path);
// TODO: Remove this method or make it private. Once initialized the
// path must not be changed.
@ -77,7 +81,6 @@ public:
virtual void Dump(bool deep = true, int32 level = 0);
protected:
virtual status_t GetMediaStatus(status_t *mediaStatus);
virtual status_t GetGeometry(device_geometry *geometry);
private:

View File

@ -1,5 +1,5 @@
/*
* Copyright 2004-2006, Haiku, Inc. All rights reserved.
* Copyright 2004-2007, Haiku, Inc. All rights reserved.
* Copyright 2003-2004, Ingo Weinhold, bonefish@cs.tu-berlin.de. All rights reserved.
*
* Distributed under the terms of the MIT License.
@ -8,8 +8,8 @@
#define _K_DISK_DEVICE_MANAGER_H
#include "disk_device_manager.h"
#include "Locker.h"
#include <disk_device_manager.h>
#include <Locker.h>
namespace BPrivate {
@ -125,6 +125,9 @@ public:
status_t RescanDiskSystems();
private:
static void _CheckMediaStatusDaemon(void* self, int iteration);
void _CheckMediaStatus();
status_t _RescanDiskSystems(bool fileSystems);
status_t _AddPartitioningSystem(const char *name);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2004-2006, Haiku, Inc. All rights reserved.
* Copyright 2004-2007, Haiku, Inc. All rights reserved.
* Copyright 2003-2004, Ingo Weinhold, bonefish@cs.tu-berlin.de. All rights reserved.
*
* Distributed under the terms of the MIT License.
@ -133,6 +133,9 @@ KDiskDeviceManager::KDiskDeviceManager()
RescanDiskSystems();
register_kernel_daemon(&_CheckMediaStatusDaemon, this, 10);
// once every second
DBG(OUT("number of disk systems: %ld\n", CountDiskSystems()));
// TODO: Watch the disk systems and the relevant directories.
}
@ -140,6 +143,8 @@ KDiskDeviceManager::KDiskDeviceManager()
KDiskDeviceManager::~KDiskDeviceManager()
{
unregister_kernel_daemon(&_CheckMediaStatusDaemon, this);
// TODO: terminate and remove all jobs
// remove all devices
for (int32 cookie = 0; KDiskDevice *device = NextDevice(&cookie);) {
@ -1243,3 +1248,51 @@ KDiskDeviceManager::_ScanPartition(KPartition *partition, bool async)
return status;
}
void
KDiskDeviceManager::_CheckMediaStatus()
{
ManagerLocker locker(this);
if (!locker.IsLocked())
return;
int32 cookie = 0;
while (true) {
KDiskDevice* device = NextDevice(&cookie);
if (device == NULL)
break;
status_t mediaStatus;
if (device->GetMediaStatus(&mediaStatus) == B_OK) {
bool removed = false;
bool changed = false;
switch (mediaStatus) {
case B_DEV_MEDIA_CHANGED:
changed = true;
break;
case B_DEV_NO_MEDIA:
case B_DEV_DOOR_OPEN:
removed = true;
break;
case B_DEV_MEDIA_CHANGE_REQUESTED:
case B_DEV_NOT_READY:
case B_OK:
break;
}
// TODO: propagate changes!
if (removed)
dprintf("Media removed from %s\n", device->Path());
if (changed)
dprintf("Media changed from %s\n", device->Path());
}
}
}
void
KDiskDeviceManager::_CheckMediaStatusDaemon(void* self, int iteration)
{
((KDiskDeviceManager*)self)->_CheckMediaStatus();
}