mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-06 08:12:14 +00:00
Only clear the next entry
Fix incorrect amount written
This commit is contained in:
parent
c9dfec1740
commit
f97f641bb4
2 changed files with 8 additions and 14 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
//#define COSMOSDEBUG
|
#define COSMOSDEBUG
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -826,25 +826,20 @@ namespace Cosmos.System.FileSystem.FAT
|
||||||
/// <param name="aOffset">unused.</param>
|
/// <param name="aOffset">unused.</param>
|
||||||
/// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception>
|
/// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception>
|
||||||
/// <exception cref="Exception">Thrown when data size invalid.</exception>
|
/// <exception cref="Exception">Thrown when data size invalid.</exception>
|
||||||
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("-- FatFileSystem.Read --");
|
||||||
Global.mFileSystemDebugger.SendInternal("aCluster: " + aCluster);
|
|
||||||
|
|
||||||
if (aSize == 0)
|
|
||||||
{
|
|
||||||
aSize = BytesPerCluster;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mFatType == FatTypeEnum.Fat32)
|
if (mFatType == FatTypeEnum.Fat32)
|
||||||
{
|
{
|
||||||
aData = NewBlockArray();
|
aData = NewBlockArray();
|
||||||
long xSector = DataSector + (aCluster - RootCluster) * SectorsPerCluster;
|
long xSector = DataSector + (aCluster - RootCluster) * SectorsPerCluster;
|
||||||
Global.mFileSystemDebugger.SendInternal("aSector: " + aCluster);
|
Global.mFileSystemDebugger.SendInternal("xSector: " + aCluster);
|
||||||
Device.ReadBlock((ulong)xSector, SectorsPerCluster, ref aData);
|
Device.ReadBlock((ulong)xSector, SectorsPerCluster, ref aData);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Global.mFileSystemDebugger.SendInternal("aCluster: " + aCluster);
|
||||||
aData = Device.NewBlockArray(1);
|
aData = Device.NewBlockArray(1);
|
||||||
Device.ReadBlock((ulong)aCluster, RootSectorCount, ref aData);
|
Device.ReadBlock((ulong)aCluster, RootSectorCount, ref aData);
|
||||||
}
|
}
|
||||||
|
|
@ -894,9 +889,10 @@ namespace Cosmos.System.FileSystem.FAT
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] xData;
|
byte[] xData;
|
||||||
|
|
||||||
Read(aCluster, out xData);
|
Read(aCluster, out xData);
|
||||||
Array.Copy(aData, 0, xData, aOffset, aData.Length);
|
|
||||||
|
|
||||||
|
Array.Copy(aData, 0, xData, aOffset, aSize);
|
||||||
|
|
||||||
if (mFatType == FatTypeEnum.Fat32)
|
if (mFatType == FatTypeEnum.Fat32)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -452,9 +452,7 @@ namespace Cosmos.System.FileSystem.FAT.Listing
|
||||||
|
|
||||||
xNewEntry.AllocateDirectoryEntry(xShortName);
|
xNewEntry.AllocateDirectoryEntry(xShortName);
|
||||||
|
|
||||||
// We need to clear the cluster in case there is some data left over (currently happens when we reformat the fs)
|
((FatFileSystem)mFileSystem).Write(xFirstCluster, new byte[32], 32, 0); //Clear the next entry to ensure that it is detected as end of directory
|
||||||
var bytesPerCluster = ((FatFileSystem)mFileSystem).BytesPerCluster;
|
|
||||||
((FatFileSystem)mFileSystem).Write(xFirstCluster, new byte[bytesPerCluster], bytesPerCluster, 0);
|
|
||||||
|
|
||||||
return xNewEntry;
|
return xNewEntry;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue