diff --git a/headers/private/kernel/disk_device_manager/KDiskDevice.h b/headers/private/kernel/disk_device_manager/KDiskDevice.h index 9c97767143..f5973db469 100644 --- a/headers/private/kernel/disk_device_manager/KDiskDevice.h +++ b/headers/private/kernel/disk_device_manager/KDiskDevice.h @@ -6,14 +6,25 @@ #include #include "KPartition.h" +#include "RWLocker.h" + +// disk device flags +// TODO: move to another header (must be accessible from userland API impl.) +enum { + B_DISK_DEVICE_REMOVABLE = 0x01, + B_DISK_DEVICE_HAS_MEDIA = 0x02, +}; namespace BPrivate { namespace DiskDevice { class KDiskDevice : public KPartition { +public: KDiskDevice(partition_id id = -1); virtual ~KDiskDevice(); + status_t InitCheck() const; + // A read lock owner can be sure that the device (incl. all of its // partitions won't be changed). // A write lock owner is moreover allowed to make changes. @@ -25,12 +36,17 @@ class KDiskDevice : public KPartition { bool WriteLock(); void WriteUnlock(); + virtual void SetID(partition_id id); + void SetDeviceFlags(uint32 flags); // comprises the ones below uint32 DeviceFlags() const; bool IsRemovable() const; bool HasMedia() const; 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 GetPath(char *path) const; // File descriptor: Set only from a kernel thread, valid only for @@ -46,6 +62,13 @@ class KDiskDevice : public KPartition { void SetShadowOwner(team_id team); team_id ShadowOwner() const; + +private: + disk_device_data fDeviceData; + RWLocker fLocker; + int fFD; + status_t fMediaStatus; + team_id fShadowOwner; }; } // namespace DiskDevice diff --git a/src/kernel/core/disk_device_manager/KDiskDevice.cpp b/src/kernel/core/disk_device_manager/KDiskDevice.cpp index 5ad3612f96..4508127419 100644 --- a/src/kernel/core/disk_device_manager/KDiskDevice.cpp +++ b/src/kernel/core/disk_device_manager/KDiskDevice.cpp @@ -1,3 +1,180 @@ // KDiskDevice.cpp #include "KDiskDevice.h" +#include "KDiskDeviceUtils.h" + +// constructor +KDiskDevice::KDiskDevice(partition_id id) + : KPartition(id), + fDeviceData(), + fLocker("diskdevice"), + fFD(-1), + fMediaStatus(B_ERROR), + fShadowOwner(-1) +{ + fDeviceData.id = -1; + fDeviceData.flags = 0; + fDeviceData.path = NULL; + fDeviceData.geometry.bytes_per_sector = 0; + fDeviceData.geometry.sectors_per_track = 0; + fDeviceData.geometry.cylinder_count = 0; + fDeviceData.geometry.head_count = 0; + fDeviceData.geometry.device_type = B_DISK; + fDeviceData.geometry.removable = false; + fDeviceData.geometry.read_only = true; + fDeviceData.geometry.write_once = false; +} + +// destructor +KDiskDevice::~KDiskDevice() +{ + free(fDeviceData.path); +} + +// InitCheck +status_t +KDiskDevice::InitCheck() const +{ + return fLocker.InitCheck(); +} + +// ReadLock +bool +KDiskDevice::ReadLock() +{ + return fLocker.ReadLock(); +} + +// ReadUnlock +void +KDiskDevice::ReadUnlock() +{ + fLocker.ReadUnlock(); +} + +// WriteLock +bool +KDiskDevice::WriteLock() +{ + return fLocker.WriteLock(); +} + +// WriteUnlock +void +KDiskDevice::WriteUnlock() +{ + fLocker.WriteUnlock(); +} + +// SetID +void +KDiskDevice::SetID(partition_id id) +{ + KPartition::SetID(id); + fDeviceData.id = id; +} + +// SetDeviceFlags +void +KDiskDevice::SetDeviceFlags(uint32 flags) +{ + fDeviceData.flags = flags; +} + +// DeviceFlags +uint32 +KDiskDevice::DeviceFlags() const +{ + return fDeviceData.flags; +} + +// IsRemovable +bool +KDiskDevice::IsRemovable() const +{ + return fDeviceData.geometry.removable; +} + +// HasMedia +bool +KDiskDevice::HasMedia() const +{ + return (fMediaStatus == B_OK); +} + +// SetPath +status_t +KDiskDevice::SetPath(const char *path) +{ + return set_string(fDeviceData.path, path); +} + +// Path +const char * +KDiskDevice::Path() const +{ + return fDeviceData.path; +} + +// GetPath +status_t +KDiskDevice::GetPath(char *path) const +{ + if (!path) + return B_BAD_VALUE; + if (!fDeviceData.path) + return B_NO_INIT; + strcpy(path, fDeviceData.path); + return B_OK; +} + +// SetFD +void +KDiskDevice::SetFD(int fd) +{ + fFD = fd; +} + +// FD +int +KDiskDevice::FD() const +{ + return fFD; +} + +// DeviceData +disk_device_data * +KDiskDevice::DeviceData() +{ + return &fDeviceData; +} + +// DeviceData +const disk_device_data * +KDiskDevice::DeviceData() const +{ + return &fDeviceData; +} + +// CreateShadowPartition +KPartition * +KDiskDevice::CreateShadowPartition() +{ + // not implemented + return NULL; +} + +// SetShadowOwner +void +KDiskDevice::SetShadowOwner(team_id team) +{ + fShadowOwner = team; +} + +// ShadowOwner +team_id +KDiskDevice::ShadowOwner() const +{ + return fShadowOwner; +} +