Initial checkin. Handles allocation for data chunks in a Udf physical partition.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5642 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,90 @@
|
|||||||
|
//----------------------------------------------------------------------
|
||||||
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
|
// by the OpenBeOS license.
|
||||||
|
//
|
||||||
|
// Copyright (c) 2003 Tyler Dauwalder, [email protected]
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*! \file PartitionAllocator.h
|
||||||
|
|
||||||
|
Udf physical partition allocator (implementation).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PhysicalPartitionAllocator.h"
|
||||||
|
|
||||||
|
PhysicalPartitionAllocator::PhysicalPartitionAllocator(uint16 number,
|
||||||
|
uint32 offset,
|
||||||
|
Allocator &allocator)
|
||||||
|
: fNumber(number)
|
||||||
|
, fOffset(offset)
|
||||||
|
, fAllocator(allocator)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Allocates the next available block.
|
||||||
|
|
||||||
|
\param block Output parameter into which the number of the
|
||||||
|
allocated block (in the partition) is stored.
|
||||||
|
\param physicalBlock Output parameter into which the number of the
|
||||||
|
allocated block (on the physical volume) is
|
||||||
|
stored.
|
||||||
|
|
||||||
|
\return
|
||||||
|
- B_OK: Success.
|
||||||
|
- error code: Failure, no blocks available.
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
PhysicalPartitionAllocator::GetNextBlock(uint32 &block, uint32 &physicalBlock)
|
||||||
|
{
|
||||||
|
status_t error = fAllocator.GetNextBlock(physicalBlock, fOffset);
|
||||||
|
if (!error)
|
||||||
|
block = physicalBlock-fOffset;
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Allocates the next available extent of given length.
|
||||||
|
|
||||||
|
\param length The desired length (in bytes) of the extent.
|
||||||
|
\param contiguous If false, signals that an extent of shorter length will
|
||||||
|
be accepted. This allows for small chunks of
|
||||||
|
unallocated space to be consumed, provided a
|
||||||
|
contiguous chunk is not needed.
|
||||||
|
\param extent Output parameter into which the extent as allocated
|
||||||
|
in the partition is stored. Note that the length
|
||||||
|
field of the extent may be shorter than the length
|
||||||
|
parameter passed to this function is \a contiguous is
|
||||||
|
false.
|
||||||
|
\param physicalExtent Output parameter into which the extent as allocated
|
||||||
|
on the physical volume is stored. Note that the length
|
||||||
|
field of the extent may be shorter than the length
|
||||||
|
parameter passed to this function is \a contiguous is
|
||||||
|
false.
|
||||||
|
|
||||||
|
\return
|
||||||
|
- B_OK: Success.
|
||||||
|
- error code: Failure.
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
PhysicalPartitionAllocator::GetNextExtent(uint32 length,
|
||||||
|
bool contiguous,
|
||||||
|
Udf::long_address &extent,
|
||||||
|
Udf::extent_address &physicalExtent)
|
||||||
|
{
|
||||||
|
status_t error = fAllocator.GetNextExtent(length, contiguous, physicalExtent, fOffset);
|
||||||
|
if (!error) {
|
||||||
|
extent.set_partition(PartitionNumber());
|
||||||
|
extent.set_block(physicalExtent.location()-fOffset);
|
||||||
|
extent.set_length(physicalExtent.length());
|
||||||
|
}
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Returns the length of the partition in blocks.
|
||||||
|
*/
|
||||||
|
uint32
|
||||||
|
PhysicalPartitionAllocator::Length() const
|
||||||
|
{
|
||||||
|
uint32 length = fAllocator.Length();
|
||||||
|
return fOffset >= length ? 0 : length-fOffset;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
//----------------------------------------------------------------------
|
||||||
|
// This software is part of the OpenBeOS distribution and is covered
|
||||||
|
// by the OpenBeOS license.
|
||||||
|
//
|
||||||
|
// Copyright (c) 2003 Tyler Dauwalder, [email protected]
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*! \file PhysicalPartitionAllocator.h
|
||||||
|
|
||||||
|
Udf physical partition allocator (declarations).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _PHYSICAL_PARTITION_ALLOCATOR_H
|
||||||
|
#define _PHYSICAL_PARTITION_ALLOCATOR_H
|
||||||
|
|
||||||
|
#include "Allocator.h"
|
||||||
|
#include "UdfStructures.h"
|
||||||
|
|
||||||
|
/*! \brief Allocates blocks and extents from a Udf physical partition.
|
||||||
|
*/
|
||||||
|
class PhysicalPartitionAllocator {
|
||||||
|
public:
|
||||||
|
PhysicalPartitionAllocator(uint16 number, uint32 offset, Allocator &allocator);
|
||||||
|
|
||||||
|
status_t GetNextBlock(uint32 &block, uint32 &physicalBlock);
|
||||||
|
status_t GetNextExtent(uint32 length, bool contiguous, Udf::long_address &extent,
|
||||||
|
Udf::extent_address &physicalExtent = dummyExtent);
|
||||||
|
|
||||||
|
|
||||||
|
uint16 PartitionNumber() const { return fNumber; }
|
||||||
|
uint32 Length() const;
|
||||||
|
private:
|
||||||
|
static Udf::extent_address dummyExtent;
|
||||||
|
uint16 fNumber; //!< The partition number of this partition
|
||||||
|
uint32 fOffset; //!< The offset of the start of this partition in physical space
|
||||||
|
Allocator &fAllocator;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _PHYSICAL_PARTITION_ALLOCATOR_H
|
||||||
Reference in New Issue
Block a user