kernel/disk_device_manager: Cleanup code style, fix some minor TODOs.
This commit is contained in:
@@ -27,8 +27,6 @@ public:
|
||||
|
||||
status_t SetTo(const char *path);
|
||||
void Unset();
|
||||
virtual status_t InitCheck() const;
|
||||
// TODO: probably superfluous
|
||||
|
||||
// A read lock owner can be sure that the device (incl. all of its
|
||||
// partitions won't be changed).
|
||||
@@ -60,16 +58,11 @@ public:
|
||||
|
||||
void UpdateGeometry();
|
||||
|
||||
status_t SetPath(const char *path);
|
||||
// TODO: Remove this method or make it private. Once initialized the
|
||||
// path must not be changed.
|
||||
const char *Path() const;
|
||||
virtual status_t GetFileName(char* buffer, size_t size) const;
|
||||
virtual status_t GetPath(KPath *path) const;
|
||||
|
||||
// File descriptor: Set only from a kernel thread, valid only for
|
||||
// kernel threads.
|
||||
void SetFD(int fd);
|
||||
// File descriptor: valid only for kernel threads.
|
||||
int FD() const;
|
||||
|
||||
// access to C style device data
|
||||
@@ -101,6 +94,8 @@ private:
|
||||
} // namespace DiskDevice
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
using BPrivate::DiskDevice::KDiskDevice;
|
||||
|
||||
|
||||
#endif // _K_DISK_DEVICE_H
|
||||
|
||||
@@ -1,26 +1,30 @@
|
||||
// KFileDiskDevice.h
|
||||
|
||||
/*
|
||||
* Copyright 2003-2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _K_FILE_DISK_DEVICE_H
|
||||
#define _K_FILE_DISK_DEVICE_H
|
||||
|
||||
|
||||
#include <OS.h>
|
||||
|
||||
#include "KDiskDevice.h"
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
namespace DiskDevice {
|
||||
|
||||
|
||||
class KPath;
|
||||
|
||||
class KFileDiskDevice : public KDiskDevice {
|
||||
|
||||
class KFileDiskDevice final : public KDiskDevice {
|
||||
public:
|
||||
KFileDiskDevice(partition_id id = -1);
|
||||
virtual ~KFileDiskDevice();
|
||||
|
||||
status_t SetTo(const char *filePath, const char *devicePath = NULL);
|
||||
void Unset();
|
||||
virtual status_t InitCheck() const;
|
||||
// TODO: probably superfluous
|
||||
|
||||
const char *FilePath() const;
|
||||
|
||||
@@ -40,9 +44,12 @@ private:
|
||||
char *fFilePath;
|
||||
};
|
||||
|
||||
|
||||
} // namespace DiskDevice
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
using BPrivate::DiskDevice::KFileDiskDevice;
|
||||
|
||||
|
||||
#endif // _K_FILE_DISK_DEVICE_H
|
||||
|
||||
@@ -8,14 +8,18 @@
|
||||
#ifndef _K_DISK_DEVICE_PARTITION_H
|
||||
#define _K_DISK_DEVICE_PARTITION_H
|
||||
|
||||
|
||||
#include <disk_device_manager.h>
|
||||
#include <Vector.h>
|
||||
|
||||
|
||||
struct user_partition_data;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
namespace DiskDevice {
|
||||
|
||||
|
||||
class UserDataWriter;
|
||||
|
||||
class KDiskDevice;
|
||||
@@ -25,6 +29,7 @@ class KPartitionVisitor;
|
||||
class KPath;
|
||||
class KPhysicalPartition;
|
||||
|
||||
|
||||
//! \brief Class representing a single partition.
|
||||
class KPartition {
|
||||
public:
|
||||
@@ -235,9 +240,12 @@ protected:
|
||||
static int32 sNextID;
|
||||
};
|
||||
|
||||
|
||||
} // namespace DiskDevice
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
using BPrivate::DiskDevice::KPartition;
|
||||
|
||||
|
||||
#endif // _K_DISK_DEVICE_PARTITION_H
|
||||
|
||||
@@ -51,17 +51,14 @@ KDiskDevice::~KDiskDevice()
|
||||
status_t
|
||||
KDiskDevice::SetTo(const char* path)
|
||||
{
|
||||
// check initialization and parameter
|
||||
status_t error = InitCheck();
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
if (!path)
|
||||
return B_BAD_VALUE;
|
||||
Unset();
|
||||
// set the path
|
||||
error = set_string(fDeviceData.path, path);
|
||||
|
||||
status_t error = set_string(fDeviceData.path, path);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
// open the device
|
||||
fFD = open(path, O_RDONLY);
|
||||
if (fFD < 0)
|
||||
@@ -72,6 +69,7 @@ KDiskDevice::SetTo(const char* path)
|
||||
return error;
|
||||
if (fMediaStatus == B_DEV_MEDIA_CHANGED)
|
||||
fMediaStatus = B_OK;
|
||||
|
||||
// get device geometry
|
||||
if (fMediaStatus == B_OK) {
|
||||
error = GetGeometry(&fDeviceData.geometry);
|
||||
@@ -82,9 +80,7 @@ KDiskDevice::SetTo(const char* path)
|
||||
_ResetGeometry();
|
||||
}
|
||||
|
||||
// set device flags
|
||||
_UpdateDeviceFlags();
|
||||
// update partition data
|
||||
_InitPartitionData();
|
||||
return B_OK;
|
||||
}
|
||||
@@ -108,13 +104,6 @@ KDiskDevice::Unset()
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
KDiskDevice::InitCheck() const
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
KDiskDevice::ReadLock()
|
||||
{
|
||||
@@ -257,13 +246,6 @@ KDiskDevice::UpdateGeometry()
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
KDiskDevice::SetPath(const char* path)
|
||||
{
|
||||
return set_string(fDeviceData.path, path);
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
KDiskDevice::Path() const
|
||||
{
|
||||
@@ -291,13 +273,6 @@ KDiskDevice::GetPath(KPath* path) const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
KDiskDevice::SetFD(int fd)
|
||||
{
|
||||
fFD = fd;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
KDiskDevice::FD() const
|
||||
{
|
||||
|
||||
@@ -40,11 +40,11 @@ KFileDiskDevice::~KFileDiskDevice()
|
||||
status_t
|
||||
KFileDiskDevice::SetTo(const char* filePath, const char* devicePath)
|
||||
{
|
||||
// check params
|
||||
if (!filePath || strlen(filePath) > B_PATH_NAME_LENGTH
|
||||
|| (devicePath && strlen(devicePath) > B_PATH_NAME_LENGTH)) {
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
// normalize the file path
|
||||
// (should actually not be necessary, since this method is only invoked
|
||||
// by the DDM, which has already normalized the path)
|
||||
@@ -52,35 +52,32 @@ KFileDiskDevice::SetTo(const char* filePath, const char* devicePath)
|
||||
status_t error = tmpFilePath.SetTo(filePath, KPath::NORMALIZE);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
// check the file
|
||||
struct stat st;
|
||||
if (stat(filePath, &st) != 0)
|
||||
return errno;
|
||||
if (!S_ISREG(st.st_mode))
|
||||
return B_BAD_VALUE;
|
||||
|
||||
// create the device, if requested
|
||||
KPath tmpDevicePath;
|
||||
if (devicePath == NULL) {
|
||||
// no device path: we shall create a new device entry
|
||||
if (tmpDevicePath.InitCheck() != B_OK)
|
||||
return tmpDevicePath.InitCheck();
|
||||
// TODO: Cleanup. The directory creation is done automatically by the devfs.
|
||||
// // make the file devices dir
|
||||
// if (mkdir(kFileDevicesDir, 0777) != 0) {
|
||||
// if (errno != B_FILE_EXISTS)
|
||||
// return errno;
|
||||
// }
|
||||
|
||||
// make the directory
|
||||
status_t error = _GetDirectoryPath(ID(), &tmpDevicePath);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
// if (mkdir(tmpDevicePath.Path(), 0777) != 0)
|
||||
// return errno;
|
||||
|
||||
// get the device path name
|
||||
error = tmpDevicePath.Append("raw");
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
devicePath = tmpDevicePath.Path();
|
||||
|
||||
// register the file as virtual disk device
|
||||
error = _RegisterDevice(filePath, devicePath);
|
||||
if (error != B_OK)
|
||||
@@ -94,8 +91,7 @@ KFileDiskDevice::SetTo(const char* filePath, const char* devicePath)
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
// reset the B_DISK_DEVICE_IS_FILE flag -- KDiskDevice::SetTo() has cleared
|
||||
// it
|
||||
// reset the B_DISK_DEVICE_IS_FILE flag -- KDiskDevice::SetTo() has cleared it
|
||||
SetDeviceFlags(DeviceFlags() | B_DISK_DEVICE_IS_FILE);
|
||||
|
||||
return B_OK;
|
||||
@@ -113,19 +109,12 @@ KFileDiskDevice::Unset()
|
||||
// if (_GetDirectoryPath(ID(), &dirPath) == B_OK)
|
||||
// rmdir(dirPath.Path());
|
||||
}
|
||||
// free file path
|
||||
|
||||
free(fFilePath);
|
||||
fFilePath = NULL;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
KFileDiskDevice::InitCheck() const
|
||||
{
|
||||
return KDiskDevice::InitCheck();
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
KFileDiskDevice::FilePath() const
|
||||
{
|
||||
@@ -211,4 +200,3 @@ KFileDiskDevice::_GetDirectoryPath(partition_id id, KPath* path)
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user