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:
parent
350043e707
commit
260bb9a2a1
@ -193,11 +193,12 @@ 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
|
||||
bool
|
||||
PartitionType::SetType(uint8 type)
|
||||
{
|
||||
fType = type;
|
||||
fValid = partition_type_string(type);
|
||||
return fValid;
|
||||
}
|
||||
|
||||
// SetType
|
||||
@ -205,17 +206,18 @@ PartitionType::SetType(uint8 type)
|
||||
\brief Sets the type via its string name.
|
||||
\param typeName Name of the partition type.
|
||||
*/
|
||||
void
|
||||
bool
|
||||
PartitionType::SetType(const char *typeName)
|
||||
{
|
||||
for (int32 i = 0; kPartitionTypes[i].name ; i++) {
|
||||
if (!strcmp(typeName, kPartitionTypes[i].name)) {
|
||||
fType = kPartitionTypes[i].type;
|
||||
fValid = true;
|
||||
return;
|
||||
return fValid;
|
||||
}
|
||||
}
|
||||
fValid = false;
|
||||
return fValid;
|
||||
}
|
||||
|
||||
// SetContentType
|
||||
@ -223,17 +225,18 @@ PartitionType::SetType(const char *typeName)
|
||||
\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
|
||||
bool
|
||||
PartitionType::SetContentType(const char *contentType)
|
||||
{
|
||||
for (int32 i = 0; kPartitionContentTypes[i].name ; i++) {
|
||||
if (!strcmp(contentType, kPartitionContentTypes[i].name)) {
|
||||
fType = kPartitionContentTypes[i].type;
|
||||
fValid = true;
|
||||
return;
|
||||
return fValid;
|
||||
}
|
||||
}
|
||||
fValid = false;
|
||||
return fValid;
|
||||
}
|
||||
|
||||
// FindNext
|
||||
@ -314,15 +317,30 @@ Partition::SetTo(const partition_descriptor *descriptor, off_t ptsOffset,
|
||||
off_t baseOffset)
|
||||
{
|
||||
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;
|
||||
fOffset = baseOffset + (off_t)descriptor->start * SECTOR_SIZE;
|
||||
fSize = (off_t)descriptor->size * SECTOR_SIZE;
|
||||
fType = descriptor->type;
|
||||
fActive = descriptor->active;
|
||||
fOffset = offset;
|
||||
fSize = size;
|
||||
fType = type;
|
||||
fActive = active;
|
||||
|
||||
if (fSize == 0)
|
||||
Unset();
|
||||
}
|
||||
|
||||
|
||||
// Unset
|
||||
void
|
||||
Partition::Unset()
|
||||
@ -394,6 +412,16 @@ PrimaryPartition::SetTo(const partition_descriptor *descriptor, off_t ptsOffset)
|
||||
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
|
||||
void
|
||||
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
|
||||
void
|
||||
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
|
||||
int32
|
||||
PartitionMap::CountPartitions() const
|
||||
|
@ -101,9 +101,9 @@ class PartitionType {
|
||||
public:
|
||||
PartitionType();
|
||||
|
||||
void SetType(uint8 type);
|
||||
void SetType(const char *typeName);
|
||||
void SetContentType(const char *contentType);
|
||||
bool SetType(uint8 type);
|
||||
bool SetType(const char *typeName);
|
||||
bool SetContentType(const char *contentType);
|
||||
|
||||
bool IsValid() const { return fValid; }
|
||||
bool IsEmpty() const { return is_empty_type(fType); }
|
||||
@ -127,6 +127,8 @@ public:
|
||||
|
||||
void SetTo(const partition_descriptor *descriptor, off_t ptsOffset,
|
||||
off_t baseOffset);
|
||||
void SetTo(off_t offset, off_t size, uint8 type, bool active,
|
||||
off_t ptsOffset);
|
||||
void Unset();
|
||||
|
||||
bool IsEmpty() const { return is_empty_type(fType); }
|
||||
@ -167,6 +169,7 @@ public:
|
||||
PrimaryPartition();
|
||||
|
||||
void SetTo(const partition_descriptor *descriptor, off_t ptsOffset);
|
||||
void SetTo(off_t offset, off_t size, uint8 type, bool active);
|
||||
void Unset();
|
||||
|
||||
status_t Assign(const PrimaryPartition& other);
|
||||
@ -197,6 +200,8 @@ public:
|
||||
|
||||
void SetTo(const partition_descriptor *descriptor, off_t ptsOffset,
|
||||
PrimaryPartition *primary);
|
||||
void SetTo(off_t offset, off_t size, uint8 type, bool active,
|
||||
off_t ptsOffset, PrimaryPartition *primary);
|
||||
void Unset();
|
||||
|
||||
void SetPrimaryPartition(PrimaryPartition *primary) { fPrimary = primary; }
|
||||
@ -227,6 +232,9 @@ public:
|
||||
PrimaryPartition *PrimaryPartitionAt(int32 index);
|
||||
const PrimaryPartition *PrimaryPartitionAt(int32 index) const;
|
||||
int32 IndexOfPrimaryPartition(const PrimaryPartition* partition) const;
|
||||
int32 CountNonEmptyPrimaryPartitions() const;
|
||||
|
||||
int32 ExtendedPartitionIndex() const;
|
||||
|
||||
int32 CountPartitions() const;
|
||||
int32 CountNonEmptyPartitions() const;
|
||||
|
Loading…
Reference in New Issue
Block a user