Added a few handy methods. The PartitionType::Set*() methods return bool

(valid), now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22541 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2007-10-13 21:32:43 +00:00
parent 350043e707
commit 260bb9a2a1
2 changed files with 89 additions and 12 deletions

View File

@ -193,11 +193,12 @@ PartitionType::PartitionType()
\brief Sets the \a type via its ID. \brief Sets the \a type via its ID.
\param type ID of the partition type, it is in the range [0..255]. \param type ID of the partition type, it is in the range [0..255].
*/ */
void bool
PartitionType::SetType(uint8 type) PartitionType::SetType(uint8 type)
{ {
fType = type; fType = type;
fValid = partition_type_string(type); fValid = partition_type_string(type);
return fValid;
} }
// SetType // SetType
@ -205,17 +206,18 @@ PartitionType::SetType(uint8 type)
\brief Sets the type via its string name. \brief Sets the type via its string name.
\param typeName Name of the partition type. \param typeName Name of the partition type.
*/ */
void bool
PartitionType::SetType(const char *typeName) PartitionType::SetType(const char *typeName)
{ {
for (int32 i = 0; kPartitionTypes[i].name ; i++) { for (int32 i = 0; kPartitionTypes[i].name ; i++) {
if (!strcmp(typeName, kPartitionTypes[i].name)) { if (!strcmp(typeName, kPartitionTypes[i].name)) {
fType = kPartitionTypes[i].type; fType = kPartitionTypes[i].type;
fValid = true; fValid = true;
return; return fValid;
} }
} }
fValid = false; fValid = false;
return fValid;
} }
// SetContentType // SetContentType
@ -223,17 +225,18 @@ PartitionType::SetType(const char *typeName)
\brief Converts content type to the partition type that fits best. \brief Converts content type to the partition type that fits best.
\param content_type Name of the content type, it is standardized by system. \param content_type Name of the content type, it is standardized by system.
*/ */
void bool
PartitionType::SetContentType(const char *contentType) PartitionType::SetContentType(const char *contentType)
{ {
for (int32 i = 0; kPartitionContentTypes[i].name ; i++) { for (int32 i = 0; kPartitionContentTypes[i].name ; i++) {
if (!strcmp(contentType, kPartitionContentTypes[i].name)) { if (!strcmp(contentType, kPartitionContentTypes[i].name)) {
fType = kPartitionContentTypes[i].type; fType = kPartitionContentTypes[i].type;
fValid = true; fValid = true;
return; return fValid;
} }
} }
fValid = false; fValid = false;
return fValid;
} }
// FindNext // FindNext
@ -314,15 +317,30 @@ Partition::SetTo(const partition_descriptor *descriptor, off_t ptsOffset,
off_t baseOffset) off_t baseOffset)
{ {
TRACE(("Partition::SetTo(): active: %x\n", descriptor->active)); TRACE(("Partition::SetTo(): active: %x\n", descriptor->active));
SetTo(baseOffset + (off_t)descriptor->start * SECTOR_SIZE,
(off_t)descriptor->size * SECTOR_SIZE,
descriptor->type,
descriptor->active,
ptsOffset);
}
// SetTo
void
Partition::SetTo(off_t offset, off_t size, uint8 type, bool active,
off_t ptsOffset)
{
fPTSOffset = ptsOffset; fPTSOffset = ptsOffset;
fOffset = baseOffset + (off_t)descriptor->start * SECTOR_SIZE; fOffset = offset;
fSize = (off_t)descriptor->size * SECTOR_SIZE; fSize = size;
fType = descriptor->type; fType = type;
fActive = descriptor->active; fActive = active;
if (fSize == 0) if (fSize == 0)
Unset(); Unset();
} }
// Unset // Unset
void void
Partition::Unset() Partition::Unset()
@ -394,6 +412,16 @@ PrimaryPartition::SetTo(const partition_descriptor *descriptor, off_t ptsOffset)
Partition::SetTo(descriptor, ptsOffset, 0); Partition::SetTo(descriptor, ptsOffset, 0);
} }
// SetTo
void
PrimaryPartition::SetTo(off_t offset, off_t size, uint8 type, bool active)
{
Unset();
Partition::SetTo(offset, size, type, active, 0);
}
// Unset // Unset
void void
PrimaryPartition::Unset() PrimaryPartition::Unset()
@ -527,6 +555,20 @@ LogicalPartition::SetTo(const partition_descriptor *descriptor,
} }
} }
// SetTo
void
LogicalPartition::SetTo(off_t offset, off_t size, uint8 type, bool active,
off_t ptsOffset, PrimaryPartition *primary)
{
Unset();
if (primary) {
Partition::SetTo(offset, size, type, active, ptsOffset);
fPrimary = primary;
}
}
// Unset // Unset
void void
LogicalPartition::Unset() LogicalPartition::Unset()
@ -597,6 +639,33 @@ PartitionMap::PrimaryPartitionAt(int32 index) const
} }
// CountNonEmptyPrimaryPartitions
int32
PartitionMap::CountNonEmptyPrimaryPartitions() const
{
int32 count = 0;
for (int32 i = 0; i < 4; i++) {
if (!fPrimaries[i].IsEmpty())
count++;
}
return count;
}
// ExtendedPartitionIndex
int32
PartitionMap::ExtendedPartitionIndex() const
{
for (int32 i = 0; i < 4; i++) {
if (fPrimaries[i].IsExtended())
return i;
}
return -1;
}
// CountPartitions // CountPartitions
int32 int32
PartitionMap::CountPartitions() const PartitionMap::CountPartitions() const

