Skip to content

Commit

Permalink
Fixed Newobj for string with length parameter.
Browse files Browse the repository at this point in the history
Minor changes in debugging and FAT test messages.
Removed useless "if" in FAT, previously added by me.
  • Loading branch information
jp2masa committed Sep 29, 2016
1 parent 4b67c02 commit 2c3ae62
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private void TestDirectory()
mDebugger.Send("");

//
mDebugger.Send("Get files:");
mDebugger.Send("START TEST: Get files:");
var xFiles = Directory.GetFiles(@"0:\");
mDebugger.Send("Found " + xFiles.Length + " files.");
if (xFiles.Length > 0)
Expand All @@ -478,7 +478,7 @@ private void TestDirectory()
mDebugger.Send("");

//
mDebugger.Send("Get directories:");
mDebugger.Send("START TEST: Get directories:");
var xDirectories = Directory.GetDirectories(@"0:\");
mDebugger.Send("Found " + xDirectories.Length + " directories.");
if (xDirectories.Length > 0)
Expand All @@ -495,14 +495,14 @@ private void TestDirectory()
mDebugger.Send("");

//
mDebugger.Send("Directory exist check:");
mDebugger.Send("START TEST: Directory exist check:");
var xTest = Directory.Exists(@"0:\test");
Assert.IsTrue(xTest, "Folder does not exist!");
mDebugger.Send("END TEST");

mDebugger.Send("");

mDebugger.Send("START TEST");
mDebugger.Send("START TEST: Create Directory");
var xDirectory = Directory.CreateDirectory(@"0:\test2");
Assert.IsTrue(xDirectory != null, "Directory.CreateDirectory failed: Directory is null");
bool xExists = Directory.Exists(@"0:\test2");
Expand Down
3 changes: 1 addition & 2 deletions source/Cosmos.Common/Extensions/ByteConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,5 @@ static public string GetUtf16String(this byte[] n, UInt32 aStart, UInt32 aCharCo
}
return new string(xChars);
}

}
}
}
4 changes: 2 additions & 2 deletions source/Cosmos.IL2CPU/IL/Newobj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static void Assemble(Assembler.Assembler aAssembler, MethodInfo aMethod,
&& xParams[2].ParameterType == typeof(int))
{
xHasCalcSize = true;
XS.Set(EAX, ESP, sourceDisplacement: 4, sourceIsIndirect: true);
XS.Set(EAX, ESP, sourceIsIndirect: true);
XS.ShiftLeft(EAX, 1);
XS.Push(EAX);
}
Expand All @@ -153,7 +153,7 @@ public static void Assemble(Assembler.Assembler aAssembler, MethodInfo aMethod,
&& xParams[1].ParameterType == typeof(int))
{
xHasCalcSize = true;
XS.Set(EAX, ESP, sourceDisplacement: 4, sourceIsIndirect: true);
XS.Set(EAX, ESP, sourceIsIndirect: true);
XS.ShiftLeft(EAX, 1);
XS.Push(EAX);
}
Expand Down
8 changes: 7 additions & 1 deletion source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ public static void Ctor(
Global.mFileSystemDebugger.SendInternal(aPath);

aStorage = VFSManager.GetDirectory(aPath);

if (aStorage == null)
{
throw new NullReferenceException("Failed to create DirectoryInfo: Directory '" + aPath + "' doesn't exist");
}

aFullPath = aStorage.mFullPath;
aName = aStorage.mName;
}

public static string get_Name(DirectoryInfo aThis)
{
Global.mFileSystemDebugger.SendInternal($"DirectoryInfo.get_Name : Nane = {aThis}");
Global.mFileSystemDebugger.SendInternal($"DirectoryInfo.get_Name : Name = {aThis}");
return aThis.ToString();
}

