haiku/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h
Michael Lotz 06da81f012 Implement node monitoring in the kernel disk device manager.
* Added {Create|Delete}Device() analogous to {Create|Delete}FileDevice
* Added a small DeviceWatcher class that reacts to entry creation/removal
* Implemented a way to start/stop node monitoring
* Start watching for devices after the boot volume has been mounted and the
  the second initial scan was run

The disk device manager now creates and scans a device when a "raw" node is
published and deletes the device on removal. This makes hot-plugging of disk
devices (for example memory sticks using usb_disk) work. Their partitions will
be scanned and published so they can be mounted. Somehow the removal of the
partitions does not yet work however, any insights are welcome.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24777 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-04-03 18:14:11 +00:00

145 lines
4.1 KiB
C++

/*
* 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.
*/
#ifndef _K_DISK_DEVICE_MANAGER_H
#define _K_DISK_DEVICE_MANAGER_H
#include <disk_device_manager.h>
#include <Locker.h>
namespace BPrivate {
namespace DiskDevice {
class KDiskDevice;
class KDiskSystem;
class KFileDiskDevice;
class KPartition;
class KDiskDeviceManager {
public:
KDiskDeviceManager();
~KDiskDeviceManager();
status_t InitCheck() const;
// Singleton Creation, Deletion, and Access
static status_t CreateDefault();
static void DeleteDefault();
static KDiskDeviceManager *Default();
// Locking
bool Lock();
void Unlock();
// Disk Device / Partition Management
// manager must be locked
KDiskDevice *FindDevice(const char *path);
KDiskDevice *FindDevice(partition_id id, bool deviceOnly = true);
KPartition *FindPartition(const char *path);
KPartition *FindPartition(partition_id id);
KFileDiskDevice *FindFileDevice(const char *filePath);
KDiskDevice *RegisterDevice(const char *path);
KDiskDevice *RegisterDevice(partition_id id, bool deviceOnly = true);
KDiskDevice *RegisterNextDevice(int32 *cookie);
KPartition *RegisterPartition(const char *path);
KPartition *RegisterPartition(partition_id id);
KFileDiskDevice *RegisterFileDevice(const char *filePath);
KDiskDevice *ReadLockDevice(partition_id id, bool deviceOnly = true);
KDiskDevice *WriteLockDevice(partition_id id, bool deviceOnly = true);
// The device is also registered and must be unregistered by the
// caller.
KPartition *ReadLockPartition(partition_id id);
KPartition *WriteLockPartition(partition_id id);
// Both the device and the partition is also registered and must be
// unregistered by the caller.
status_t ScanPartition(KPartition* partition);
partition_id CreateDevice(const char *path, bool *newlyCreated = NULL);
status_t DeleteDevice(const char *path);
partition_id CreateFileDevice(const char* filePath,
bool* newlyCreated = NULL);
status_t DeleteFileDevice(const char *filePath);
status_t DeleteFileDevice(partition_id id);
// manager must be locked
int32 CountDevices();
KDiskDevice *NextDevice(int32 *cookie);
bool PartitionAdded(KPartition *partition); // implementation internal
bool PartitionRemoved(KPartition *partition); //
bool DeletePartition(KPartition *partition); //
// Disk Systems
// manager must be locked
KDiskSystem *FindDiskSystem(const char *name, bool byPrettyName = false);
KDiskSystem *FindDiskSystem(disk_system_id id);
int32 CountDiskSystems();
KDiskSystem *NextDiskSystem(int32 *cookie);
KDiskSystem *LoadDiskSystem(const char *name, bool byPrettyName = false);
KDiskSystem *LoadDiskSystem(disk_system_id id);
KDiskSystem *LoadNextDiskSystem(int32 *cookie);
status_t InitialDeviceScan();
status_t RescanDiskSystems();
status_t StartMonitoring();
private:
static status_t _CheckMediaStatusDaemon(void* self);
status_t _CheckMediaStatus();
status_t _RescanDiskSystems(bool fileSystems);
status_t _AddPartitioningSystem(const char *name);
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, bool async);
// the manager must be locked and the device write locked
status_t _ScanPartition(KPartition *partition);
// used by the other _ScanPartition() version only
status_t _AddRemoveMonitoring(const char *path, bool add);
struct DeviceMap;
struct DiskSystemMap;
struct PartitionMap;
struct PartitionSet;
class DeviceWatcher;
BLocker fLock;
DeviceMap *fDevices;
PartitionMap *fPartitions;
DiskSystemMap *fDiskSystems;
PartitionSet *fObsoletePartitions;
thread_id fMediaChecker;
volatile bool fTerminating;
DeviceWatcher *fDeviceWatcher;
static KDiskDeviceManager *sDefaultManager;
};
} // namespace DiskDevice
} // namespace BPrivate
using BPrivate::DiskDevice::KDiskDeviceManager;
#endif // _K_DISK_DEVICE_MANAGER_H