diff --git a/source2/Kernel/Common/Cosmos.Common.Extensions/ByteConvertor.cs b/source2/Kernel/Common/Cosmos.Common.Extensions/ByteConvertor.cs index f1025ed70..fed1cd022 100644 --- a/source2/Kernel/Common/Cosmos.Common.Extensions/ByteConvertor.cs +++ b/source2/Kernel/Common/Cosmos.Common.Extensions/ByteConvertor.cs @@ -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); + } + + } } diff --git a/source2/Kernel/System/Cosmos.System/Filesystem/FAT.cs b/source2/Kernel/System/Cosmos.System/Filesystem/FAT.cs index 9fb9834ab..478452bad 100644 --- a/source2/Kernel/System/Cosmos.System/Filesystem/FAT.cs +++ b/source2/Kernel/System/Cosmos.System/Filesystem/FAT.cs @@ -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 GetDir() { var xResult = new List(); - 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; } diff --git a/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/AtaPio.cs b/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/AtaPio.cs index 654108c6f..418fd7fba 100644 --- a/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/AtaPio.cs +++ b/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/AtaPio.cs @@ -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() { - - } - } } diff --git a/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/BlockDevice.cs b/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/BlockDevice.cs index f865a1a90..0034fa95e 100644 --- a/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/BlockDevice.cs +++ b/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/BlockDevice.cs @@ -14,7 +14,7 @@ namespace Cosmos.Hardware.BlockDevice { // TODO: Need to protect this from changes except by Hardware ring static public List Devices = new List(); - 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."); } } diff --git a/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/MBR.cs b/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/MBR.cs index 9a46d63ba..4d8c5e138 100644 --- a/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/MBR.cs +++ b/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/MBR.cs @@ -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); diff --git a/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/Partition.cs b/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/Partition.cs index c0e2a8ab2..d4c6509e4 100644 --- a/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/Partition.cs +++ b/source2/Kernel/System/Hardware/Cosmos.Hardware/BlockDevice/Partition.cs @@ -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) { diff --git a/source2/Users/Kudzu/Breakpoints/BreakpointsOS.cs b/source2/Users/Kudzu/Breakpoints/BreakpointsOS.cs index 2efa501d2..555842b52 100644 --- a/source2/Users/Kudzu/Breakpoints/BreakpointsOS.cs +++ b/source2/Users/Kudzu/Breakpoints/BreakpointsOS.cs @@ -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++) {