From 1b5f6266337ee805a085153179201e3a88d03907 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 27 Oct 2004 21:52:33 +0000 Subject: [PATCH] * Changes to use KPath where possible now. * Made GetMediaStatus() a bit more robust. If the ioctl fails (e.g. if it is not implemented as in Thomas' drivers), it gets the device geometry and does not fail, if the device is not removable. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9546 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/disk_device_manager/KDiskDevice.h | 2 +- .../core/disk_device_manager/KDiskDevice.cpp | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/headers/private/kernel/disk_device_manager/KDiskDevice.h b/headers/private/kernel/disk_device_manager/KDiskDevice.h index b16c99041b..b5ed7decf6 100644 --- a/headers/private/kernel/disk_device_manager/KDiskDevice.h +++ b/headers/private/kernel/disk_device_manager/KDiskDevice.h @@ -54,7 +54,7 @@ public: // TODO: Remove this method or make it private. Once initialized the // path must not be changed. const char *Path() const; - virtual status_t GetPath(char *path) const; + virtual status_t GetPath(KPath *path) const; // File descriptor: Set only from a kernel thread, valid only for // kernel threads. diff --git a/src/kernel/core/disk_device_manager/KDiskDevice.cpp b/src/kernel/core/disk_device_manager/KDiskDevice.cpp index 977ece65cd..154188f41d 100644 --- a/src/kernel/core/disk_device_manager/KDiskDevice.cpp +++ b/src/kernel/core/disk_device_manager/KDiskDevice.cpp @@ -12,6 +12,7 @@ #include "KDiskDevice.h" #include "KDiskDeviceUtils.h" #include "KShadowPartition.h" +#include "KPath.h" #include "UserDataWriter.h" // debugging @@ -256,14 +257,13 @@ KDiskDevice::Path() const // GetPath status_t -KDiskDevice::GetPath(char *path) const +KDiskDevice::GetPath(KPath *path) const { - if (!path) + if (!path || path->InitCheck() != B_OK) return B_BAD_VALUE; if (!fDeviceData.path) return B_NO_INIT; - strcpy(path, fDeviceData.path); - return B_OK; + return path->SetPath(fDeviceData.path); } // SetFD @@ -366,9 +366,23 @@ KDiskDevice::Dump(bool deep, int32 level) status_t KDiskDevice::GetMediaStatus(status_t *mediaStatus) { + status_t error = B_OK; if (ioctl(fFD, B_GET_MEDIA_STATUS, mediaStatus) != 0) - return errno; - return B_OK; + error = errno; + // maybe the device driver doesn't implement this ioctl -- see, if getting + // the device geometry succeeds + if (error != B_OK) { + device_geometry geometry; + if (GetGeometry(&geometry) == B_OK) { + // if the device is not removable, we can ignore the failed ioctl + // and return a media status of B_OK + if (!geometry.removable) { + error = B_OK; + *mediaStatus = B_OK; + } + } + } + return error; } // GetGeometry