diff --git a/src/add-ons/kernel/file_systems/udf/PartitionMap.cpp b/src/add-ons/kernel/file_systems/udf/PartitionMap.cpp new file mode 100644 index 0000000000..b272aadc7a --- /dev/null +++ b/src/add-ons/kernel/file_systems/udf/PartitionMap.cpp @@ -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::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::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); +} diff --git a/src/add-ons/kernel/file_systems/udf/PartitionMap.h b/src/add-ons/kernel/file_systems/udf/PartitionMap.h new file mode 100644 index 0000000000..1a4ad04793 --- /dev/null +++ b/src/add-ons/kernel/file_systems/udf/PartitionMap.h @@ -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 fList; + uint32 fCount; +}; + +}; // namespace UDF + +#endif // _UDF_PARTITION_MAP_H