mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 20:39:01 +00:00
This commit is contained in:
parent
91066ec8cd
commit
16632ec66c
2 changed files with 103 additions and 93 deletions
103
source/Cosmos.Kernel.FileSystems/MBT.cs
Normal file
103
source/Cosmos.Kernel.FileSystems/MBT.cs
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cosmos.Hardware;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Cosmos.Kernel.FileSystems {
|
||||
public static class MBT {
|
||||
private class MBTPartition: BlockDevice {
|
||||
private readonly BlockDevice mBackend;
|
||||
private readonly ulong mBlockStart;
|
||||
private readonly ulong mBlockCount;
|
||||
private readonly string mName;
|
||||
public MBTPartition(BlockDevice aBackend, ulong aBlockStart, ulong aBlockCount, string aName) {
|
||||
mBlockStart = aBlockStart;
|
||||
mBlockCount = aBlockCount;
|
||||
mBackend = aBackend;
|
||||
mName = aName;
|
||||
}
|
||||
|
||||
public override uint BlockSize {
|
||||
get {
|
||||
return mBackend.BlockSize;
|
||||
}
|
||||
}
|
||||
|
||||
public override ulong BlockCount {
|
||||
get {
|
||||
return mBlockCount;
|
||||
}
|
||||
}
|
||||
|
||||
private ulong GetActualBlock(ulong aBlock) {
|
||||
return aBlock;
|
||||
}
|
||||
|
||||
public override byte[] ReadBlock(ulong aBlock) {
|
||||
return mBackend.ReadBlock(GetActualBlock(aBlock));
|
||||
}
|
||||
|
||||
public override void WriteBlock(ulong aBlock, byte[] aContents) {
|
||||
mBackend.WriteBlock(GetActualBlock(aBlock), aContents);
|
||||
}
|
||||
|
||||
public override string Name {
|
||||
get {
|
||||
return mName;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void Initialize()
|
||||
{
|
||||
//DebugUtil.SendMessage("MBT", "Initializing");
|
||||
//DebugUtil.SendNumber("MBT", "DeviceCount", (uint)Device.Devices.Count, 32);
|
||||
Device.Devices.ForEach(delegate(Device d)
|
||||
{
|
||||
addDevice(d as BlockDevice);
|
||||
});
|
||||
}
|
||||
|
||||
private static void addDevice(BlockDevice xBlockDev)
|
||||
{
|
||||
if (xBlockDev == null)
|
||||
return;
|
||||
|
||||
int xContentsIndex = 0x1BE;
|
||||
//DebugUtil.SendMessage("MBT", "Found Device");
|
||||
byte[] xBlockContents = xBlockDev.ReadBlock(0);
|
||||
// detecting whether MBT or not
|
||||
//DebugUtil.SendNumber("MBT", "xBlockDev.BlockSize", xBlockDev.BlockSize, 32);
|
||||
|
||||
//DebugUtil.SendDoubleNumber("MBT", "Last bytes of block", xBlockContents[510], 8, xBlockContents[511], 8);
|
||||
if (!(xBlockContents[xBlockDev.BlockSize - 2] == 0x55 && xBlockContents[xBlockDev.BlockSize - 1] == 0xAA))
|
||||
{
|
||||
//DebugUtil.SendMessage("MBT", "Does not contain MBR");
|
||||
//Hardware.DebugUtil.SendATA_BlockReceived(255, 255, 0, xBlockContents);
|
||||
return;
|
||||
}
|
||||
|
||||
for (byte j = 0; j < 4; j++)
|
||||
{
|
||||
//DebugUtil.SendNumber("MBT", "Partition Status", xBlockContents[xContentsIndex], 8);
|
||||
if (!(xBlockContents[xContentsIndex] == 0x80 || xBlockContents[xContentsIndex] == 0))
|
||||
{
|
||||
xContentsIndex += 16;
|
||||
continue;
|
||||
}
|
||||
xContentsIndex += 8;
|
||||
uint xStart = BitConverter.ToUInt32(xBlockContents, xContentsIndex);
|
||||
xContentsIndex += 4;
|
||||
uint xLength = BitConverter.ToUInt32(xBlockContents, xContentsIndex);
|
||||
xContentsIndex += 4;
|
||||
if (xStart > 0 && xLength > 0)
|
||||
{
|
||||
//DebugUtil.SendDoubleNumber("MBT", "Entry Found. Start, Length in blocks", xStart, 32, xLength, 32);
|
||||
xStart += 2;
|
||||
Console.WriteLine("Add Partition to Device list");
|
||||
Device.Add(new MBTPartition(xBlockDev, xStart, xLength, "Partition"));
|
||||
//DebugUtil.SendMessage("MBT", "FoundPartition");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cosmos.Hardware;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Cosmos.Kernel.New.Partitioning {
|
||||
public static class MBT {
|
||||
private class MBTPartition: BlockDevice {
|
||||
private readonly BlockDevice mBackend;
|
||||
private readonly ulong mBlockStart;
|
||||
private readonly ulong mBlockCount;
|
||||
private readonly string mName;
|
||||
public MBTPartition(BlockDevice aBackend, ulong aBlockStart, ulong aBlockCount, string aName) {
|
||||
mBlockStart = aBlockStart;
|
||||
mBlockCount = aBlockCount;
|
||||
mBackend = aBackend;
|
||||
mName = aName;
|
||||
}
|
||||
|
||||
public override uint BlockSize {
|
||||
get {
|
||||
return mBackend.BlockSize;
|
||||
}
|
||||
}
|
||||
|
||||
public override ulong BlockCount {
|
||||
get {
|
||||
return mBlockCount;
|
||||
}
|
||||
}
|
||||
|
||||
private ulong GetActualBlock(ulong aBlock) {
|
||||
return aBlock;
|
||||
}
|
||||
|
||||
public override byte[] ReadBlock(ulong aBlock) {
|
||||
return mBackend.ReadBlock(GetActualBlock(aBlock));
|
||||
}
|
||||
|
||||
public override void WriteBlock(ulong aBlock, byte[] aContents) {
|
||||
mBackend.WriteBlock(GetActualBlock(aBlock), aContents);
|
||||
}
|
||||
|
||||
public override string Name {
|
||||
get {
|
||||
return mName;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void Initialize() {
|
||||
DebugUtil.SendMessage("MBT", "Initializing");
|
||||
DebugUtil.SendNumber("MBT", "DeviceCount", (uint)Device.Devices.Count, 32);
|
||||
for (int i = 0; i < Device.Devices.Count; i++) {
|
||||
var xDevice = Device.Devices[i];
|
||||
var xBlockDev = xDevice as BlockDevice;
|
||||
if (xBlockDev == null) {
|
||||
continue;
|
||||
}
|
||||
DebugUtil.SendMessage("MBT", "Found Device");
|
||||
var xBlockContents = xBlockDev.ReadBlock(0);
|
||||
// detecting whether MBT or not
|
||||
DebugUtil.SendNumber("MBT", "xBlockDev.BlockSize", xBlockDev.BlockSize, 32);
|
||||
DebugUtil.SendDoubleNumber("MBT", "Last bytes of block", xBlockContents[510], 8, xBlockContents[511], 8);
|
||||
if (!(xBlockContents[xBlockDev.BlockSize - 2] == 0x55 && xBlockContents[xBlockDev.BlockSize - 1] == 0xAA)) {
|
||||
DebugUtil.SendMessage("MBT", "Does not contain MBR");
|
||||
Hardware.DebugUtil.SendATA_BlockReceived(255, 255, 0, xBlockContents);
|
||||
continue;
|
||||
}
|
||||
int xContentsIndex = 0;
|
||||
xContentsIndex = 0x1BE;
|
||||
for (byte j = 0; j < 4; j++) {
|
||||
DebugUtil.SendNumber("MBT", "Partition Status", xBlockContents[xContentsIndex], 8);
|
||||
if (!(xBlockContents[xContentsIndex] == 0x80 || xBlockContents[xContentsIndex] == 0)) {
|
||||
xContentsIndex += 16;
|
||||
continue;
|
||||
}
|
||||
xContentsIndex += 8;
|
||||
uint xStart = BitConverter.ToUInt32(xBlockContents, xContentsIndex);
|
||||
xContentsIndex += 4;
|
||||
uint xLength = BitConverter.ToUInt32(xBlockContents, xContentsIndex);
|
||||
xContentsIndex += 4;
|
||||
if (xStart > 0 && xLength > 0) {
|
||||
DebugUtil.SendDoubleNumber("MBT", "Entry Found. Start, Length in blocks", xStart, 32, xLength, 32);
|
||||
xStart += 2;
|
||||
Console.WriteLine("Add Partition to Device list");
|
||||
Device.Add(new MBTPartition(xBlockDev, xStart, xLength, "Partition"));
|
||||
DebugUtil.SendMessage("MBT", "FoundPartition");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue