Style cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22600 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2007-10-17 20:51:10 +00:00
parent b0e2e12f4f
commit 46b93b2cfd
4 changed files with 119 additions and 66 deletions
+15 -11
View File
@@ -1,13 +1,14 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2003-2007, Ingo Weinhold, [email protected].
// by the OpenBeOS license. * Copyright 2003, Tyler Akidau, [email protected].
//--------------------------------------------------------------------- * Distributed under the terms of the MIT License.
*/
#ifndef _DISK_DEVICE_H #ifndef _DISK_DEVICE_H
#define _DISK_DEVICE_H #define _DISK_DEVICE_H
#include <Partition.h> #include <Partition.h>
struct user_disk_device_data; struct user_disk_device_data;
class BDiskDevice : public BPartition { class BDiskDevice : public BPartition {
@@ -43,18 +44,21 @@ private:
BDiskDevice(const BDiskDevice&); BDiskDevice(const BDiskDevice&);
BDiskDevice& operator=(const BDiskDevice&); BDiskDevice& operator=(const BDiskDevice&);
static status_t _GetData(partition_id id, bool deviceOnly, bool shadow, static status_t _GetData(partition_id id, bool deviceOnly,
size_t neededSize, user_disk_device_data **data); bool shadow, size_t neededSize,
user_disk_device_data** data);
status_t _SetTo(partition_id id, bool deviceOnly, bool shadow, status_t _SetTo(partition_id id, bool deviceOnly,
size_t neededSize); bool shadow, size_t neededSize);
status_t _SetTo(user_disk_device_data* data); status_t _SetTo(user_disk_device_data* data);
status_t _Update(bool shadow, bool* updated); status_t _Update(bool shadow, bool* updated);
status_t _Update(user_disk_device_data *data, bool *updated); status_t _Update(user_disk_device_data* data,
bool* updated);
static void _ClearUserData(user_partition_data* data); static void _ClearUserData(user_partition_data* data);
virtual bool _AcceptVisitor(BDiskDeviceVisitor *visitor, int32 level); virtual bool _AcceptVisitor(BDiskDeviceVisitor* visitor,
int32 level);
user_disk_device_data* fDeviceData; user_disk_device_data* fDeviceData;
}; };
+2 -1
View File
@@ -1,5 +1,6 @@
/* /*
* Copyright 2003-2007, Ingo Weinhold, [email protected].de. * Copyright 2003-2007, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2003, Tyler Akidau, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _PARTITION_H #ifndef _PARTITION_H
+54 -6
View File
@@ -1,7 +1,7 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2003-2007, Ingo Weinhold, [email protected].
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//--------------------------------------------------------------------- */
#include <DiskDevice.h> #include <DiskDevice.h>
@@ -28,6 +28,7 @@
\brief A BDiskDevice object represents a storage device. \brief A BDiskDevice object represents a storage device.
*/ */
// constructor // constructor
/*! \brief Creates an uninitialized BDiskDevice object. /*! \brief Creates an uninitialized BDiskDevice object.
*/ */
@@ -36,6 +37,7 @@ BDiskDevice::BDiskDevice()
{ {
} }
// destructor // destructor
/*! \brief Frees all resources associated with this object. /*! \brief Frees all resources associated with this object.
*/ */
@@ -44,6 +46,7 @@ BDiskDevice::~BDiskDevice()
CancelModifications(); CancelModifications();
} }
// HasMedia // HasMedia
/*! \brief Returns whether the device contains a media. /*! \brief Returns whether the device contains a media.
\return \c true, if the device contains a media, \c false otherwise. \return \c true, if the device contains a media, \c false otherwise.
@@ -55,6 +58,7 @@ BDiskDevice::HasMedia() const
&& fDeviceData->device_flags & B_DISK_DEVICE_HAS_MEDIA); && fDeviceData->device_flags & B_DISK_DEVICE_HAS_MEDIA);
} }
// IsRemovableMedia // IsRemovableMedia
/*! \brief Returns whether the device media are removable. /*! \brief Returns whether the device media are removable.
\return \c true, if the device media are removable, \c false otherwise. \return \c true, if the device media are removable, \c false otherwise.
@@ -66,6 +70,7 @@ BDiskDevice::IsRemovableMedia() const
&& fDeviceData->device_flags & B_DISK_DEVICE_REMOVABLE); && fDeviceData->device_flags & B_DISK_DEVICE_REMOVABLE);
} }
// IsReadOnlyMedia // IsReadOnlyMedia
bool bool
BDiskDevice::IsReadOnlyMedia() const BDiskDevice::IsReadOnlyMedia() const
@@ -74,6 +79,7 @@ BDiskDevice::IsReadOnlyMedia() const
&& fDeviceData->device_flags & B_DISK_DEVICE_READ_ONLY); && fDeviceData->device_flags & B_DISK_DEVICE_READ_ONLY);
} }
// IsWriteOnceMedia // IsWriteOnceMedia
bool bool
BDiskDevice::IsWriteOnceMedia() const BDiskDevice::IsWriteOnceMedia() const
@@ -82,6 +88,7 @@ BDiskDevice::IsWriteOnceMedia() const
&& fDeviceData->device_flags & B_DISK_DEVICE_WRITE_ONCE); && fDeviceData->device_flags & B_DISK_DEVICE_WRITE_ONCE);
} }
// Eject // Eject
/*! \brief Eject the device's media. /*! \brief Eject the device's media.
@@ -120,6 +127,7 @@ BDiskDevice::Eject(bool update)
return B_ERROR; return B_ERROR;
} }
// SetTo // SetTo
status_t status_t
BDiskDevice::SetTo(partition_id id) BDiskDevice::SetTo(partition_id id)
@@ -127,6 +135,7 @@ BDiskDevice::SetTo(partition_id id)
return _SetTo(id, true, false, 0); 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.
@@ -146,6 +155,7 @@ BDiskDevice::Update(bool *updated)
return _Update(_IsShadow(), updated); return _Update(_IsShadow(), updated);
} }
// Unset // Unset
void void
BDiskDevice::Unset() BDiskDevice::Unset()
@@ -155,6 +165,7 @@ BDiskDevice::Unset()
fDeviceData = NULL; fDeviceData = NULL;
} }
// InitCheck // InitCheck
status_t status_t
BDiskDevice::InitCheck() const BDiskDevice::InitCheck() const
@@ -162,6 +173,7 @@ BDiskDevice::InitCheck() const
return (fDeviceData ? B_OK : B_NO_INIT); return (fDeviceData ? B_OK : B_NO_INIT);
} }
// GetPath // GetPath
status_t status_t
BDiskDevice::GetPath(BPath* path) const BDiskDevice::GetPath(BPath* path) const
@@ -171,6 +183,7 @@ BDiskDevice::GetPath(BPath *path) const
return path->SetTo(fDeviceData->path); return path->SetTo(fDeviceData->path);
} }
// IsModified // IsModified
bool bool
BDiskDevice::IsModified() const BDiskDevice::IsModified() const
@@ -179,6 +192,7 @@ BDiskDevice::IsModified() const
&& _kern_is_disk_device_modified(ID())); && _kern_is_disk_device_modified(ID()));
} }
// PrepareModifications // PrepareModifications
/*! \brief Initializes the partition hierarchy for modifications. /*! \brief Initializes the partition hierarchy for modifications.
* *
@@ -197,19 +211,23 @@ BDiskDevice::PrepareModifications()
return error; return error;
if (_IsShadow()) if (_IsShadow())
return B_ERROR; return B_ERROR;
// ask kernel to prepare for modifications // ask kernel to prepare for modifications
error = _kern_prepare_disk_device_modifications(ID()); error = _kern_prepare_disk_device_modifications(ID());
if (error != B_OK) if (error != B_OK)
return error; return error;
// update // update
error = _Update(true, NULL); error = _Update(true, NULL);
if (error != B_OK) { if (error != B_OK) {
// bad -- cancelling the modifications is all we can do // bad -- cancelling the modifications is all we can do
_kern_cancel_disk_device_modifications(ID()); _kern_cancel_disk_device_modifications(ID());
} }
return error; return error;
} }
// CommitModifications // CommitModifications
/*! \brief Commits modifications to device. /*! \brief Commits modifications to device.
* *
@@ -219,14 +237,14 @@ BDiskDevice::PrepareModifications()
*/ */
status_t status_t
BDiskDevice::CommitModifications(bool synchronously, BDiskDevice::CommitModifications(bool synchronously,
BMessenger progressMessenger, BMessenger progressMessenger, bool receiveCompleteProgressUpdates)
bool receiveCompleteProgressUpdates)
{ {
status_t error = InitCheck(); status_t error = InitCheck();
if (error != B_OK) if (error != B_OK)
return error; return error;
if (!_IsShadow()) if (!_IsShadow())
return B_BAD_VALUE; return B_BAD_VALUE;
// TODO: Get port and token from the progressMessenger // TODO: Get port and token from the progressMessenger
// TODO: Respect "synchronously"! // TODO: Respect "synchronously"!
port_id port = -1; port_id port = -1;
@@ -235,9 +253,11 @@ BDiskDevice::CommitModifications(bool synchronously,
receiveCompleteProgressUpdates); receiveCompleteProgressUpdates);
if (error == B_OK) if (error == B_OK)
error = _SetTo(ID(), true, false, 0); error = _SetTo(ID(), true, false, 0);
return error; return error;
} }
// CancelModifications // CancelModifications
/*! \brief Cancels all modifications performed on the device. /*! \brief Cancels all modifications performed on the device.
* *
@@ -251,12 +271,15 @@ BDiskDevice::CancelModifications()
return error; return error;
if (!_IsShadow()) if (!_IsShadow())
return B_BAD_VALUE; return B_BAD_VALUE;
error = _kern_cancel_disk_device_modifications(ID()); error = _kern_cancel_disk_device_modifications(ID());
if (error == B_OK) if (error == B_OK)
error = _SetTo(ID(), true, false, 0); error = _SetTo(ID(), true, false, 0);
return error; return error;
} }
// copy constructor // copy constructor
/*! \brief Privatized copy constructor to avoid usage. /*! \brief Privatized copy constructor to avoid usage.
*/ */
@@ -264,6 +287,7 @@ BDiskDevice::BDiskDevice(const BDiskDevice &)
{ {
} }
// = // =
/*! \brief Privatized assignment operator to avoid usage. /*! \brief Privatized assignment operator to avoid usage.
*/ */
@@ -273,6 +297,7 @@ BDiskDevice::operator=(const BDiskDevice &)
return *this; return *this;
} }
// _GetData // _GetData
status_t status_t
BDiskDevice::_GetData(partition_id id, bool deviceOnly, bool shadow, BDiskDevice::_GetData(partition_id id, bool deviceOnly, bool shadow,
@@ -288,6 +313,7 @@ BDiskDevice::_GetData(partition_id id, bool deviceOnly, bool shadow,
return B_NO_MEMORY; return B_NO_MEMORY;
bufferSize = neededSize; bufferSize = neededSize;
} }
status_t error = B_OK; status_t error = B_OK;
do { do {
error = _kern_get_disk_device_data(id, deviceOnly, shadow, error = _kern_get_disk_device_data(id, deviceOnly, shadow,
@@ -297,47 +323,60 @@ BDiskDevice::_GetData(partition_id id, bool deviceOnly, bool shadow,
// buffer to small re-allocate it // buffer to small re-allocate it
if (buffer) if (buffer)
free(buffer); free(buffer);
buffer = malloc(neededSize); buffer = malloc(neededSize);
if (buffer) if (buffer)
bufferSize = neededSize; bufferSize = neededSize;
else else
error = B_NO_MEMORY; error = B_NO_MEMORY;
} }
} while (error == B_BUFFER_OVERFLOW); } while (error == B_BUFFER_OVERFLOW);
// set result / cleanup on error // set result / cleanup on error
if (error == B_OK) if (error == B_OK)
*data = (user_disk_device_data*)buffer; *data = (user_disk_device_data*)buffer;
else if (buffer) else if (buffer)
free(buffer); free(buffer);
return error; return error;
} }
// _SetTo // _SetTo
status_t status_t
BDiskDevice::_SetTo(partition_id id, bool deviceOnly, bool shadow, BDiskDevice::_SetTo(partition_id id, bool deviceOnly, bool shadow,
size_t neededSize) size_t neededSize)
{ {
Unset(); Unset();
// get the device data // get the device data
user_disk_device_data* data = NULL; user_disk_device_data* data = NULL;
status_t error = _GetData(id, deviceOnly, shadow, neededSize, &data); status_t error = _GetData(id, deviceOnly, shadow, neededSize, &data);
// set the data // set the data
if (error == B_OK) if (error == B_OK)
error = _SetTo(data); error = _SetTo(data);
// cleanup on error // cleanup on error
if (error != B_OK && data) if (error != B_OK && data)
free(data); free(data);
return error; return error;
} }
// _SetTo // _SetTo
status_t status_t
BDiskDevice::_SetTo(user_disk_device_data* data) BDiskDevice::_SetTo(user_disk_device_data* data)
{ {
Unset(); Unset();
if (!data) if (!data)
return B_BAD_VALUE; return B_BAD_VALUE;
fDeviceData = data; fDeviceData = 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) {
@@ -346,27 +385,34 @@ BDiskDevice::_SetTo(user_disk_device_data *data)
fDeviceData = NULL; fDeviceData = NULL;
Unset(); Unset();
} }
return error; return error;
} }
// _Update // _Update
status_t status_t
BDiskDevice::_Update(bool shadow, bool* updated) BDiskDevice::_Update(bool shadow, bool* updated)
{ {
if (InitCheck() != B_OK) if (InitCheck() != B_OK)
return InitCheck(); return InitCheck();
// get the device data // get the device data
user_disk_device_data* data = NULL; user_disk_device_data* data = NULL;
status_t error = _GetData(ID(), true, shadow, 0, &data); status_t error = _GetData(ID(), true, shadow, 0, &data);
// set the data // set the data
if (error == B_OK) if (error == B_OK)
error = _Update(data, updated); error = _Update(data, updated);
// cleanup on error // cleanup on error
if (error != B_OK && data) if (error != B_OK && data)
free(data); free(data);
return error; return error;
} }
// _Update // _Update
status_t status_t
BDiskDevice::_Update(user_disk_device_data* data, bool* updated) BDiskDevice::_Update(user_disk_device_data* data, bool* updated)
@@ -399,9 +445,11 @@ BDiskDevice::_Update(user_disk_device_data *data, bool *updated)
} }
free(oldData); free(oldData);
} }
return error; return error;
} }
// _AcceptVisitor // _AcceptVisitor
bool bool
BDiskDevice::_AcceptVisitor(BDiskDeviceVisitor* visitor, int32 level) BDiskDevice::_AcceptVisitor(BDiskDeviceVisitor* visitor, int32 level)
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2007, Ingo Weinhold, [email protected].de. * Copyright 2003-2007, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */