Added a deviceOnly flag to {Find,Register}Device(). Minor {Create,Delete}FileDevice() changes.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3975 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
5d22fa967a
commit
2438192b6c
@ -38,20 +38,21 @@ public:
|
|||||||
|
|
||||||
// manager must be locked
|
// manager must be locked
|
||||||
KDiskDevice *FindDevice(const char *path);
|
KDiskDevice *FindDevice(const char *path);
|
||||||
KDiskDevice *FindDevice(partition_id id);
|
KDiskDevice *FindDevice(partition_id id, bool deviceOnly = true);
|
||||||
KPartition *FindPartition(const char *path, bool noShadow = false);
|
KPartition *FindPartition(const char *path, bool noShadow = false);
|
||||||
KPartition *FindPartition(partition_id id, bool noShadow = false);
|
KPartition *FindPartition(partition_id id, bool noShadow = false);
|
||||||
KFileDiskDevice *FindFileDevice(const char *filePath);
|
KFileDiskDevice *FindFileDevice(const char *filePath);
|
||||||
|
|
||||||
KDiskDevice *RegisterDevice(const char *path);
|
KDiskDevice *RegisterDevice(const char *path);
|
||||||
KDiskDevice *RegisterDevice(partition_id id);
|
KDiskDevice *RegisterDevice(partition_id id, bool deviceOnly = true);
|
||||||
KDiskDevice *RegisterNextDevice(int32 *cookie);
|
KDiskDevice *RegisterNextDevice(int32 *cookie);
|
||||||
KPartition *RegisterPartition(const char *path, bool noShadow = false);
|
KPartition *RegisterPartition(const char *path, bool noShadow = false);
|
||||||
KPartition *RegisterPartition(partition_id id, bool noShadow = false);
|
KPartition *RegisterPartition(partition_id id, bool noShadow = false);
|
||||||
KFileDiskDevice *RegisterFileDevice(const char *filePath);
|
KFileDiskDevice *RegisterFileDevice(const char *filePath);
|
||||||
|
|
||||||
status_t CreateFileDevice(const char *filePath, partition_id *device = 0);
|
partition_id CreateFileDevice(const char *filePath);
|
||||||
status_t DeleteFileDevice(const char *filePath);
|
status_t DeleteFileDevice(const char *filePath);
|
||||||
|
status_t DeleteFileDevice(partition_id id);
|
||||||
|
|
||||||
// manager must be locked
|
// manager must be locked
|
||||||
int32 CountDevices();
|
int32 CountDevices();
|
||||||
|
@ -121,10 +121,18 @@ KDiskDeviceManager::~KDiskDeviceManager()
|
|||||||
if (fPartitions->Count() > 0) {
|
if (fPartitions->Count() > 0) {
|
||||||
DBG(OUT("WARNING: There are still %ld unremoved partitions!\n",
|
DBG(OUT("WARNING: There are still %ld unremoved partitions!\n",
|
||||||
fPartitions->Count()));
|
fPartitions->Count()));
|
||||||
|
for (PartitionMap::Iterator it = fPartitions->Begin();
|
||||||
|
it != fPartitions->End(); ++it) {
|
||||||
|
DBG(OUT(" partition: %ld\n", it->Value()->ID()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (fObsoletePartitions->Count() > 0) {
|
if (fObsoletePartitions->Count() > 0) {
|
||||||
DBG(OUT("WARNING: There are still %ld obsolete partitions!\n",
|
DBG(OUT("WARNING: There are still %ld obsolete partitions!\n",
|
||||||
fObsoletePartitions->Count()));
|
fObsoletePartitions->Count()));
|
||||||
|
for (PartitionSet::Iterator it = fObsoletePartitions->Begin();
|
||||||
|
it != fObsoletePartitions->End(); ++it) {
|
||||||
|
DBG(OUT(" partition: %ld\n", (*it)->ID()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// remove all disk systems
|
// remove all disk systems
|
||||||
for (int32 cookie = 0;
|
for (int32 cookie = 0;
|
||||||
@ -214,10 +222,13 @@ KDiskDeviceManager::FindDevice(const char *path)
|
|||||||
|
|
||||||
// FindDevice
|
// FindDevice
|
||||||
KDiskDevice *
|
KDiskDevice *
|
||||||
KDiskDeviceManager::FindDevice(partition_id id)
|
KDiskDeviceManager::FindDevice(partition_id id, bool deviceOnly)
|
||||||
{
|
{
|
||||||
if (KPartition *partition = FindPartition(id))
|
if (KPartition *partition = FindPartition(id)) {
|
||||||
return partition->Device();
|
KDiskDevice *device = partition->Device();
|
||||||
|
if (!deviceOnly || id == device->ID())
|
||||||
|
return device;
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,10 +294,10 @@ KDiskDeviceManager::RegisterDevice(const char *path)
|
|||||||
|
|
||||||
// RegisterDevice
|
// RegisterDevice
|
||||||
KDiskDevice *
|
KDiskDevice *
|
||||||
KDiskDeviceManager::RegisterDevice(partition_id id)
|
KDiskDeviceManager::RegisterDevice(partition_id id, bool deviceOnly)
|
||||||
{
|
{
|
||||||
if (ManagerLocker locker = this) {
|
if (ManagerLocker locker = this) {
|
||||||
if (KDiskDevice *device = FindDevice(id)) {
|
if (KDiskDevice *device = FindDevice(id, deviceOnly)) {
|
||||||
device->Register();
|
device->Register();
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
@ -349,13 +360,13 @@ KDiskDeviceManager::RegisterFileDevice(const char *filePath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateFileDevice
|
// CreateFileDevice
|
||||||
status_t
|
partition_id
|
||||||
KDiskDeviceManager::CreateFileDevice(const char *filePath,
|
KDiskDeviceManager::CreateFileDevice(const char *filePath)
|
||||||
partition_id *deviceID)
|
|
||||||
{
|
{
|
||||||
if (!filePath)
|
if (!filePath)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
status_t error = B_ERROR;
|
status_t error = B_ERROR;
|
||||||
|
partition_id deviceID = -1;
|
||||||
KFileDiskDevice *device = NULL;
|
KFileDiskDevice *device = NULL;
|
||||||
if (ManagerLocker locker = this) {
|
if (ManagerLocker locker = this) {
|
||||||
// check, if the device does already exist
|
// check, if the device does already exist
|
||||||
@ -374,8 +385,7 @@ KDiskDeviceManager::CreateFileDevice(const char *filePath,
|
|||||||
delete device;
|
delete device;
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
if (deviceID)
|
deviceID = device->ID();
|
||||||
*deviceID = device->ID();
|
|
||||||
device->Register();
|
device->Register();
|
||||||
}
|
}
|
||||||
// scan device
|
// scan device
|
||||||
@ -383,7 +393,7 @@ KDiskDeviceManager::CreateFileDevice(const char *filePath,
|
|||||||
_ScanDevice(device);
|
_ScanDevice(device);
|
||||||
device->Unregister();
|
device->Unregister();
|
||||||
}
|
}
|
||||||
return error;
|
return (error == B_OK ? deviceID : error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteFileDevice
|
// DeleteFileDevice
|
||||||
@ -400,6 +410,22 @@ KDiskDeviceManager::DeleteFileDevice(const char *filePath)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteFileDevice
|
||||||
|
status_t
|
||||||
|
KDiskDeviceManager::DeleteFileDevice(partition_id id)
|
||||||
|
{
|
||||||
|
if (KDiskDevice *device = RegisterDevice(id)) {
|
||||||
|
PartitionRegistrar _(device, true);
|
||||||
|
if (!dynamic_cast<KFileDiskDevice*>(device) || id != device->ID())
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
if (DeviceWriteLocker locker = device) {
|
||||||
|
if (_RemoveDevice(device))
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
// CountDevices
|
// CountDevices
|
||||||
int32
|
int32
|
||||||
KDiskDeviceManager::CountDevices()
|
KDiskDeviceManager::CountDevices()
|
||||||
|
@ -105,7 +105,7 @@ disk_device_data *
|
|||||||
get_disk_device(partition_id partitionID)
|
get_disk_device(partition_id partitionID)
|
||||||
{
|
{
|
||||||
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
||||||
KDiskDevice *device = manager->FindDevice(partitionID);
|
KDiskDevice *device = manager->FindDevice(partitionID, false);
|
||||||
return (device ? device->DeviceData() : NULL);
|
return (device ? device->DeviceData() : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user