This commit is contained in:
kudzu_cp 2011-02-24 07:02:28 +00:00
parent 9c4fb010ff
commit b751e45aaf
7 changed files with 46 additions and 14 deletions

View file

@ -24,5 +24,14 @@ namespace Cosmos.Common.Extensions {
return (UInt32)(n[aPos + 3] << 24 | n[aPos + 2] << 16 | n[aPos + 1] << 8 | n[aPos]);
}
static public string GetAsciiString(this byte[] n, int aStart, int aSize) {
var xChars = new char[aSize];
for (int i = aStart; i < aStart + aSize; i++) {
xChars[i] = (char)n[i];
}
return new string(xChars);
}
}
}

View file

@ -47,7 +47,6 @@ namespace Cosmos.System.Filesystem {
RootEntryCount = xBPB.ToUInt16(17);
TotalSectorCount = xBPB.ToUInt16(19);
var i = TotalSectorCount;
if (TotalSectorCount == 0) {
TotalSectorCount = xBPB.ToUInt32(32);
}
@ -96,7 +95,29 @@ namespace Cosmos.System.Filesystem {
public List<string> GetDir() {
var xResult = new List<string>();
var xData = NewClusterArray();
byte[] xData;
if (FatType == FatTypeEnum.Fat32) {
xData = NewClusterArray();
ReadCluster(RootCluster, xData);
} else {
xData = mDevice.NewBlockArray(RootSectorCount);
mDevice.ReadBlock(RootSector, RootSectorCount, xData);
}
for (int i = 0; i < xData.Length; i = i + 32) {
byte xStatus = xData[i];
if (xStatus == 0xE5) {
// 0xE5 = Empty slot
} else if (xStatus == 0x00) {
// Empty slot, and no more entries after this
break;
} else if (xStatus == 0x05) {
// Japanese characters - We dont handle this
} else {
string xName = xData.GetAsciiString(i, 11);
int x = 4;
}
}
return xResult;
}

View file

@ -202,8 +202,8 @@ namespace Cosmos.Hardware.BlockDevice {
}
public override void ReadBlock(UInt32 aBlockNo, UInt32 aBlockCount, byte[] aData) {
CheckDataSize(aData, 1);
SelectSector(aBlockNo, 1);
CheckDataSize(aData, aBlockCount);
SelectSector(aBlockNo, aBlockCount);
SendCmd(Cmd.ReadPio);
IO.Data.Read16(aData);
}
@ -224,9 +224,5 @@ namespace Cosmos.Hardware.BlockDevice {
SendCmd(Cmd.CacheFlush);
}
public void Test() {
}
}
}

View file

@ -14,7 +14,7 @@ namespace Cosmos.Hardware.BlockDevice {
// TODO: Need to protect this from changes except by Hardware ring
static public List<BlockDevice> Devices = new List<BlockDevice>();
public byte[] NewBlockArray(int aBlockCount) {
public byte[] NewBlockArray(UInt32 aBlockCount) {
return new byte[aBlockCount * mBlockSize];
}
@ -36,8 +36,12 @@ namespace Cosmos.Hardware.BlockDevice {
public abstract void WriteBlock(UInt32 aBlockNo, UInt32 aBlockCount, byte[] aData);
protected void CheckDataSize(byte[] aData, UInt32 aBlockCount) {
var xBlockSize = mBlockSize;
var xDataLength = aData.Length;
var xDataSize = aBlockCount * mBlockSize;
if (aData.Length != aBlockCount * mBlockSize) {
throw new Exception("Invalid data size.");
//TODO: uint comparison to int is broken - so we comment this out for now
//throw new Exception("Invalid data size.");
}
}

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmos.Common.Extensions;
namespace Cosmos.Hardware.BlockDevice {
// Its not a BlockDevice, but its related to "fixed" devices
@ -36,10 +37,8 @@ namespace Cosmos.Hardware.BlockDevice {
byte xSystemID = aMBR[aLoc + 4];
// SystemID = 0 means no partition
if (xSystemID != 0) {
// TODO - Make Bitconvertor work and change all these
// TODO - Make a note about BitConvertor - change to high speed ASM plugs / cosmos calls
UInt32 xStartSector = (UInt32)(aMBR[aLoc + 11] << 24 | aMBR[aLoc + 10] << 16 | aMBR[aLoc + 9] << 8 | aMBR[aLoc + 8]);
UInt32 xSectorCount = (UInt32)(aMBR[aLoc + 15] << 24 | aMBR[aLoc + 14] << 16 | aMBR[aLoc + 13] << 8 | aMBR[aLoc + 12]);
UInt32 xStartSector = aMBR.ToUInt32(aLoc + 8);
UInt32 xSectorCount = aMBR.ToUInt32(aLoc + 12);
var xPartInfo = new PartInfo(xSystemID, xStartSector, xSectorCount);
Partitions.Add(xPartInfo);

View file

@ -14,6 +14,8 @@ namespace Cosmos.Hardware.BlockDevice {
mHost = aHost;
mStartingSector = aStartingSector;
mBlockCount = aSectorCount;
mBlockSize = mHost.BlockSize;
}
public override void ReadBlock(UInt32 aBlockNo, UInt32 aBlockCount, byte[] aData) {

View file

@ -48,6 +48,7 @@ namespace BreakpointsKernel {
Console.WriteLine("Size: " + xATA.BlockCount * xATA.BlockSize / 1024 / 1024 + " MB");
var xFS = new Cosmos.System.Filesystem.FAT(BlockDevice.Devices[1]);
xFS.GetDir();
//var xWrite = new byte[512];
//for (int i = 0; i < 512; i++) {