From 1e2e4b3c718aae81f52826645792320776eb5573 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 28 Oct 2004 22:18:20 +0000 Subject: [PATCH] Re-added support for file devices. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9626 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../disk_device_manager/KDiskDeviceManager.h | 3 +- .../KDiskDeviceManager.cpp | 34 +++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h b/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h index 8fdf563a97..f92524702b 100644 --- a/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h +++ b/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h @@ -60,7 +60,8 @@ public: // 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, + bool *newlyCreated = NULL); status_t DeleteFileDevice(const char *filePath); status_t DeleteFileDevice(partition_id id); diff --git a/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp b/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp index a288e9f77d..e15bd4ed1f 100644 --- a/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp +++ b/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp @@ -532,23 +532,32 @@ KDiskDeviceManager::WriteLockPartition(partition_id id) // CreateFileDevice partition_id -KDiskDeviceManager::CreateFileDevice(const char *filePath) +KDiskDeviceManager::CreateFileDevice(const char *filePath, bool *newlyCreated) { -// ToDo! - return B_ERROR; -#if 0 if (!filePath) 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; if (ManagerLocker locker = this) { // check, if the device does already exist - if (FindFileDevice(filePath)) - return B_FILE_EXISTS; + if ((device = FindFileDevice(filePath))) { + if (newlyCreated) + *newlyCreated = false; + return device->ID(); + } + // allocate a KFileDiskDevice device = new(nothrow) KFileDiskDevice; if (!device) return B_NO_MEMORY; + // initialize and add the device error = device->SetTo(filePath); // Note: Here we are allowed to lock a device although already having @@ -558,23 +567,27 @@ KDiskDeviceManager::CreateFileDevice(const char *filePath) error = B_ERROR; if (error == B_OK && !_AddDevice(device)) error = B_NO_MEMORY; + // scan device if (error == B_OK) { _ScanPartition(device); + + if (newlyCreated) + *newlyCreated = true; return device->ID(); } + // cleanup on failure delete device; - } + } else + error = B_ERROR; return error; -#endif } // DeleteFileDevice status_t KDiskDeviceManager::DeleteFileDevice(const char *filePath) { -#if 0 if (KFileDiskDevice *device = RegisterFileDevice(filePath)) { PartitionRegistrar _(device, true); if (DeviceWriteLocker locker = device) { @@ -582,7 +595,6 @@ KDiskDeviceManager::DeleteFileDevice(const char *filePath) return B_OK; } } -#endif return B_ERROR; }