View File

@ -101,9 +101,9 @@ class PartitionType {
public: public:
PartitionType(); PartitionType();
void SetType(uint8 type); bool SetType(uint8 type);
void SetType(const char *typeName); bool SetType(const char *typeName);
void SetContentType(const char *contentType); bool SetContentType(const char *contentType);
bool IsValid() const { return fValid; } bool IsValid() const { return fValid; }
bool IsEmpty() const { return is_empty_type(fType); } bool IsEmpty() const { return is_empty_type(fType); }
@ -127,6 +127,8 @@ public:
void SetTo(const partition_descriptor *descriptor, off_t ptsOffset, void SetTo(const partition_descriptor *descriptor, off_t ptsOffset,
off_t baseOffset); off_t baseOffset);
void SetTo(off_t offset, off_t size, uint8 type, bool active,
off_t ptsOffset);
void Unset(); void Unset();
bool IsEmpty() const { return is_empty_type(fType); } bool IsEmpty() const { return is_empty_type(fType); }
@ -167,6 +169,7 @@ public:
PrimaryPartition(); PrimaryPartition();
void SetTo(const partition_descriptor *descriptor, off_t ptsOffset); void SetTo(const partition_descriptor *descriptor, off_t ptsOffset);
void SetTo(off_t offset, off_t size, uint8 type, bool active);
void Unset(); void Unset();
status_t Assign(const PrimaryPartition& other); status_t Assign(const PrimaryPartition& other);
@ -197,6 +200,8 @@ public:
void SetTo(const partition_descriptor *descriptor, off_t ptsOffset, void SetTo(const partition_descriptor *descriptor, off_t ptsOffset,
PrimaryPartition *primary); PrimaryPartition *primary);
void SetTo(off_t offset, off_t size, uint8 type, bool active,
off_t ptsOffset, PrimaryPartition *primary);
void Unset(); void Unset();
void SetPrimaryPartition(PrimaryPartition *primary) { fPrimary = primary; } void SetPrimaryPartition(PrimaryPartition *primary) { fPrimary = primary; }
@ -227,6 +232,9 @@ public:
PrimaryPartition *PrimaryPartitionAt(int32 index); PrimaryPartition *PrimaryPartitionAt(int32 index);
const PrimaryPartition *PrimaryPartitionAt(int32 index) const; const PrimaryPartition *PrimaryPartitionAt(int32 index) const;
int32 IndexOfPrimaryPartition(const PrimaryPartition* partition) const; int32 IndexOfPrimaryPartition(const PrimaryPartition* partition) const;
int32 CountNonEmptyPrimaryPartitions() const;
int32 ExtendedPartitionIndex() const;
int32 CountPartitions() const; int32 CountPartitions() const;
int32 CountNonEmptyPartitions() const; int32 CountNonEmptyPartitions() const;