-
Notifications
You must be signed in to change notification settings - Fork 558
/
Copy pathPartition.cs
80 lines (76 loc) · 3.25 KB
/
Partition.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
namespace Cosmos.HAL.BlockDevice
{
/// <summary>
/// Partition class. Used to read and write blocks of data.
/// </summary>
public class Partition : BlockDevice
{
/// <summary>
/// Hosting device.
/// </summary>
public readonly BlockDevice Host;
/// <summary>
/// Starting sector.
/// </summary>
public readonly ulong StartingSector;
public static List<Partition> Partitions = new();
public override BlockDeviceType Type => Host.Type;
/// <summary>
/// Create new instance of the <see cref="Partition"/> class.
/// </summary>
/// <param name="aHost">A hosting device.</param>
/// <param name="aStartingSector">A starting sector.</param>
/// <param name="aSectorCount">A sector count.</param>
public Partition(BlockDevice aHost, ulong StartingSector, ulong SectorCount)
{
Host = aHost;
this.StartingSector = StartingSector;
mBlockCount = SectorCount;
mBlockSize = Host.BlockSize;
}
/// <summary>
/// Read block from partition.
/// </summary>
/// <param name="aBlockNo">A block to read from.</param>
/// <param name="aBlockCount">A number of blocks in the partition.</param>
/// <param name="aData">A data that been read.</param>
/// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception>
/// <exception cref="Exception">Thrown when data size invalid.</exception>
public override void ReadBlock(ulong aBlockNo, ulong aBlockCount, ref byte[] aData)
{
Global.debugger.SendInternal("-- Partition.ReadBlock --");
Global.debugger.SendInternal($"aBlockNo = {aBlockNo}");
Global.debugger.SendInternal($"aBlockCount = {aBlockCount}");
CheckDataSize(aData, aBlockCount);
ulong xHostBlockNo = StartingSector + aBlockNo;
CheckBlockNo(xHostBlockNo, aBlockCount);
Host.ReadBlock(xHostBlockNo, aBlockCount, ref aData);
Global.debugger.SendInternal("Returning -- Partition.ReadBlock --");
}
/// <summary>
/// Write block to partition.
/// </summary>
/// <param name="aBlockNo">A block number to write to.</param>
/// <param name="aBlockCount">A number of blocks in the partition.</param>
/// <param name="aData">A data to write.</param>
/// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception>
/// <exception cref="Exception">Thrown when data size invalid.</exception>
public override void WriteBlock(ulong aBlockNo, ulong aBlockCount, ref byte[] aData)
{
CheckDataSize(aData, aBlockCount);
ulong xHostBlockNo = StartingSector + aBlockNo;
CheckBlockNo(xHostBlockNo, aBlockCount);
Host.WriteBlock(xHostBlockNo, aBlockCount, ref aData);
}
/// <summary>
/// To string.
/// </summary>
/// <returns>string value.</returns>
public override string ToString()
{
return "Partition";
}
}
}