From 92b9e33326dd1691fc10386de42aaae1f52fd320 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 15 Jul 2003 01:15:17 +0000 Subject: [PATCH] * Added SetTo(partition_id), InitCheck(). * Added more parameters to _SetTo(). * Fixed problem in Unset() -- the BPartition version wasn't called. * Implemented {Prepare,Cancel}Modifications() and IsModified(). The latter doesn't work yet, since the syscall implementation is still empty yet. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3977 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/storage/DiskDevice.h | 5 ++- src/kits/storage/DiskDevice.cpp | 57 ++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/headers/private/storage/DiskDevice.h b/headers/private/storage/DiskDevice.h index 0b5f3b022d..b1394418bc 100644 --- a/headers/private/storage/DiskDevice.h +++ b/headers/private/storage/DiskDevice.h @@ -22,8 +22,10 @@ public: status_t Eject(bool update = false); + status_t SetTo(partition_id id); status_t Update(bool *updated = NULL); void Unset(); + status_t InitCheck() const; virtual status_t GetPath(BPath *path) const; @@ -38,7 +40,8 @@ private: friend class BDiskDeviceList; friend class BDiskDeviceRoster; - status_t _SetTo(partition_id id, size_t neededSize = 0); + status_t _SetTo(partition_id id, bool deviceOnly, bool shadow, + size_t neededSize); status_t _SetTo(user_disk_device_data *data); virtual bool _AcceptVisitor(BDiskDeviceVisitor *visitor, int32 level); diff --git a/src/kits/storage/DiskDevice.cpp b/src/kits/storage/DiskDevice.cpp index 6f97f692e1..8cd31d7e2e 100644 --- a/src/kits/storage/DiskDevice.cpp +++ b/src/kits/storage/DiskDevice.cpp @@ -117,6 +117,13 @@ BDiskDevice::Eject(bool update) return B_ERROR; } +// SetTo +status_t +BDiskDevice::SetTo(partition_id id) +{ + return _SetTo(id, true, false, 0); +} + // Update /*! \brief Updates the object to reflect the latest changes to the device. @@ -184,10 +191,18 @@ BDiskDevice::Update(bool *updated) void BDiskDevice::Unset() { + BPartition::_Unset(); free(fDeviceData); fDeviceData = NULL; } +// InitCheck +status_t +BDiskDevice::InitCheck() const +{ + return (fDeviceData ? B_OK : B_NO_INIT); +} + // GetPath status_t BDiskDevice::GetPath(BPath *path) const @@ -201,16 +216,27 @@ BDiskDevice::GetPath(BPath *path) const bool BDiskDevice::IsModified() const { - // not implemented - return false; + return (InitCheck() == B_OK && _IsShadow() + && _kern_is_disk_device_modified(ID())); } // PrepareModifications status_t BDiskDevice::PrepareModifications() { - // not implemented - return B_ERROR; + // check initialization + status_t error = InitCheck(); + if (error != B_OK) + return error; + if (_IsShadow()) + return B_ERROR; + // ask kernel to prepare for modifications + error = _kern_prepare_disk_device_modifications(ID()); + if (error != B_OK) + return error; + // update + // TODO: Add an _Update(bool shadow)? + return _SetTo(ID(), true, true, 0); } // CommitModifications @@ -227,13 +253,21 @@ BDiskDevice::CommitModifications(bool synchronously, status_t BDiskDevice::CancelModifications() { - // not implemented - return B_ERROR; + status_t error = InitCheck(); + if (error != B_OK) + return error; + if (!_IsShadow()) + return B_BAD_VALUE; + error = _kern_cancel_disk_device_modifications(ID()); + if (error == B_OK) + error = _SetTo(ID(), true, false, 0); + return error; } // _SetTo status_t -BDiskDevice::_SetTo(partition_id id, size_t neededSize) +BDiskDevice::_SetTo(partition_id id, bool deviceOnly, bool shadow, + size_t neededSize) { Unset(); // get the device data @@ -248,7 +282,7 @@ BDiskDevice::_SetTo(partition_id id, size_t neededSize) } status_t error = B_OK; do { - error = _kern_get_disk_device_data(id, false, + error = _kern_get_disk_device_data(id, deviceOnly, shadow, (user_disk_device_data*)buffer, bufferSize, &neededSize); if (error == B_BUFFER_OVERFLOW) { @@ -282,11 +316,10 @@ BDiskDevice::_SetTo(user_disk_device_data *data) status_t error = BPartition::_SetTo(this, NULL, &fDeviceData->device_partition_data); if (error != B_OK) { - // Don't call Unset() here. If _SetTo() fails, the caller retains - // ownership of the supplied data. - // TODO: Maybe introduce a _Unset() to avoid potential future - // problems. + // If _SetTo() fails, the caller retains ownership of the supplied + // data. So, unset fDeviceData before calling Unset(). fDeviceData = NULL; + Unset(); } return error; }