using System;
namespace Cosmos.HAL.BlockDevice
{
///
/// Partition class. Used to read and write blocks of data.
///
public class Partition : BlockDevice
{
///
/// Hosting device.
///
private readonly BlockDevice mHost;
///
/// Starting sector.
///
private readonly UInt64 mStartingSector;
///
/// Create new inctanse of the class.
///
/// A hosting device.
/// A starting sector.
/// A sector count.
public Partition(BlockDevice aHost, UInt64 aStartingSector, UInt64 aSectorCount)
{
mHost = aHost;
mStartingSector = aStartingSector;
mBlockCount = aSectorCount;
mBlockSize = aHost.BlockSize;
}
///
/// Read block from partition.
///
/// A block to read from.
/// A number of blocks in the partition.
/// A data that been read.
/// Thrown when data lenght is greater then Int32.MaxValue.
/// Thrown when data size invalid.
public override void ReadBlock(UInt64 aBlockNo, UInt64 aBlockCount, ref byte[] aData)
{
CheckDataSize(aData, aBlockCount);
UInt64 xHostBlockNo = mStartingSector + aBlockNo;
CheckBlockNo(xHostBlockNo, aBlockCount);
mHost.ReadBlock(xHostBlockNo, aBlockCount, ref aData);
}
///
/// Write block to partition.
///
/// A block number to write to.
/// A number of blocks in the partition.
/// A data to write.
/// Thrown when data lenght is greater then Int32.MaxValue.
/// Thrown when data size invalid.
public override void WriteBlock(UInt64 aBlockNo, UInt64 aBlockCount,ref byte[] aData)
{
CheckDataSize(aData, aBlockCount);
UInt64 xHostBlockNo = mStartingSector + aBlockNo;
CheckBlockNo(xHostBlockNo, aBlockCount);
mHost.WriteBlock(xHostBlockNo, aBlockCount, ref aData);
}
///
/// To string.
///
/// string value.
public override string ToString()
{
return "Partition";
}
}
}