From f97f641bb446f21ac663efa308df3e1e72b6fccf Mon Sep 17 00:00:00 2001 From: Quajak Date: Thu, 29 Oct 2020 21:36:13 +0100 Subject: [PATCH] Only clear the next entry Fix incorrect amount written --- .../FileSystem/FAT/FatFileSystem.cs | 18 +++++++----------- .../FileSystem/FAT/Listing/FatDiretoryEntry.cs | 4 +--- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs b/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs index aff2aacea..b18dfd66d 100644 --- a/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs +++ b/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs @@ -1,4 +1,4 @@ -//#define COSMOSDEBUG +#define COSMOSDEBUG using System; using System.Collections.Generic; @@ -826,25 +826,20 @@ namespace Cosmos.System.FileSystem.FAT /// unused. /// Thrown when data lenght is greater then Int32.MaxValue. /// Thrown when data size invalid. - internal void Read(long aCluster, out byte[] aData, long aSize = 0, long aOffset = 0) + internal void Read(long aCluster, out byte[] aData) { Global.mFileSystemDebugger.SendInternal("-- FatFileSystem.Read --"); - Global.mFileSystemDebugger.SendInternal("aCluster: " + aCluster); - - if (aSize == 0) - { - aSize = BytesPerCluster; - } if (mFatType == FatTypeEnum.Fat32) { aData = NewBlockArray(); long xSector = DataSector + (aCluster - RootCluster) * SectorsPerCluster; - Global.mFileSystemDebugger.SendInternal("aSector: " + aCluster); + Global.mFileSystemDebugger.SendInternal("xSector: " + aCluster); Device.ReadBlock((ulong)xSector, SectorsPerCluster, ref aData); } else { + Global.mFileSystemDebugger.SendInternal("aCluster: " + aCluster); aData = Device.NewBlockArray(1); Device.ReadBlock((ulong)aCluster, RootSectorCount, ref aData); } @@ -894,9 +889,10 @@ namespace Cosmos.System.FileSystem.FAT } byte[] xData; - Read(aCluster, out xData); - Array.Copy(aData, 0, xData, aOffset, aData.Length); + + + Array.Copy(aData, 0, xData, aOffset, aSize); if (mFatType == FatTypeEnum.Fat32) { diff --git a/source/Cosmos.System2/FileSystem/FAT/Listing/FatDiretoryEntry.cs b/source/Cosmos.System2/FileSystem/FAT/Listing/FatDiretoryEntry.cs index a54500796..07d937101 100644 --- a/source/Cosmos.System2/FileSystem/FAT/Listing/FatDiretoryEntry.cs +++ b/source/Cosmos.System2/FileSystem/FAT/Listing/FatDiretoryEntry.cs @@ -452,9 +452,7 @@ namespace Cosmos.System.FileSystem.FAT.Listing xNewEntry.AllocateDirectoryEntry(xShortName); - // We need to clear the cluster in case there is some data left over (currently happens when we reformat the fs) - var bytesPerCluster = ((FatFileSystem)mFileSystem).BytesPerCluster; - ((FatFileSystem)mFileSystem).Write(xFirstCluster, new byte[bytesPerCluster], bytesPerCluster, 0); + ((FatFileSystem)mFileSystem).Write(xFirstCluster, new byte[32], 32, 0); //Clear the next entry to ensure that it is detected as end of directory return xNewEntry; }