* 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
This commit is contained in:
Ingo Weinhold 2004-10-27 21:52:33 +00:00
parent 0707c10377
commit 1b5f626633
2 changed files with 21 additions and 7 deletions

View File

@ -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.

View File

@ -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