* Style cleanup.

* Moved method documentation from headers to source files.
* Removed test code.
* Added TODOs where I spotted problems.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21717 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2007-07-27 02:48:18 +00:00
parent 74f09960d2
commit 288102e6c3
7 changed files with 669 additions and 1004 deletions
@@ -12,8 +12,8 @@
// constructor // constructor
PartitionLocker::PartitionLocker(partition_id partitionID) PartitionLocker::PartitionLocker(partition_id partitionID)
: device_(NULL), : fDevice(NULL),
partitionID_(partitionID) fPartitionID(partitionID)
{ {
} }
@@ -26,14 +26,14 @@ PartitionLocker::~PartitionLocker()
bool bool
PartitionLocker::IsLocked() const PartitionLocker::IsLocked() const
{ {
return device_; return fDevice;
} }
// PartitionId // PartitionId
partition_id partition_id
PartitionLocker::PartitionId() const PartitionLocker::PartitionId() const
{ {
return partitionID_; return fPartitionID;
} }
@@ -44,7 +44,7 @@ PartitionLocker::PartitionId() const
PartitionReadLocker::PartitionReadLocker(partition_id partitionID) PartitionReadLocker::PartitionReadLocker(partition_id partitionID)
: PartitionLocker(partitionID) : PartitionLocker(partitionID)
{ {
device_ = read_lock_disk_device(partitionID); fDevice = read_lock_disk_device(partitionID);
} }
// destructor // destructor
@@ -62,7 +62,7 @@ PartitionReadLocker::~PartitionReadLocker()
PartitionWriteLocker::PartitionWriteLocker(partition_id partitionID) PartitionWriteLocker::PartitionWriteLocker(partition_id partitionID)
: PartitionLocker(partitionID) : PartitionLocker(partitionID)
{ {
device_ = write_lock_disk_device(partitionID); fDevice = write_lock_disk_device(partitionID);
} }
// destructor // destructor
@@ -17,42 +17,47 @@
#include <disk_device_manager.h> #include <disk_device_manager.h>
class PartitionLocker { class PartitionLocker {
public: public:
PartitionLocker(partition_id partitionID); PartitionLocker(partition_id partitionID);
virtual ~PartitionLocker(); ~PartitionLocker();
bool IsLocked() const; bool IsLocked() const;
partition_id PartitionId() const; partition_id PartitionId() const;
protected: protected:
const disk_device_data *device_; const disk_device_data *fDevice;
private: private:
partition_id partitionID_; partition_id fPartitionID;
}; };
/*! /*!
\brief Structure which locks given partition for reading. \brief Structure which locks given partition for reading.
When this structure is going to be destroyed, it automatically unlocks When this structure is going to be destroyed, it automatically unlocks
that partition. that partition.
*/ */
class PartitionReadLocker : public PartitionLocker { class PartitionReadLocker : public PartitionLocker {
public: public:
PartitionReadLocker(partition_id partitionID); PartitionReadLocker(partition_id partitionID);
virtual ~PartitionReadLocker(); ~PartitionReadLocker();
}; };
/*! /*!
\brief Structure which locks given partition for writing. \brief Structure which locks given partition for writing.
When this structure is going to be destroyed, it automatically unlocks When this structure is going to be destroyed, it automatically unlocks
that partition. that partition.
*/ */
class PartitionWriteLocker : public PartitionLocker { class PartitionWriteLocker : public PartitionLocker {
public: public:
PartitionWriteLocker(partition_id partitionID); PartitionWriteLocker(partition_id partitionID);
virtual ~PartitionWriteLocker(); ~PartitionWriteLocker();
}; };
#endif // _PARTITION_LOCKER_H
#endif // _PARTITION_LOCKER_H
@@ -183,62 +183,105 @@ is_inside_partitions(off_t location, const Partition **partitions, int32 count)
// constructor // constructor
PartitionType::PartitionType() PartitionType::PartitionType()
: type_(0), : fType(0),
valid_(false) fValid(false)
{ {
} }
// SetType // SetType
/*!
\brief Sets the \a type via its ID.
\param type ID of the partition type, it is in the range [0..255].
*/
void void
PartitionType::SetType(uint8 type) PartitionType::SetType(uint8 type)
{ {
type_ = type; fType = type;
valid_ = partition_type_string(type); fValid = partition_type_string(type);
} }
// SetType // SetType
/*!
\brief Sets the type via its string name.
\param typeName Name of the partition type.
*/
void void
PartitionType::SetType(const char *type_name) PartitionType::SetType(const char *typeName)
{ {
for (int32 i = 0; kPartitionTypes[i].name ; i++) { for (int32 i = 0; kPartitionTypes[i].name ; i++) {
if (!strcmp(type_name, kPartitionTypes[i].name)) { if (!strcmp(typeName, kPartitionTypes[i].name)) {
type_ = kPartitionTypes[i].type; fType = kPartitionTypes[i].type;
valid_ = true; fValid = true;
return; return;
} }
} }
valid_ = false; fValid = false;
} }
// SetContentType // SetContentType
/*!
\brief Converts content type to the partition type that fits best.
\param content_type Name of the content type, it is standardized by system.
*/
void void
PartitionType::SetContentType(const char *content_type) PartitionType::SetContentType(const char *contentType)
{ {
for (int32 i = 0; kPartitionContentTypes[i].name ; i++) { for (int32 i = 0; kPartitionContentTypes[i].name ; i++) {
if (!strcmp(content_type, kPartitionContentTypes[i].name)) { if (!strcmp(contentType, kPartitionContentTypes[i].name)) {
type_ = kPartitionContentTypes[i].type; fType = kPartitionContentTypes[i].type;
valid_ = true; fValid = true;
return; return;
} }
} }
valid_ = false; fValid = false;
} }
// FindNext // FindNext
/*!
\brief Finds next supported partition.
*/
void void
PartitionType::FindNext() PartitionType::FindNext()
{ {
for (int32 i = 0; kPartitionTypes[i].name; i++) { for (int32 i = 0; kPartitionTypes[i].name; i++) {
if (type_ < kPartitionTypes[i].type) { if (fType < kPartitionTypes[i].type) {
type_ = kPartitionTypes[i].type; fType = kPartitionTypes[i].type;
valid_ = true; fValid = true;
return; return;
} }
} }
valid_ = false; fValid = false;
} }
/*!
\fn bool PartitionType::IsValid() const
\brief Check whether the current type is valid.
*/
/*!
\fn bool PartitionType::IsEmpty() const
\brief Check whether the current type describes empty type.
*/
/*!
\fn bool PartitionType::IsExtended() const
\brief Check whether the current type describes extended partition type.
*/
/*!
\fn uint8 PartitionType::Type() const
\brief Returns ID of the current type.
*/
/*!
\fn void PartitionType::GetTypeString(char *buffer) const
\brief Returns string name of the current type.
\param buffer Buffer where the name is stored, has to be allocated with
sufficient length.
*/
// #pragma mark - Partition // #pragma mark - Partition
@@ -31,24 +31,21 @@
// is_empty_type // is_empty_type
static inline static inline bool
bool
is_empty_type(uint8 type) is_empty_type(uint8 type)
{ {
return (type == 0x00); return (type == 0x00);
} }
// is_extended_type // is_extended_type
static inline static inline bool
bool
is_extended_type(uint8 type) is_extended_type(uint8 type)
{ {
return (type == 0x05 || type == 0x0f || type == 0x85); return (type == 0x05 || type == 0x0f || type == 0x85);
} }
// fill_buffer // fill_buffer
static inline static inline void
void
fill_buffer(char *buffer, uint32 length, char ch) fill_buffer(char *buffer, uint32 length, char ch)
{ {
for (uint32 i = 0; i < length; i++) for (uint32 i = 0; i < length; i++)
@@ -104,53 +101,21 @@ class PartitionType {
public: public:
PartitionType(); PartitionType();
/*!
\brief Sets the \a type via its ID.
\param type ID of the partition type, it is in the range [0..255].
*/
void SetType(uint8 type); void SetType(uint8 type);
/*! void SetType(const char *typeName);
\brief Sets the type via its string name. void SetContentType(const char *contentType);
\param type_name Name of the partition type.
*/
void SetType(const char *type_name);
/*!
\brief Converts content type to the partition type that fits best.
\param content_type Name of the content type, it is standardized by system.
*/
void SetContentType(const char *content_type);
/*! bool IsValid() const { return fValid; }
\brief Check whether the current type is valid. bool IsEmpty() const { return is_empty_type(fType); }
*/ bool IsExtended() const { return is_extended_type(fType); }
bool IsValid() const { return valid_; }
/*!
\brief Check whether the current type describes empty type.
*/
bool IsEmpty() const { return is_empty_type(type_); }
/*!
\brief Check whether the current type describes extended partition type.
*/
bool IsExtended() const { return is_extended_type(type_); }
/*! uint8 Type() const { return fType; }
\brief Returns ID of the current type.
*/
uint8 Type() const { return type_; }
/*!
\brief Finds next supported partition.
*/
void FindNext(); void FindNext();
/*!
\brief Returns string name of the current type.
\param buffer Buffer where the name is stored, has to be allocated with
sufficient length.
*/
void GetTypeString(char *buffer) const void GetTypeString(char *buffer) const
{ get_partition_type_string(type_, buffer); } { get_partition_type_string(fType, buffer); }
private: private:
uint8 type_; uint8 fType;
bool valid_; bool fValid;
}; };
// Partition // Partition
@@ -158,10 +123,10 @@ class Partition {
public: public:
Partition(); Partition();
Partition(const partition_descriptor *descriptor, off_t ptsOffset, Partition(const partition_descriptor *descriptor, off_t ptsOffset,
off_t baseOffset, int32 blockSize); off_t baseOffset, int32 blockSize);
void SetTo(const partition_descriptor *descriptor, off_t ptsOffset, void SetTo(const partition_descriptor *descriptor, off_t ptsOffset,
off_t baseOffset, int32 blockSize); off_t baseOffset, int32 blockSize);
void Unset(); void Unset();
bool IsEmpty() const { return is_empty_type(fType); } bool IsEmpty() const { return is_empty_type(fType); }
@@ -201,10 +166,10 @@ class PrimaryPartition : public Partition {
public: public:
PrimaryPartition(); PrimaryPartition();
PrimaryPartition(const partition_descriptor *descriptor, off_t ptsOffset, PrimaryPartition(const partition_descriptor *descriptor, off_t ptsOffset,
int32 blockSize); int32 blockSize);
void SetTo(const partition_descriptor *descriptor, off_t ptsOffset, void SetTo(const partition_descriptor *descriptor, off_t ptsOffset,
int32 blockSize); int32 blockSize);
void Unset(); void Unset();
// only if extended // only if extended
@@ -224,10 +189,10 @@ class LogicalPartition : public Partition {
public: public:
LogicalPartition(); LogicalPartition();
LogicalPartition(const partition_descriptor *descriptor, off_t ptsOffset, LogicalPartition(const partition_descriptor *descriptor, off_t ptsOffset,
int32 blockSize, PrimaryPartition *primary); int32 blockSize, PrimaryPartition *primary);
void SetTo(const partition_descriptor *descriptor, off_t ptsOffset, void SetTo(const partition_descriptor *descriptor, off_t ptsOffset,
int32 blockSize, PrimaryPartition *primary); int32 blockSize, PrimaryPartition *primary);
void Unset(); void Unset();
void SetPrimaryPartition(PrimaryPartition *primary) { fPrimary = primary; } void SetPrimaryPartition(PrimaryPartition *primary) { fPrimary = primary; }
@@ -33,8 +33,16 @@
using std::nothrow; using std::nothrow;
// constructor // constructor
/*!
\brief Creates the writer.
\param deviceFD File descriptor.
\param sessionOffset Disk offset of the partition with partitioning system.
\param sessionSize Size of the partition with partitioning system.
\param blockSize Size of the sector on given disk.
*/
PartitionMapWriter::PartitionMapWriter(int deviceFD, off_t sessionOffset, PartitionMapWriter::PartitionMapWriter(int deviceFD, off_t sessionOffset,
off_t sessionSize, int32 blockSize) off_t sessionSize, int32 blockSize)
: fDeviceFD(deviceFD), : fDeviceFD(deviceFD),
fSessionOffset(sessionOffset), fSessionOffset(sessionOffset),
fSessionSize(sessionSize), fSessionSize(sessionSize),
@@ -50,6 +58,15 @@ PartitionMapWriter::~PartitionMapWriter()
} }
// WriteMBR // WriteMBR
/*!
\brief Writes Master Boot Record to the first sector of the disk.
If a \a block is not specified, the sector is firstly read from the disk
and after changing relevant items it is written back to the disk.
This allows to keep code area in MBR intact.
\param block Pointer to \c partition_table_sector.
\param map Pointer to the PartitionMap structure describing disk partitions.
*/
status_t status_t
PartitionMapWriter::WriteMBR(uint8 *block, const PartitionMap *map) PartitionMapWriter::WriteMBR(uint8 *block, const PartitionMap *map)
{ {
@@ -78,8 +95,21 @@ PartitionMapWriter::WriteMBR(uint8 *block, const PartitionMap *map)
} }
// WriteLogical // WriteLogical
/*!
\brief Writes Partition Table Sector of the logical \a partition to the
disk.
This function ensures that the connection of the following linked list
of logical partitions will be correct. It do nothing with the connection of
previous logical partitions (call this function on previous logical
partition to ensure it).
\param block Pointer to \c partition_table_sector.
\param partition Pointer to the logical partition.
*/
status_t status_t
PartitionMapWriter::WriteLogical(uint8 *block, const LogicalPartition *partition) PartitionMapWriter::WriteLogical(uint8 *block,
const LogicalPartition *partition)
{ {
status_t error = (partition ? B_OK : B_BAD_VALUE); status_t error = (partition ? B_OK : B_BAD_VALUE);
if (error == B_OK) { if (error == B_OK) {
@@ -103,9 +133,21 @@ PartitionMapWriter::WriteLogical(uint8 *block, const LogicalPartition *partition
} }
// WriteExtendedHead // WriteExtendedHead
/*!
\brief Writes Extended Boot Record to the first sector of Extended
Partition.
Writes the head of linked list describing logical partitions.
If the \a first_partition is not specified, it only initializes EBR and the
linked list contains no logical partitions.
\param block Pointer to \c partition_table_sector.
\param first_partition Pointer to the first logical partition.
*/
status_t status_t
PartitionMapWriter::WriteExtendedHead(uint8 *block, PartitionMapWriter::WriteExtendedHead(uint8 *block,
const LogicalPartition *first_partition) const LogicalPartition *first_partition)
{ {
LogicalPartition partition; LogicalPartition partition;
if (first_partition) if (first_partition)
@@ -160,8 +202,7 @@ PartitionMapWriter::_WritePrimary(partition_table_sector *pts)
// _WriteExtended // _WriteExtended
status_t status_t
PartitionMapWriter::_WriteExtended(partition_table_sector *pts, PartitionMapWriter::_WriteExtended(partition_table_sector *pts,
const LogicalPartition *partition, const LogicalPartition *partition, const LogicalPartition *next)
const LogicalPartition *next)
{ {
if (!pts || !partition) if (!pts || !partition)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -172,7 +213,8 @@ PartitionMapWriter::_WriteExtended(partition_table_sector *pts,
// check the partition's location // check the partition's location
if (!partition->CheckLocation(fSessionSize, fBlockSize)) { if (!partition->CheckLocation(fSessionSize, fBlockSize)) {
TRACE(("intel: _WriteExtended(): Invalid partition " TRACE(("intel: _WriteExtended(): Invalid partition "
"location: pts: %lld, offset: %lld, size: %lld, fSessionSize: %lld\n", "location: pts: %lld, offset: %lld, size: %lld, "
"fSessionSize: %lld\n",
partition->PTSOffset(), partition->Offset(), partition->PTSOffset(), partition->Offset(),
partition->Size(), fSessionSize)); partition->Size(), fSessionSize));
return B_BAD_DATA; return B_BAD_DATA;
@@ -180,7 +222,8 @@ PartitionMapWriter::_WriteExtended(partition_table_sector *pts,
// write the table // write the table
partition_descriptor *descriptor = &(pts->table[0]); partition_descriptor *descriptor = &(pts->table[0]);
partition->GetPartitionDescriptor(descriptor, partition->PTSOffset(), fBlockSize); partition->GetPartitionDescriptor(descriptor, partition->PTSOffset(),
fBlockSize);
// setting offset and size of the next partition in the linked list // setting offset and size of the next partition in the linked list
descriptor = &(pts->table[1]); descriptor = &(pts->table[1]);
@@ -205,9 +248,10 @@ PartitionMapWriter::_WriteExtended(partition_table_sector *pts,
} }
// _ReadPTS // _ReadPTS
/*! \brief Reads the sector from the disk.
*/
status_t status_t
PartitionMapWriter::_ReadPTS(off_t offset, partition_table_sector *pts) PartitionMapWriter::_ReadPTS(off_t offset, partition_table_sector *pts)
// reads the sector from the disk
{ {
status_t error = B_OK; status_t error = B_OK;
if (!pts) if (!pts)
@@ -233,9 +277,10 @@ PartitionMapWriter::_ReadPTS(off_t offset, partition_table_sector *pts)
} }
// _WritePTS // _WritePTS
/*! \brief Writes the sector to the disk.
*/
status_t status_t
PartitionMapWriter::_WritePTS(off_t offset, const partition_table_sector *pts) PartitionMapWriter::_WritePTS(off_t offset, const partition_table_sector *pts)
// writes the sector to the disk
{ {
status_t error = B_OK; status_t error = B_OK;
if (!pts) if (!pts)
@@ -11,8 +11,9 @@
\ingroup intel_module \ingroup intel_module
\brief Implementation of disk writer for "intel" style partitions. \brief Implementation of disk writer for "intel" style partitions.
Writer can write \b Master \b Boot \b Record or \b Extended \b Boot \b Records Writer can write \b Master \b Boot \b Record or \b Extended \b Boot
to the disk according to partitions defined in \c PartitionMap structure. \b Records to the disk according to partitions defined in \c PartitionMap
structure.
*/ */
@@ -33,66 +34,30 @@ struct partition_table_sector;
This class serves for writing \a primary and \a logical \a partitions to disk. This class serves for writing \a primary and \a logical \a partitions to disk.
*/ */
class PartitionMapWriter { class PartitionMapWriter {
public: public:
/*! PartitionMapWriter(int deviceFD, off_t sessionOffset, off_t sessionSize,
\brief Creates the writer. int32 blockSize);
~PartitionMapWriter();
\param deviceFD File descriptor. status_t WriteMBR(uint8 *block, const PartitionMap *map);
\param sessionOffset Disk offset of the partition with partitioning system. status_t WriteLogical(uint8 *block, const LogicalPartition *partition);
\param sessionSize Size of the partition with partitioning system. status_t WriteExtendedHead(uint8 *block,
\param blockSize Size of the sector on given disk. const LogicalPartition *first_partition);
*/
PartitionMapWriter(int deviceFD, off_t sessionOffset, off_t sessionSize,
int32 blockSize);
~PartitionMapWriter();
/*! private:
\brief Writes Master Boot Record to the first sector of the disk. status_t _WritePrimary(partition_table_sector *pts);
status_t _WriteExtended(partition_table_sector *pts,
const LogicalPartition *partition, const LogicalPartition *next);
status_t _ReadPTS(off_t offset, partition_table_sector *pts = NULL);
status_t _WritePTS(off_t offset, const partition_table_sector *pts = NULL);
If a \a block is not specified, the sector is firstly read from the disk private:
and after changing relevant items it is written back to the disk. int fDeviceFD;
This allows to keep code area in MBR intact. off_t fSessionOffset;
\param block Pointer to \c partition_table_sector. off_t fSessionSize;
\param map Pointer to the PartitionMap structure describing disk partitions. int32 fBlockSize;
*/ partition_table_sector *fPTS; // while writing
status_t WriteMBR(uint8 *block, const PartitionMap *map); const PartitionMap *fMap;
/*!
\brief Writes Partition Table Sector of the logical \a partition to the disk.
This function ensures that the connection of the following linked list of logical
partitions will be correct. It do nothing with the connection of previous logical
partitions (call this function on previous logical partition to ensure it).
\param block Pointer to \c partition_table_sector.
\param partition Pointer to the logical partition.
*/
status_t WriteLogical(uint8 *block, const LogicalPartition *partition);
/*!
\brief Writes Extended Boot Record to the first sector of Extended Partition.
Writes the head of linked list describing logical partitions.
If the \a first_partition is not specified, it only initializes EBR and the linked
list contains no logical partitions.
\param block Pointer to \c partition_table_sector.
\param first_partition Pointer to the first logical partition.
*/
status_t WriteExtendedHead(uint8 *block, const LogicalPartition *first_partition);
private:
status_t _WritePrimary(partition_table_sector *pts);
status_t _WriteExtended(partition_table_sector *pts,
const LogicalPartition *partition,
const LogicalPartition *next);
status_t _ReadPTS(off_t offset, partition_table_sector *pts = NULL);
status_t _WritePTS(off_t offset, const partition_table_sector *pts = NULL);
private:
int fDeviceFD;
off_t fSessionOffset;
off_t fSessionSize;
int32 fBlockSize;
partition_table_sector *fPTS; // while writing
const PartitionMap *fMap;
}; };
#endif // PARTITION_MAP_WRITER_H #endif // PARTITION_MAP_WRITER_H
File diff suppressed because it is too large Load Diff