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:
Ingo Weinhold 2003-07-15 21:39:34 +00:00
parent c261267f46
commit a97769a5d3
2 changed files with 97 additions and 0 deletions

View File

@ -50,6 +50,15 @@ public:
KPartition *RegisterPartition(partition_id id, bool noShadow = false);
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);
status_t DeleteFileDevice(const char *filePath);
status_t DeleteFileDevice(partition_id id);

View File

@ -359,6 +359,94 @@ KDiskDeviceManager::RegisterFileDevice(const char *filePath)
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
partition_id
KDiskDeviceManager::CreateFileDevice(const char *filePath)