Expand Down
2 changes: 2 additions & 0 deletions source/Cosmos.System/FileSystem/CosmosVFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public override DirectoryEntry GetDirectory(string aPath)
}
catch (Exception)
{
Global.mFileSystemDebugger.SendInternal("CosmosVFS.GetDirectory - DoGetDirectoryEntry failed, returning null. aPath = " + aPath);
return null;
}
throw new Exception(aPath + " was found, but is not a directory.");
Expand All @@ -259,6 +260,7 @@ public override DirectoryEntry GetFile(string aPath)
}
catch (Exception)
{
Global.mFileSystemDebugger.SendInternal("CosmosVFS.GetFile - DoGetDirectoryEntry failed, returning null. aPath = " + aPath);
return null;
}
throw new Exception(aPath + " was found, but is not a file.");
Expand Down
35 changes: 27 additions & 8 deletions source/Cosmos.System/FileSystem/FAT/Listing/FatDiretoryEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,19 @@ private void AllocateDirectoryEntry()
}

string xNameString = new string(xName);

SetDirectoryEntryMetadataValue(FatDirectoryEntryMetadata.ShortName, xNameString);

if (mEntryType == DirectoryEntryTypeEnum.Directory)
{
SetDirectoryEntryMetadataValue(FatDirectoryEntryMetadata.Attributes, FatDirectoryEntryAttributeConsts.Directory);
}

SetDirectoryEntryMetadataValue(FatDirectoryEntryMetadata.FirstClusterHigh, (uint)(mFirstClusterNum >> 16));
SetDirectoryEntryMetadataValue(FatDirectoryEntryMetadata.FirstClusterLow, (uint)(mFirstClusterNum & 0xFFFF));

byte[] xData = GetDirectoryEntryData();

SetDirectoryEntryData(xData);
}

Expand All @@ -172,7 +177,9 @@ public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum
Global.mFileSystemDebugger.SendInternal(xEntryHeaderDataOffset);

var xNewEntry = new FatDirectoryEntry((FatFileSystem)mFileSystem, this, xFullPath, aName, 0, xFirstCluster, xEntryHeaderDataOffset, aType);

xNewEntry.AllocateDirectoryEntry();

