This commit is contained in:
mterwoord_cp 2008-01-01 13:36:51 +00:00
parent 06d2462270
commit 47a16c1ea0
3 changed files with 111 additions and 16 deletions

View file

@ -26,29 +26,15 @@ namespace Cosmos.Kernel {
Console.WriteLine("Done");
Console.Write("Initializing Debug Utility...");
Hardware.DebugUtil.Initialize();
//System.Diagnostics.Debugger.Break();
Hardware.DebugUtil.SendMessage("Logging", "Initialized!");
//System.Diagnostics.Debugger.Break();
Console.WriteLine("Done");
Console.Write("Configuring PIT...");
Hardware.PIT.Initialize(Tick);
Console.WriteLine("Done");
//System.Diagnostics.Debugger.Break();
Console.Write("Creating IDT...");
Hardware.CPU.CreateIDT();
Console.WriteLine("Done");
TestATA();
MemoryStream xMS = new MemoryStream();
xMS.WriteByte(1);
xMS.WriteByte(2);
xMS.WriteByte(3);
xMS.Position = 1;
//int xResult = xMS.ReadByte();
//if (xResult == 2) {
// Console.WriteLine("MemoryStream works");
//} else {
// Console.WriteLine("MemoryStream does not work!");
//}
}
public static uint TickCount {
@ -67,7 +53,6 @@ namespace Cosmos.Kernel {
static unsafe void TestATA() {
Hardware.Storage.ATA.Initialize(Sleep);
Debugger.Break();
Hardware.Storage.ATA xDrive = new Cosmos.Hardware.Storage.ATA(0, 0);
byte* xBuffer = (byte*)Heap.MemAlloc(512);
if (xDrive.ReadBlock(1, xBuffer)) {
@ -98,6 +83,23 @@ namespace Cosmos.Kernel {
Console.Write("Contents: '");
Console.Write(s);
Console.WriteLine("'");
Console.Write("Contents of root (");
string[] xItems = xExt2.GetDirectoryEntries(new string[0]);
Hardware.Storage.ATAOld.WriteNumber((uint)xItems.Length, 8);
Console.WriteLine(" items):");
if (xItems == null) {
Console.WriteLine(" Result array is null!");
}
for (int i = 0; i < xItems.Length; i++) {
Console.Write(" - ");
Console.Write(xItems[i]);
Console.Write(" [");
Hardware.Storage.ATAOld.WriteNumber((uint)xItems[i][0], 16);
Console.Write("] (Length = ");
System.Diagnostics.Debugger.Break();
Hardware.Storage.ATAOld.WriteNumber((uint)xItems[i].Length, 8);
Console.WriteLine(")");
}
}
}
}

View file

@ -1,5 +1,6 @@
using System;
using Cosmos.Hardware.Storage;
using System.Collections.Generic;
namespace Cosmos.Kernel.FileSystem {
public unsafe partial class Ext2 {
@ -10,6 +11,7 @@ namespace Cosmos.Kernel.FileSystem {
private uint mGroupDescriptorsPerBlock;
private GroupDescriptor*[] mGroupDescriptors;
public const ushort EXT2_ROOT_INO = 0x02;
public Ext2(Storage aBackend) {
mBackend = aBackend;
@ -316,6 +318,96 @@ namespace Cosmos.Kernel.FileSystem {
return null;
}
public string[] GetDirectoryEntries(string[] aPath) {
List<string> xResult = new List<string>(32);
ushort* xBuffer = (ushort*)Heap.MemAlloc(mBackend.BlockSize);
byte* xExt2BlockBuffer = (byte*)Heap.MemAlloc(mBlockSize);
INode xCurrentINode;
if (!ReadINode(EXT2_ROOT_INO, out xCurrentINode)) {
Heap.MemFree((uint)xBuffer);
Heap.MemFree((uint)xExt2BlockBuffer);
return null;
}
bool xCurrentINodeChanged = true;
uint xInspectedINodeCount = 0;
for (int i = 0; i < aPath.Length; i++) {
Console.Write("ReadFile, Iteration ");
ATAOld.WriteNumber((uint)i, 8);
Console.WriteLine("");
if (!xCurrentINodeChanged) {
Console.WriteLine("Terminating for loop, CurrentINode didn't change");
Heap.MemFree((uint)xBuffer);
Heap.MemFree((uint)xExt2BlockBuffer);
return null;
}
xCurrentINodeChanged = false;
if (!ReadINodeContents(&xCurrentINode, 0, xExt2BlockBuffer)) {
Heap.MemFree((uint)xBuffer);
Heap.MemFree((uint)xExt2BlockBuffer);
return null;
}
DirectoryEntry* xEntryPtr = (DirectoryEntry*)xExt2BlockBuffer;
uint xTotalSize = mBlockSize;
while (xTotalSize != 0) {
DebugUtil.SendExt2_DirectoryEntry(xEntryPtr);
uint xPtrAddress = (uint)xEntryPtr;
char[] xName = new char[xEntryPtr->NameLength];
byte* xNamePtr = &xEntryPtr->FirstNameChar;
for (int c = 0; c < xName.Length; c++) {
xName[c] = (char)xNamePtr[c];
}
xInspectedINodeCount++;
if (EqualsName(aPath[i], xName)) {
if (!ReadINode(xEntryPtr->INodeNumber, out xCurrentINode)) {
Heap.MemFree((uint)xBuffer);
Heap.MemFree((uint)xExt2BlockBuffer);
return null;
}
xCurrentINodeChanged = true;
xTotalSize = 0;
continue;
}
xPtrAddress += xEntryPtr->RecordLength;
xTotalSize -= xEntryPtr->RecordLength;
xEntryPtr = (DirectoryEntry*)xPtrAddress;
}
}
if (xCurrentINodeChanged) {
DebugUtil.SendMessage("Ext2", "ReadFile, for loop exited with an inode change");
} else {
DebugUtil.SendMessage("Ext2", "ReadFile, for loop exited without an inode change");
}
if ((xCurrentINode.Mode & INodeModeEnum.Directory) == 0) {
Console.WriteLine("Ext2|GetDirectoryEntries, No directory after for loop");
return null;
}
if (!ReadINodeContents(&xCurrentINode, 0, xExt2BlockBuffer)) {
Heap.MemFree((uint)xBuffer);
Heap.MemFree((uint)xExt2BlockBuffer);
return null;
}
DirectoryEntry* xEntry = (DirectoryEntry*)xExt2BlockBuffer;
uint xSize = mBlockSize;
DebugUtil.SendMessage("Ext2", "GetDirectoryEntries");
while (xSize != 0) {
DebugUtil.SendExt2_DirectoryEntry(xEntry);
uint xPtrAddress = (uint)xEntry;
char[] xName = new char[xEntry->NameLength];
byte* xNamePtr = &xEntry->FirstNameChar;
for (int c = 0; c < xName.Length; c++) {
byte b= xNamePtr[c];
xName[c] = (char)b;
}
xResult.Add(new String(xName));
xPtrAddress += xEntry->RecordLength;
xSize -= xEntry->RecordLength;
xEntry = (DirectoryEntry*)xPtrAddress;
}
Heap.MemFree((uint)xBuffer);
Heap.MemFree((uint)xExt2BlockBuffer);
return xResult.ToArray();
}
private static bool EqualsName(string a1, char[] a2) {
if (a1 == null || a2 == null) {
return false;

View file

@ -37,7 +37,8 @@ namespace Indy.IL2CPU.IL.X86 {
xDataName = aAssembler.GetIdentifier("StringLiteral");
StringBuilder xRefByteArray = new StringBuilder();
xRefByteArray.Append("0x" + ((uint)Engine.RegisterType(Engine.GetTypeDefinition("mscorlib", "System.String"))).ToString("X"));
xRefByteArray.Append(",0x" + ((uint)InstanceTypeEnum.StaticEmbeddedObject).ToString("X") + ",0,");
xRefByteArray.Append(",0x" + ((uint)InstanceTypeEnum.StaticEmbeddedObject).ToString("X") + ",");
xRefByteArray.Append("0x" + (1).ToString("X") + ",");
xRefByteArray.Append(xDataName + "__Contents,");
xRefByteArray.Append("0,0,0");
aAssembler.DataMembers.Add(new DataMember(xDataName, "dd", xRefByteArray.ToString()));