2 * Copyright 2004-2009, Haiku, Inc. All rights reserved.
3 * Copyright 2003-2004, Ingo Weinhold, bonefish@cs.tu-berlin.de. All rights reserved.
5 * Distributed under the terms of the MIT License.
7 #ifndef _K_DISK_DEVICE_MANAGER_H
8 #define _K_DISK_DEVICE_MANAGER_H
11 #include <disk_device_manager.h>
13 #include <Notifications.h>
17 namespace DiskDevice
{
21 class KFileDiskDevice
;
24 class KDiskDeviceManager
{
27 ~KDiskDeviceManager();
29 status_t
InitCheck() const;
31 // Singleton Creation, Deletion, and Access
33 static status_t
CreateDefault();
34 static void DeleteDefault();
35 static KDiskDeviceManager
*Default();
42 // Disk Device / Partition Management
44 DefaultUserNotificationService
& Notifications();
45 void Notify(const KMessage
& event
, uint32 eventMask
);
47 // manager must be locked
48 KDiskDevice
*FindDevice(const char *path
);
49 KDiskDevice
*FindDevice(partition_id id
, bool deviceOnly
= true);
50 KPartition
*FindPartition(const char *path
);
51 KPartition
*FindPartition(partition_id id
);
52 KFileDiskDevice
*FindFileDevice(const char *filePath
);
54 KDiskDevice
*RegisterDevice(const char *path
);
55 KDiskDevice
*RegisterDevice(partition_id id
, bool deviceOnly
= true);
56 KDiskDevice
*RegisterNextDevice(int32
*cookie
);
57 KPartition
*RegisterPartition(const char *path
);
58 KPartition
*RegisterPartition(partition_id id
);
59 KFileDiskDevice
*RegisterFileDevice(const char *filePath
);
61 KDiskDevice
*ReadLockDevice(partition_id id
, bool deviceOnly
= true);
62 KDiskDevice
*WriteLockDevice(partition_id id
, bool deviceOnly
= true);
63 // The device is also registered and must be unregistered by the
65 KPartition
*ReadLockPartition(partition_id id
);
66 KPartition
*WriteLockPartition(partition_id id
);
67 // Both the device and the partition is also registered and must be
68 // unregistered by the caller.
70 status_t
ScanPartition(KPartition
* partition
);
72 partition_id
CreateDevice(const char *path
, bool *newlyCreated
= NULL
);
73 status_t
DeleteDevice(const char *path
);
75 partition_id
CreateFileDevice(const char* filePath
,
76 bool* newlyCreated
= NULL
);
77 status_t
DeleteFileDevice(const char *filePath
);
78 status_t
DeleteFileDevice(partition_id id
);
80 // manager must be locked
82 KDiskDevice
*NextDevice(int32
*cookie
);
84 bool PartitionAdded(KPartition
*partition
); // implementation internal
85 bool PartitionRemoved(KPartition
*partition
); //
86 bool DeletePartition(KPartition
*partition
); //
90 // manager must be locked
91 KDiskSystem
*FindDiskSystem(const char *name
, bool byPrettyName
= false);
92 KDiskSystem
*FindDiskSystem(disk_system_id id
);
93 int32
CountDiskSystems();
94 KDiskSystem
*NextDiskSystem(int32
*cookie
);
96 KDiskSystem
*LoadDiskSystem(const char *name
, bool byPrettyName
= false);
97 KDiskSystem
*LoadDiskSystem(disk_system_id id
);
98 KDiskSystem
*LoadNextDiskSystem(int32
*cookie
);
100 status_t
InitialDeviceScan();
101 status_t
RescanDiskSystems();
102 status_t
StartMonitoring();
106 struct DiskSystemMap
;
109 class DiskSystemWatcher
;
111 class DiskNotifications
;
113 static status_t
_CheckMediaStatusDaemon(void* self
);
114 status_t
_CheckMediaStatus();
116 status_t
_RescanDiskSystems(DiskSystemMap
& addedSystems
, bool fileSystems
);
118 status_t
_AddPartitioningSystem(const char *name
);
119 status_t
_AddFileSystem(const char *name
);
120 status_t
_AddDiskSystem(KDiskSystem
*diskSystem
);
122 bool _AddDevice(KDiskDevice
*device
);
123 bool _RemoveDevice(KDiskDevice
*device
);
125 status_t
_Scan(const char *path
);
126 status_t
_ScanPartition(KPartition
*partition
, bool async
,
127 DiskSystemMap
* restrictScan
= NULL
);
128 // the manager must be locked and the device write locked
129 status_t
_ScanPartition(KPartition
*partition
,
130 DiskSystemMap
* restrictScan
);
132 status_t
_AddRemoveMonitoring(const char *path
, bool add
);
134 void _NotifyDeviceEvent(KDiskDevice
* device
, int32 event
, uint32 mask
);
136 recursive_lock fLock
;
138 PartitionMap
*fPartitions
;
139 DiskSystemMap
*fDiskSystems
;
140 PartitionSet
*fObsoletePartitions
;
141 thread_id fMediaChecker
;
142 volatile bool fTerminating
;
143 DiskSystemWatcher
*fDiskSystemWatcher
;
144 DeviceWatcher
*fDeviceWatcher
;
145 DiskNotifications
* fNotifications
;
147 static KDiskDeviceManager
*sDefaultManager
;
150 } // namespace DiskDevice
151 } // namespace BPrivate
153 using BPrivate::DiskDevice::KDiskDeviceManager
;
155 #endif // _K_DISK_DEVICE_MANAGER_H