Re-added support for file devices.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9626 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2004-10-28 22:18:20 +00:00
parent cba3b01fdf
commit 1e2e4b3c71
2 changed files with 25 additions and 12 deletions

View File

@ -60,7 +60,8 @@ public:
// Both the device and the partition is also registered and must be // Both the device and the partition is also registered and must be
// unregistered by the caller. // unregistered by the caller.
partition_id CreateFileDevice(const char *filePath); partition_id CreateFileDevice(const char *filePath,
bool *newlyCreated = NULL);
status_t DeleteFileDevice(const char *filePath); status_t DeleteFileDevice(const char *filePath);
status_t DeleteFileDevice(partition_id id); status_t DeleteFileDevice(partition_id id);

View File

@ -532,23 +532,32 @@ KDiskDeviceManager::WriteLockPartition(partition_id id)
// CreateFileDevice // CreateFileDevice
partition_id partition_id
KDiskDeviceManager::CreateFileDevice(const char *filePath) KDiskDeviceManager::CreateFileDevice(const char *filePath, bool *newlyCreated)
{ {
// ToDo!
return B_ERROR;
#if 0
if (!filePath) if (!filePath)
return B_BAD_VALUE; return B_BAD_VALUE;
status_t error = B_ERROR;
// normalize the file path
KPath normalizedFilePath;
status_t error = normalizedFilePath.SetTo(filePath, true);
if (error != B_OK)
return error;
filePath = normalizedFilePath.Path();
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
if (FindFileDevice(filePath)) if ((device = FindFileDevice(filePath))) {
return B_FILE_EXISTS; if (newlyCreated)
*newlyCreated = false;
return device->ID();
}
// allocate a KFileDiskDevice // allocate a KFileDiskDevice
device = new(nothrow) KFileDiskDevice; device = new(nothrow) KFileDiskDevice;
if (!device) if (!device)
return B_NO_MEMORY; return B_NO_MEMORY;
// initialize and add the device // initialize and add the device
error = device->SetTo(filePath); error = device->SetTo(filePath);
// Note: Here we are allowed to lock a device although already having // Note: Here we are allowed to lock a device although already having
@ -558,23 +567,27 @@ KDiskDeviceManager::CreateFileDevice(const char *filePath)
error = B_ERROR; error = B_ERROR;
if (error == B_OK && !_AddDevice(device)) if (error == B_OK && !_AddDevice(device))
error = B_NO_MEMORY; error = B_NO_MEMORY;
// scan device // scan device
if (error == B_OK) { if (error == B_OK) {
_ScanPartition(device); _ScanPartition(device);
if (newlyCreated)
*newlyCreated = true;
return device->ID(); return device->ID();
} }
// cleanup on failure // cleanup on failure
delete device; delete device;
} } else
error = B_ERROR;
return error; return error;
#endif
} }
// DeleteFileDevice // DeleteFileDevice
status_t status_t
KDiskDeviceManager::DeleteFileDevice(const char *filePath) KDiskDeviceManager::DeleteFileDevice(const char *filePath)
{ {
#if 0
if (KFileDiskDevice *device = RegisterFileDevice(filePath)) { if (KFileDiskDevice *device = RegisterFileDevice(filePath)) {
PartitionRegistrar _(device, true); PartitionRegistrar _(device, true);
if (DeviceWriteLocker locker = device) { if (DeviceWriteLocker locker = device) {
@ -582,7 +595,6 @@ KDiskDeviceManager::DeleteFileDevice(const char *filePath)
return B_OK; return B_OK;
} }
} }
#endif
return B_ERROR; return B_ERROR;
} }