Initial checkin. Provides mapping of partition numbers to udf_partition_descriptors.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3353 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
15eec8a161
commit
8a079cf89c
|
@ -0,0 +1,79 @@
|
|||
#include "PartitionMap.h"
|
||||
|
||||
using namespace UDF;
|
||||
|
||||
/*! \brief Initializes the empty partition map.
|
||||
*/
|
||||
PartitionMap::PartitionMap()
|
||||
: fCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
/*! Debugging dump function.
|
||||
*/
|
||||
void
|
||||
PartitionMap::dump()
|
||||
{
|
||||
DUMP_INIT(CF_DUMP, "PartitionMap");
|
||||
PRINT(("fCount: %ld\n", fCount));
|
||||
PRINT(("fList:\n"));
|
||||
|
||||
SLList<udf_partition_descriptor>::Iterator i;
|
||||
fList.GetIterator(&i);
|
||||
if (i.GetCurrent()) {
|
||||
for (udf_partition_descriptor* partition = NULL;
|
||||
(partition = i.GetCurrent());
|
||||
i.GetNext())
|
||||
{
|
||||
PRINT((" partition #%d: start: %ld, length: %ld\n", partition->partition_number(),
|
||||
partition->start(), partition->length()));
|
||||
}
|
||||
|
||||
} else {
|
||||
PRINT((" (empty)\n"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Adds a copy of the given partition to the mapping,
|
||||
replacing any existing partition with the same partition
|
||||
number.
|
||||
*/
|
||||
status_t
|
||||
PartitionMap::Add(const udf_partition_descriptor* partition)
|
||||
{
|
||||
status_t err = partition ? B_OK : B_BAD_VALUE;
|
||||
if (!err) {
|
||||
udf_partition_descriptor *temp = Find(partition->partition_number());
|
||||
if (temp) {
|
||||
*temp = *partition;
|
||||
} else {
|
||||
err = fList.Insert(*partition) ? B_OK : B_ERROR;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
/*! \brief Returns a pointer to the partition in the list with the
|
||||
given number, or NULL if no such partition exists.
|
||||
*/
|
||||
udf_partition_descriptor*
|
||||
PartitionMap::Find(uint32 partitionNumber) const
|
||||
{
|
||||
udf_partition_descriptor *partition;
|
||||
SLList<udf_partition_descriptor>::Iterator i;
|
||||
fList.GetIterator(&i);
|
||||
while ((partition = i.GetCurrent())
|
||||
&& partition->partition_number() != partitionNumber)
|
||||
{
|
||||
i.GetNext();
|
||||
}
|
||||
return partition;
|
||||
}
|
||||
|
||||
udf_partition_descriptor*
|
||||
PartitionMap::operator[](uint32 partitionNumber) const
|
||||
{
|
||||
return Find(partitionNumber);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
//----------------------------------------------------------------------
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//
|
||||
// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
|
||||
//---------------------------------------------------------------------
|
||||
#ifndef _UDF_PARTITION_MAP_H
|
||||
#define _UDF_PARTITION_MAP_H
|
||||
|
||||
/*! \file PartitionMap.h
|
||||
*/
|
||||
|
||||
#include "cpp.h"
|
||||
#include "UdfDebug.h"
|
||||
#include "DiskStructures.h"
|
||||
|
||||
#include "SLList.h"
|
||||
|
||||
namespace UDF {
|
||||
|
||||
class PartitionMap {
|
||||
public:
|
||||
PartitionMap();
|
||||
|
||||
status_t Add(const udf_partition_descriptor* partition);
|
||||
udf_partition_descriptor* Find(uint32 partitionNumber) const;
|
||||
udf_partition_descriptor* operator[](uint32 partitionNumber) const;
|
||||
|
||||
void dump();
|
||||
private:
|
||||
SLList<UDF::udf_partition_descriptor> fList;
|
||||
uint32 fCount;
|
||||
};
|
||||
|
||||
}; // namespace UDF
|
||||
|
||||
#endif // _UDF_PARTITION_MAP_H
|
Loading…
Reference in New Issue