return xNewEntry;
}
throw new ArgumentOutOfRangeException(nameof(aType), "Unknown directory entry type.");
Expand Down Expand Up @@ -205,33 +212,39 @@ public List<FatDirectoryEntry> ReadDirectoryContents()
if (xAttrib == FatDirectoryEntryAttributeConsts.LongName)
{
byte xType = xData[i + 12];

if (xStatus == FatDirectoryEntryAttributeConsts.UnusedOrDeletedEntry)
{
Global.mFileSystemDebugger.SendInternal("<DELETED> : Attrib = " + xAttrib + ", Status = " + xStatus);
continue;
}

if (xType == 0)
{
if ((xStatus & 0x40) > 0)
{
xLongName = "";
}

//TODO: Check LDIR_Ord for ordering and throw exception
// if entries are found out of order.
// Also save buffer and only copy name if a end Ord marker is found.
string xLongPart = xData.GetUtf16String(i + 1, 5);

// We have to check the length because 0xFFFF is a valid Unicode codepoint.
// So we only want to stop if the 0xFFFF is AFTER a 0x0000. We can determin
// this by also looking at the length. Since we short circuit the or, the length
// is rarely evaluated.
if (xData.ToUInt16(i + 14) != 0xFFFF || xLongPart.Length == 5)
{
xLongPart = xLongPart + xData.GetUtf16String(i + 14, 6);

if (xData.ToUInt16(i + 28) != 0xFFFF || xLongPart.Length == 11)
{
xLongPart = xLongPart + xData.GetUtf16String(i + 28, 2);
}
}

xLongName = xLongPart + xLongName;
xLongPart = null;
//TODO: LDIR_Chksum
Expand All @@ -240,11 +253,13 @@ public List<FatDirectoryEntry> ReadDirectoryContents()
else
{
xName = xLongName;

if (xStatus == 0x00)
{
Global.mFileSystemDebugger.SendInternal("<EOF> : Attrib = " + xAttrib + ", Status = " + xStatus);
break;
}

switch (xStatus)
{
case 0x05:
Expand All @@ -266,6 +281,7 @@ public List<FatDirectoryEntry> ReadDirectoryContents()

//If there are trailing periods
int nameIndex = xName.Length - 1;

if (xName[nameIndex] == '.')
{
//Search backwards till we find the first non-period character
Expand All @@ -279,13 +295,15 @@ public List<FatDirectoryEntry> ReadDirectoryContents()
//Substring to remove the periods
xName = xName.Substring(0, nameIndex + 1);
}

xLongName = "";
}
else
{
string xEntry = xData.GetAsciiString(i, 11);
xName = xEntry.Substring(0, 8).TrimEnd();
string xExt = xEntry.Substring(8, 3).TrimEnd();

if (xExt.Length > 0)
{
xName = xName + "." + xExt;
Expand All @@ -298,22 +316,21 @@ public List<FatDirectoryEntry> ReadDirectoryContents()
uint xFirstCluster = (uint)(xData.ToUInt16(i + 20) << 16 | xData.ToUInt16(i + 26));

int xTest = xAttrib & (FatDirectoryEntryAttributeConsts.Directory | FatDirectoryEntryAttributeConsts.VolumeID);
if (xStatus == FatDirectoryEntryAttributeConsts.UnusedOrDeletedEntry)
{
// deleted file
}
else if (xAttrib == FatDirectoryEntryAttributeConsts.LongName)

if (xAttrib == FatDirectoryEntryAttributeConsts.LongName)
{
// skip adding, as it's a LongFileName entry, meaning the next normal entry is the item with the name.
//Global.mFileSystemDebugger.SendInternal($"Entry was a Long FileName entry. Current LongName = '{xLongName}'");
}
else if (xTest == 0)
{
uint xSize = xData.ToUInt32(i + 28);

if (xSize == 0 && xName.Length == 0)
{
continue;
}

string xFullPath = Path.Combine(mFullPath, xName);
var xEntry = new FatDirectoryEntry(((FatFileSystem)mFileSystem), xParent, xFullPath, xName, xSize, xFirstCluster, i, DirectoryEntryTypeEnum.File);
xResult.Add(xEntry);
Expand Down Expand Up @@ -419,7 +436,7 @@ internal void SetDirectoryEntryMetadataValue(FatDirectoryEntryMetadata aEntryMet
uint offset = mEntryHeaderDataOffset + aEntryMetadata.DataOffset;
Array.Copy(xValue, 0, xData, offset, aEntryMetadata.DataLength);
((FatDirectoryEntry)mParent).SetDirectoryEntryData(xData);
}
}
}
else
{
Expand All @@ -445,7 +462,7 @@ internal void SetDirectoryEntryMetadataValue(FatDirectoryEntryMetadata aEntryMet
Global.mFileSystemDebugger.SendInternal(offset);
Array.Copy(xValue, 0, xData, offset, aEntryMetadata.DataLength);
((FatDirectoryEntry)mParent).SetDirectoryEntryData(xData);
}
}
}
else
{
Expand All @@ -464,10 +481,12 @@ internal void SetDirectoryEntryMetadataValue(FatDirectoryEntryMetadata aEntryMet
{
var xValue = new byte[aEntryMetadata.DataLength];
xValue = aValue.GetUtf8Bytes(0, aEntryMetadata.DataLength);

uint offset = mEntryHeaderDataOffset + aEntryMetadata.DataOffset;
Array.Copy(xValue, 0, xData, offset, aEntryMetadata.DataLength);

((FatDirectoryEntry)mParent).SetDirectoryEntryData(xData);
}
}
}
}
}

0 comments on commit 2c3ae62

Please sign in to comment.