Added {Read,Write}Lock{Device,Partition}().
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3986 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
c261267f46
commit
a97769a5d3
@ -50,6 +50,15 @@ public:
|
|||||||
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);
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
partition_id CreateFileDevice(const char *filePath);
|
partition_id CreateFileDevice(const char *filePath);
|
||||||
status_t DeleteFileDevice(const char *filePath);
|
status_t DeleteFileDevice(const char *filePath);
|
||||||
status_t DeleteFileDevice(partition_id id);
|
status_t DeleteFileDevice(partition_id id);
|
||||||
|
@ -359,6 +359,94 @@ KDiskDeviceManager::RegisterFileDevice(const char *filePath)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadLockDevice
|
||||||
|
KDiskDevice *
|
||||||
|
KDiskDeviceManager::ReadLockDevice(partition_id id, bool deviceOnly)
|
||||||
|
{
|
||||||
|
// register device
|
||||||
|
KDiskDevice *device = RegisterDevice(id, deviceOnly);
|
||||||
|
if (!device)
|
||||||
|
return NULL;
|
||||||
|
// lock device
|
||||||
|
if (device->ReadLock())
|
||||||
|
return device;
|
||||||
|
device->Unregister();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteLockDevice
|
||||||
|
KDiskDevice *
|
||||||
|
KDiskDeviceManager::WriteLockDevice(partition_id id, bool deviceOnly)
|
||||||
|
{
|
||||||
|
// register device
|
||||||
|
KDiskDevice *device = RegisterDevice(id, deviceOnly);
|
||||||
|
if (!device)
|
||||||
|
return NULL;
|
||||||
|
// lock device
|
||||||
|
if (device->WriteLock())
|
||||||
|
return device;
|
||||||
|
device->Unregister();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadLockPartition
|
||||||
|
KPartition *
|
||||||
|
KDiskDeviceManager::ReadLockPartition(partition_id id)
|
||||||
|
{
|
||||||
|
// register partition
|
||||||
|
KPartition *partition = RegisterPartition(id);
|
||||||
|
if (!partition)
|
||||||
|
return NULL;
|
||||||
|
// get and register the device
|
||||||
|
KDiskDevice *device = NULL;
|
||||||
|
if (ManagerLocker locker = this) {
|
||||||
|
device = partition->Device();
|
||||||
|
if (device)
|
||||||
|
device->Register();
|
||||||
|
}
|
||||||
|
// lock the device
|
||||||
|
if (device->ReadLock()) {
|
||||||
|
// final check, if the partition still belongs to the device
|
||||||
|
if (partition->Device() == device)
|
||||||
|
return partition;
|
||||||
|
device->ReadUnlock();
|
||||||
|
}
|
||||||
|
// cleanup on failure
|
||||||
|
if (device)
|
||||||
|
device->Unregister();
|
||||||
|
partition->Unregister();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteLockPartition
|
||||||
|
KPartition *
|
||||||
|
KDiskDeviceManager::WriteLockPartition(partition_id id)
|
||||||
|
{
|
||||||
|
// register partition
|
||||||
|
KPartition *partition = RegisterPartition(id);
|
||||||
|
if (!partition)
|
||||||
|
return NULL;
|
||||||
|
// get and register the device
|
||||||
|
KDiskDevice *device = NULL;
|
||||||
|
if (ManagerLocker locker = this) {
|
||||||
|
device = partition->Device();
|
||||||
|
if (device)
|
||||||
|
device->Register();
|
||||||
|
}
|
||||||
|
// lock the device
|
||||||
|
if (device->WriteLock()) {
|
||||||
|
// final check, if the partition still belongs to the device
|
||||||
|
if (partition->Device() == device)
|
||||||
|
return partition;
|
||||||
|
device->WriteUnlock();
|
||||||
|
}
|
||||||
|
// cleanup on failure
|
||||||
|
if (device)
|
||||||
|
device->Unregister();
|
||||||
|
partition->Unregister();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// CreateFileDevice
|
// CreateFileDevice
|
||||||
partition_id
|
partition_id
|
||||||
KDiskDeviceManager::CreateFileDevice(const char *filePath)
|
KDiskDeviceManager::CreateFileDevice(const char *filePath)
|
||||||
|
Loading…
Reference in New Issue
Block a user