From 2c3ae6221d22566168c8ec6c2fc39de007c4baa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro?= Date: Thu, 29 Sep 2016 19:41:09 +0100 Subject: [PATCH 1/4] Fixed Newobj for string with length parameter. Minor changes in debugging and FAT test messages. Removed useless "if" in FAT, previously added by me. --- Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs | 8 ++--- .../Cosmos.Common/Extensions/ByteConverter.cs | 3 +- source/Cosmos.IL2CPU/IL/Newobj.cs | 4 +-- .../System/IO/DirectoryInfoImpl.cs | 8 ++++- source/Cosmos.System/FileSystem/CosmosVFS.cs | 2 ++ .../FAT/Listing/FatDiretoryEntry.cs | 35 ++++++++++++++----- 6 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs b/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs index 234634721..197c5b87f 100644 --- a/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs +++ b/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs @@ -461,7 +461,7 @@ namespace Cosmos.Kernel.Tests.Fat 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) @@ -478,7 +478,7 @@ namespace Cosmos.Kernel.Tests.Fat 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) @@ -495,14 +495,14 @@ namespace Cosmos.Kernel.Tests.Fat 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"); diff --git a/source/Cosmos.Common/Extensions/ByteConverter.cs b/source/Cosmos.Common/Extensions/ByteConverter.cs index 8b2ddb8cb..9cbfa47d4 100644 --- a/source/Cosmos.Common/Extensions/ByteConverter.cs +++ b/source/Cosmos.Common/Extensions/ByteConverter.cs @@ -106,6 +106,5 @@ namespace Cosmos.Common.Extensions } return new string(xChars); } - } -} \ No newline at end of file +} diff --git a/source/Cosmos.IL2CPU/IL/Newobj.cs b/source/Cosmos.IL2CPU/IL/Newobj.cs index c69219002..0299bc9ea 100644 --- a/source/Cosmos.IL2CPU/IL/Newobj.cs +++ b/source/Cosmos.IL2CPU/IL/Newobj.cs @@ -144,7 +144,7 @@ namespace Cosmos.IL2CPU.X86.IL && 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); } @@ -153,7 +153,7 @@ namespace Cosmos.IL2CPU.X86.IL && 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); } diff --git a/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs b/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs index ee2178781..2b710a7ef 100644 --- a/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs +++ b/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs @@ -36,13 +36,19 @@ namespace Cosmos.System.Plugs.System.IO 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(); } diff --git a/source/Cosmos.System/FileSystem/CosmosVFS.cs b/source/Cosmos.System/FileSystem/CosmosVFS.cs index 6c0995b04..c106bbd01 100644 --- a/source/Cosmos.System/FileSystem/CosmosVFS.cs +++ b/source/Cosmos.System/FileSystem/CosmosVFS.cs @@ -235,6 +235,7 @@ namespace Cosmos.System.FileSystem } 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."); @@ -259,6 +260,7 @@ namespace Cosmos.System.FileSystem } 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."); diff --git a/source/Cosmos.System/FileSystem/FAT/Listing/FatDiretoryEntry.cs b/source/Cosmos.System/FileSystem/FAT/Listing/FatDiretoryEntry.cs index e57b88c85..fcba40d97 100644 --- a/source/Cosmos.System/FileSystem/FAT/Listing/FatDiretoryEntry.cs +++ b/source/Cosmos.System/FileSystem/FAT/Listing/FatDiretoryEntry.cs @@ -140,14 +140,19 @@ namespace Cosmos.System.FileSystem.FAT.Listing } 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); } @@ -172,7 +177,9 @@ namespace Cosmos.System.FileSystem.FAT.Listing 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."); @@ -205,21 +212,25 @@ namespace Cosmos.System.FileSystem.FAT.Listing if (xAttrib == FatDirectoryEntryAttributeConsts.LongName) { byte xType = xData[i + 12]; + if (xStatus == FatDirectoryEntryAttributeConsts.UnusedOrDeletedEntry) { Global.mFileSystemDebugger.SendInternal(" : 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 @@ -227,11 +238,13 @@ namespace Cosmos.System.FileSystem.FAT.Listing 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 @@ -240,11 +253,13 @@ namespace Cosmos.System.FileSystem.FAT.Listing else { xName = xLongName; + if (xStatus == 0x00) { Global.mFileSystemDebugger.SendInternal(" : Attrib = " + xAttrib + ", Status = " + xStatus); break; } + switch (xStatus) { case 0x05: @@ -266,6 +281,7 @@ namespace Cosmos.System.FileSystem.FAT.Listing //If there are trailing periods int nameIndex = xName.Length - 1; + if (xName[nameIndex] == '.') { //Search backwards till we find the first non-period character @@ -279,6 +295,7 @@ namespace Cosmos.System.FileSystem.FAT.Listing //Substring to remove the periods xName = xName.Substring(0, nameIndex + 1); } + xLongName = ""; } else @@ -286,6 +303,7 @@ namespace Cosmos.System.FileSystem.FAT.Listing 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; @@ -298,11 +316,8 @@ namespace Cosmos.System.FileSystem.FAT.Listing 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}'"); @@ -310,10 +325,12 @@ namespace Cosmos.System.FileSystem.FAT.Listing 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); @@ -419,7 +436,7 @@ namespace Cosmos.System.FileSystem.FAT.Listing uint offset = mEntryHeaderDataOffset + aEntryMetadata.DataOffset; Array.Copy(xValue, 0, xData, offset, aEntryMetadata.DataLength); ((FatDirectoryEntry)mParent).SetDirectoryEntryData(xData); - } + } } else { @@ -445,7 +462,7 @@ namespace Cosmos.System.FileSystem.FAT.Listing Global.mFileSystemDebugger.SendInternal(offset); Array.Copy(xValue, 0, xData, offset, aEntryMetadata.DataLength); ((FatDirectoryEntry)mParent).SetDirectoryEntryData(xData); - } + } } else { @@ -464,10 +481,12 @@ namespace Cosmos.System.FileSystem.FAT.Listing { 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); - } + } } } } From a860b2373a01976b4a11571738f6d5a54f708840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro?= Date: Thu, 29 Sep 2016 19:41:09 +0100 Subject: [PATCH 2/4] Fixed Newobj for string with length parameter. Minor changes in debugging and FAT test messages. Removed useless "if" in FAT, previously added by me. --- Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs | 8 ++--- .../Cosmos.TestRunner.Core/TestKernelSets.cs | 2 +- .../Cosmos.Common/Extensions/ByteConverter.cs | 3 +- source/Cosmos.IL2CPU/IL/Newobj.cs | 4 +-- .../System/IO/DirectoryInfoImpl.cs | 8 ++++- source/Cosmos.System/FileSystem/CosmosVFS.cs | 2 ++ .../FAT/Listing/FatDiretoryEntry.cs | 35 ++++++++++++++----- 7 files changed, 44 insertions(+), 18 deletions(-) diff --git a/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs b/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs index 234634721..197c5b87f 100644 --- a/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs +++ b/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs @@ -461,7 +461,7 @@ namespace Cosmos.Kernel.Tests.Fat 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) @@ -478,7 +478,7 @@ namespace Cosmos.Kernel.Tests.Fat 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) @@ -495,14 +495,14 @@ namespace Cosmos.Kernel.Tests.Fat 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"); diff --git a/Tests/Cosmos.TestRunner.Core/TestKernelSets.cs b/Tests/Cosmos.TestRunner.Core/TestKernelSets.cs index 21542a73c..dbe4c971c 100644 --- a/Tests/Cosmos.TestRunner.Core/TestKernelSets.cs +++ b/Tests/Cosmos.TestRunner.Core/TestKernelSets.cs @@ -16,8 +16,8 @@ namespace Cosmos.TestRunner.Core yield return typeof(Cosmos.Compiler.Tests.LinqTests.Kernel); yield return typeof(Cosmos.Compiler.Tests.MethodTests.Kernel); yield return typeof(Cosmos.Kernel.Tests.IO.Kernel); + yield return typeof(Cosmos.Kernel.Tests.Fat.Kernel); - //yield return typeof(Cosmos.Kernel.Tests.Fat.Kernel); //yield return typeof(Cosmos.Compiler.Tests.Encryption.Kernel); //yield return typeof(FrotzKernel.Kernel); } diff --git a/source/Cosmos.Common/Extensions/ByteConverter.cs b/source/Cosmos.Common/Extensions/ByteConverter.cs index 8b2ddb8cb..9cbfa47d4 100644 --- a/source/Cosmos.Common/Extensions/ByteConverter.cs +++ b/source/Cosmos.Common/Extensions/ByteConverter.cs @@ -106,6 +106,5 @@ namespace Cosmos.Common.Extensions } return new string(xChars); } - } -} \ No newline at end of file +} diff --git a/source/Cosmos.IL2CPU/IL/Newobj.cs b/source/Cosmos.IL2CPU/IL/Newobj.cs index c69219002..0299bc9ea 100644 --- a/source/Cosmos.IL2CPU/IL/Newobj.cs +++ b/source/Cosmos.IL2CPU/IL/Newobj.cs @@ -144,7 +144,7 @@ namespace Cosmos.IL2CPU.X86.IL && 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); } @@ -153,7 +153,7 @@ namespace Cosmos.IL2CPU.X86.IL && 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); } diff --git a/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs b/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs index ee2178781..2b710a7ef 100644 --- a/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs +++ b/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs @@ -36,13 +36,19 @@ namespace Cosmos.System.Plugs.System.IO 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(); } diff --git a/source/Cosmos.System/FileSystem/CosmosVFS.cs b/source/Cosmos.System/FileSystem/CosmosVFS.cs index 6c0995b04..c106bbd01 100644 --- a/source/Cosmos.System/FileSystem/CosmosVFS.cs +++ b/source/Cosmos.System/FileSystem/CosmosVFS.cs @@ -235,6 +235,7 @@ namespace Cosmos.System.FileSystem } 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."); @@ -259,6 +260,7 @@ namespace Cosmos.System.FileSystem } 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."); diff --git a/source/Cosmos.System/FileSystem/FAT/Listing/FatDiretoryEntry.cs b/source/Cosmos.System/FileSystem/FAT/Listing/FatDiretoryEntry.cs index e57b88c85..fcba40d97 100644 --- a/source/Cosmos.System/FileSystem/FAT/Listing/FatDiretoryEntry.cs +++ b/source/Cosmos.System/FileSystem/FAT/Listing/FatDiretoryEntry.cs @@ -140,14 +140,19 @@ namespace Cosmos.System.FileSystem.FAT.Listing } 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); } @@ -172,7 +177,9 @@ namespace Cosmos.System.FileSystem.FAT.Listing 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."); @@ -205,21 +212,25 @@ namespace Cosmos.System.FileSystem.FAT.Listing if (xAttrib == FatDirectoryEntryAttributeConsts.LongName) { byte xType = xData[i + 12]; + if (xStatus == FatDirectoryEntryAttributeConsts.UnusedOrDeletedEntry) { Global.mFileSystemDebugger.SendInternal(" : 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 @@ -227,11 +238,13 @@ namespace Cosmos.System.FileSystem.FAT.Listing 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 @@ -240,11 +253,13 @@ namespace Cosmos.System.FileSystem.FAT.Listing else { xName = xLongName; + if (xStatus == 0x00) { Global.mFileSystemDebugger.SendInternal(" : Attrib = " + xAttrib + ", Status = " + xStatus); break; } + switch (xStatus) { case 0x05: @@ -266,6 +281,7 @@ namespace Cosmos.System.FileSystem.FAT.Listing //If there are trailing periods int nameIndex = xName.Length - 1; + if (xName[nameIndex] == '.') { //Search backwards till we find the first non-period character @@ -279,6 +295,7 @@ namespace Cosmos.System.FileSystem.FAT.Listing //Substring to remove the periods xName = xName.Substring(0, nameIndex + 1); } + xLongName = ""; } else @@ -286,6 +303,7 @@ namespace Cosmos.System.FileSystem.FAT.Listing 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; @@ -298,11 +316,8 @@ namespace Cosmos.System.FileSystem.FAT.Listing 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}'"); @@ -310,10 +325,12 @@ namespace Cosmos.System.FileSystem.FAT.Listing 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); @@ -419,7 +436,7 @@ namespace Cosmos.System.FileSystem.FAT.Listing uint offset = mEntryHeaderDataOffset + aEntryMetadata.DataOffset; Array.Copy(xValue, 0, xData, offset, aEntryMetadata.DataLength); ((FatDirectoryEntry)mParent).SetDirectoryEntryData(xData); - } + } } else { @@ -445,7 +462,7 @@ namespace Cosmos.System.FileSystem.FAT.Listing Global.mFileSystemDebugger.SendInternal(offset); Array.Copy(xValue, 0, xData, offset, aEntryMetadata.DataLength); ((FatDirectoryEntry)mParent).SetDirectoryEntryData(xData); - } + } } else { @@ -464,10 +481,12 @@ namespace Cosmos.System.FileSystem.FAT.Listing { 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); - } + } } } } From 0db57dc3b0982808903c7be1e9221028715879ff Mon Sep 17 00:00:00 2001 From: jp2masa Date: Thu, 29 Sep 2016 20:52:16 +0100 Subject: [PATCH 3/4] Update DirectoryInfoImpl.cs --- source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs b/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs index 2b710a7ef..38b64fab3 100644 --- a/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs +++ b/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs @@ -42,8 +42,8 @@ namespace Cosmos.System.Plugs.System.IO throw new NullReferenceException("Failed to create DirectoryInfo: Directory '" + aPath + "' doesn't exist"); } - aFullPath = aStorage.mFullPath; - aName = aStorage.mName; + aFullPath = aPath; + aName = Path.GetFileName(aPath); } public static string get_Name(DirectoryInfo aThis) From c21d7800741eeab8e2d51e2548be2ad5b74054a0 Mon Sep 17 00:00:00 2001 From: jp2masa Date: Thu, 29 Sep 2016 20:52:42 +0100 Subject: [PATCH 4/4] Update DirectoryInfoImpl.cs --- source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs b/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs index 38b64fab3..0d5fa424c 100644 --- a/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs +++ b/source/Cosmos.System.Plugs/System/IO/DirectoryInfoImpl.cs @@ -36,12 +36,6 @@ namespace Cosmos.System.Plugs.System.IO Global.mFileSystemDebugger.SendInternal(aPath); aStorage = VFSManager.GetDirectory(aPath); - - if (aStorage == null) - { - throw new NullReferenceException("Failed to create DirectoryInfo: Directory '" + aPath + "' doesn't exist"); - } - aFullPath = aPath; aName = Path.GetFileName(aPath); }