2006-05-05 14:54:10 +04:00
|
|
|
/*
|
2007-10-17 21:05:48 +04:00
|
|
|
* Copyright 2004-2007, Haiku, Inc. All rights reserved.
|
2006-05-05 14:54:10 +04:00
|
|
|
* Copyright 2003-2004, Ingo Weinhold, bonefish@cs.tu-berlin.de. All rights reserved.
|
|
|
|
*
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2003-06-10 03:04:54 +04:00
|
|
|
#ifndef _K_DISK_DEVICE_MANAGER_H
|
|
|
|
#define _K_DISK_DEVICE_MANAGER_H
|
|
|
|
|
2006-05-05 14:54:10 +04:00
|
|
|
|
2007-10-17 21:05:48 +04:00
|
|
|
#include <disk_device_manager.h>
|
|
|
|
#include <Locker.h>
|
2003-06-10 03:04:54 +04:00
|
|
|
|
2006-05-05 14:54:10 +04:00
|
|
|
|
2003-06-10 03:04:54 +04:00
|
|
|
namespace BPrivate {
|
|
|
|
namespace DiskDevice {
|
|
|
|
|
|
|
|
class KDiskDevice;
|
|
|
|
class KDiskSystem;
|
2003-06-23 03:00:20 +04:00
|
|
|
class KFileDiskDevice;
|
2003-06-10 03:04:54 +04:00
|
|
|
class KPartition;
|
|
|
|
|
|
|
|
class KDiskDeviceManager {
|
2003-06-11 02:35:57 +04:00
|
|
|
public:
|
2003-06-10 03:04:54 +04:00
|
|
|
KDiskDeviceManager();
|
|
|
|
~KDiskDeviceManager();
|
|
|
|
|
2003-06-11 02:35:57 +04:00
|
|
|
status_t InitCheck() const;
|
|
|
|
|
2003-06-10 03:04:54 +04:00
|
|
|
// Singleton Creation, Deletion, and Access
|
|
|
|
|
|
|
|
static status_t CreateDefault();
|
|
|
|
static void DeleteDefault();
|
|
|
|
static KDiskDeviceManager *Default();
|
|
|
|
|
|
|
|
// Locking
|
|
|
|
|
|
|
|
bool Lock();
|
|
|
|
void Unlock();
|
|
|
|
|
|
|
|
// Disk Device / Partition Management
|
|
|
|
|
2003-06-12 01:59:27 +04:00
|
|
|
// manager must be locked
|
2003-07-05 03:45:26 +04:00
|
|
|
KDiskDevice *FindDevice(const char *path);
|
2003-07-15 05:05:50 +04:00
|
|
|
KDiskDevice *FindDevice(partition_id id, bool deviceOnly = true);
|
2007-11-02 02:36:21 +03:00
|
|
|
KPartition *FindPartition(const char *path);
|
|
|
|
KPartition *FindPartition(partition_id id);
|
2003-07-05 03:45:26 +04:00
|
|
|
KFileDiskDevice *FindFileDevice(const char *filePath);
|
|
|
|
|
|
|
|
KDiskDevice *RegisterDevice(const char *path);
|
2003-07-15 05:05:50 +04:00
|
|
|
KDiskDevice *RegisterDevice(partition_id id, bool deviceOnly = true);
|
2003-06-13 02:21:10 +04:00
|
|
|
KDiskDevice *RegisterNextDevice(int32 *cookie);
|
2007-11-02 02:36:21 +03:00
|
|
|
KPartition *RegisterPartition(const char *path);
|
|
|
|
KPartition *RegisterPartition(partition_id id);
|
2003-07-05 03:45:26 +04:00
|
|
|
KFileDiskDevice *RegisterFileDevice(const char *filePath);
|
2003-06-23 03:00:20 +04:00
|
|
|
|
2003-07-16 01:39:34 +04:00
|
|
|
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.
|
|
|
|
|
2007-11-02 01:41:22 +03:00
|
|
|
status_t ScanPartition(KPartition* partition);
|
2007-10-04 22:03:24 +04:00
|
|
|
|
2008-04-03 22:14:11 +04:00
|
|
|
partition_id CreateDevice(const char *path, bool *newlyCreated = NULL);
|
|
|
|
status_t DeleteDevice(const char *path);
|
|
|
|
|
2007-11-02 01:41:22 +03:00
|
|
|
partition_id CreateFileDevice(const char* filePath,
|
|
|
|
bool* newlyCreated = NULL);
|
2003-06-23 03:00:20 +04:00
|
|
|
status_t DeleteFileDevice(const char *filePath);
|
2003-07-15 05:05:50 +04:00
|
|
|
status_t DeleteFileDevice(partition_id id);
|
2003-06-10 03:04:54 +04:00
|
|
|
|
|
|
|
// manager must be locked
|
2003-06-13 02:21:10 +04:00
|
|
|
int32 CountDevices();
|
2003-07-02 20:29:33 +04:00
|
|
|
KDiskDevice *NextDevice(int32 *cookie);
|
2003-06-10 03:04:54 +04:00
|
|
|
|
2003-06-11 02:35:57 +04:00
|
|
|
bool PartitionAdded(KPartition *partition); // implementation internal
|
|
|
|
bool PartitionRemoved(KPartition *partition); //
|
2003-06-25 03:56:16 +04:00
|
|
|
bool DeletePartition(KPartition *partition); //
|
2003-06-10 03:04:54 +04:00
|
|
|
|
|
|
|
// Disk Systems
|
|
|
|
|
|
|
|
// manager must be locked
|
2007-11-10 23:30:22 +03:00
|
|
|
KDiskSystem *FindDiskSystem(const char *name, bool byPrettyName = false);
|
2003-07-09 03:23:27 +04:00
|
|
|
KDiskSystem *FindDiskSystem(disk_system_id id);
|
2003-06-11 02:35:57 +04:00
|
|
|
int32 CountDiskSystems();
|
2003-07-02 20:29:33 +04:00
|
|
|
KDiskSystem *NextDiskSystem(int32 *cookie);
|
2003-06-10 03:04:54 +04:00
|
|
|
|
2007-11-10 23:30:22 +03:00
|
|
|
KDiskSystem *LoadDiskSystem(const char *name, bool byPrettyName = false);
|
2003-06-13 02:21:10 +04:00
|
|
|
KDiskSystem *LoadDiskSystem(disk_system_id id);
|
|
|
|
KDiskSystem *LoadNextDiskSystem(int32 *cookie);
|
|
|
|
|
|
|
|
status_t InitialDeviceScan();
|
2006-09-04 16:37:56 +04:00
|
|
|
status_t RescanDiskSystems();
|
2008-04-03 22:14:11 +04:00
|
|
|
status_t StartMonitoring();
|
2003-06-13 02:21:10 +04:00
|
|
|
|
2003-06-11 02:35:57 +04:00
|
|
|
private:
|
2008-06-30 14:36:47 +04:00
|
|
|
struct DeviceMap;
|
|
|
|
struct DiskSystemMap;
|
|
|
|
struct PartitionMap;
|
|
|
|
struct PartitionSet;
|
2008-07-10 16:21:05 +04:00
|
|
|
class DiskSystemWatcher;
|
2008-06-30 14:36:47 +04:00
|
|
|
class DeviceWatcher;
|
|
|
|
|
2007-11-12 21:41:36 +03:00
|
|
|
static status_t _CheckMediaStatusDaemon(void* self);
|
|
|
|
status_t _CheckMediaStatus();
|
2007-10-17 21:05:48 +04:00
|
|
|
|
2008-06-30 14:36:47 +04:00
|
|
|
status_t _RescanDiskSystems(DiskSystemMap& addedSystems, bool fileSystems);
|
2007-07-19 17:33:41 +04:00
|
|
|
|
2003-06-12 01:59:27 +04:00
|
|
|
status_t _AddPartitioningSystem(const char *name);
|
|
|
|
status_t _AddFileSystem(const char *name);
|
|
|
|
status_t _AddDiskSystem(KDiskSystem *diskSystem);
|
2003-06-11 02:35:57 +04:00
|
|
|
|
2003-06-14 02:08:10 +04:00
|
|
|
bool _AddDevice(KDiskDevice *device);
|
|
|
|
bool _RemoveDevice(KDiskDevice *device);
|
|
|
|
|
2003-06-13 02:21:10 +04:00
|
|
|
status_t _Scan(const char *path);
|
2008-06-30 14:36:47 +04:00
|
|
|
status_t _ScanPartition(KPartition *partition, bool async,
|
|
|
|
DiskSystemMap* restrictScan = NULL);
|
2003-08-03 22:39:12 +04:00
|
|
|
// the manager must be locked and the device write locked
|
2008-06-30 14:36:47 +04:00
|
|
|
status_t _ScanPartition(KPartition *partition,
|
|
|
|
DiskSystemMap* restrictScan);
|
2003-06-13 02:21:10 +04:00
|
|
|
|
2008-04-03 22:14:11 +04:00
|
|
|
status_t _AddRemoveMonitoring(const char *path, bool add);
|
|
|
|
|
2003-06-11 02:35:57 +04:00
|
|
|
BLocker fLock;
|
2003-07-02 20:29:33 +04:00
|
|
|
DeviceMap *fDevices;
|
|
|
|
PartitionMap *fPartitions;
|
|
|
|
DiskSystemMap *fDiskSystems;
|
|
|
|
PartitionSet *fObsoletePartitions;
|
2007-11-12 21:41:36 +03:00
|
|
|
thread_id fMediaChecker;
|
|
|
|
volatile bool fTerminating;
|
2008-07-10 16:21:05 +04:00
|
|
|
DiskSystemWatcher *fDiskSystemWatcher;
|
2008-04-03 22:14:11 +04:00
|
|
|
DeviceWatcher *fDeviceWatcher;
|
2003-06-11 02:35:57 +04:00
|
|
|
|
2004-06-13 00:59:52 +04:00
|
|
|
static KDiskDeviceManager *sDefaultManager;
|
2003-06-10 03:04:54 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace DiskDevice
|
|
|
|
} // namespace BPrivate
|
|
|
|
|
|
|
|
using BPrivate::DiskDevice::KDiskDeviceManager;
|
|
|
|
|
|
|
|
#endif // _K_DISK_DEVICE_MANAGER_H
|