* 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
This commit is contained in:
Ingo Weinhold 2003-07-15 01:15:17 +00:00
parent dd43c7769f
commit 92b9e33326
2 changed files with 49 additions and 13 deletions

View File

@ -22,8 +22,10 @@ public:
status_t Eject(bool update = false); status_t Eject(bool update = false);
status_t SetTo(partition_id id);
status_t Update(bool *updated = NULL); status_t Update(bool *updated = NULL);
void Unset(); void Unset();
status_t InitCheck() const;
virtual status_t GetPath(BPath *path) const; virtual status_t GetPath(BPath *path) const;
@ -38,7 +40,8 @@ private:
friend class BDiskDeviceList; friend class BDiskDeviceList;
friend class BDiskDeviceRoster; 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); status_t _SetTo(user_disk_device_data *data);
virtual bool _AcceptVisitor(BDiskDeviceVisitor *visitor, int32 level); virtual bool _AcceptVisitor(BDiskDeviceVisitor *visitor, int32 level);

View File

@ -117,6 +117,13 @@ BDiskDevice::Eject(bool update)
return B_ERROR; return B_ERROR;
} }
// SetTo
status_t
BDiskDevice::SetTo(partition_id id)
{
return _SetTo(id, true, false, 0);
}
// Update // Update
/*! \brief Updates the object to reflect the latest changes to the device. /*! \brief Updates the object to reflect the latest changes to the device.
@ -184,10 +191,18 @@ BDiskDevice::Update(bool *updated)
void void
BDiskDevice::Unset() BDiskDevice::Unset()
{ {
BPartition::_Unset();
free(fDeviceData); free(fDeviceData);
fDeviceData = NULL; fDeviceData = NULL;
} }
// InitCheck
status_t
BDiskDevice::InitCheck() const
{
return (fDeviceData ? B_OK : B_NO_INIT);
}
// GetPath // GetPath
status_t status_t
BDiskDevice::GetPath(BPath *path) const BDiskDevice::GetPath(BPath *path) const
@ -201,16 +216,27 @@ BDiskDevice::GetPath(BPath *path) const
bool bool
BDiskDevice::IsModified() const BDiskDevice::IsModified() const
{ {
// not implemented return (InitCheck() == B_OK && _IsShadow()
return false; && _kern_is_disk_device_modified(ID()));
} }
// PrepareModifications // PrepareModifications
status_t status_t
BDiskDevice::PrepareModifications() BDiskDevice::PrepareModifications()
{ {
// not implemented // check initialization
status_t error = InitCheck();
if (error != B_OK)
return error;
if (_IsShadow())
return B_ERROR; 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 // CommitModifications
@ -227,13 +253,21 @@ BDiskDevice::CommitModifications(bool synchronously,
status_t status_t
BDiskDevice::CancelModifications() BDiskDevice::CancelModifications()
{ {
// not implemented status_t error = InitCheck();
return B_ERROR; 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 // _SetTo
status_t status_t
BDiskDevice::_SetTo(partition_id id, size_t neededSize) BDiskDevice::_SetTo(partition_id id, bool deviceOnly, bool shadow,
size_t neededSize)
{ {
Unset(); Unset();
// get the device data // get the device data
@ -248,7 +282,7 @@ BDiskDevice::_SetTo(partition_id id, size_t neededSize)
} }
status_t error = B_OK; status_t error = B_OK;
do { do {
error = _kern_get_disk_device_data(id, false, error = _kern_get_disk_device_data(id, deviceOnly, shadow,
(user_disk_device_data*)buffer, (user_disk_device_data*)buffer,
bufferSize, &neededSize); bufferSize, &neededSize);
if (error == B_BUFFER_OVERFLOW) { if (error == B_BUFFER_OVERFLOW) {
@ -282,11 +316,10 @@ BDiskDevice::_SetTo(user_disk_device_data *data)
status_t error = BPartition::_SetTo(this, NULL, status_t error = BPartition::_SetTo(this, NULL,
&fDeviceData->device_partition_data); &fDeviceData->device_partition_data);
if (error != B_OK) { if (error != B_OK) {
// Don't call Unset() here. If _SetTo() fails, the caller retains // If _SetTo() fails, the caller retains ownership of the supplied
// ownership of the supplied data. // data. So, unset fDeviceData before calling Unset().
// TODO: Maybe introduce a _Unset() to avoid potential future
// problems.
fDeviceData = NULL; fDeviceData = NULL;
Unset();
} }
return error; return error;
} }