Skip to content

Commit

Permalink
Merge pull request #2783 from CosmosOS/fix/fat32Read
Browse files Browse the repository at this point in the history
FAT32 Read fix
  • Loading branch information
valentinbreiz authored Sep 27, 2023
2 parents 1f73caf + d8d292e commit 64db699
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
Binary file added Build/VMWare/Workstation/FilesystemTest.vmdk
Binary file not shown.
2 changes: 1 addition & 1 deletion Tests/Cosmos.TestRunner.Core/Engine.Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private bool ExecuteKernel(
else
{
xHarddiskPath = Path.Combine(workingDirectory, "Harddisk.vmdk");
var xOriginalHarddiskPath = Path.Combine(GetCosmosUserkitFolder(), "Build", "VMware", "Workstation", "Filesystem.vmdk");
var xOriginalHarddiskPath = Path.Combine(GetCosmosUserkitFolder(), "Build", "VMware", "Workstation", "FilesystemTest.vmdk");
File.Copy(xOriginalHarddiskPath, xHarddiskPath);
}

Expand Down
16 changes: 16 additions & 0 deletions Tests/Kernels/Cosmos.Kernel.Tests.Fat/System.IO/FileTest.cs

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// #define COSMOSDEBUG

// #define COSMOSDEBUG

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -145,6 +146,7 @@ public uint[] GetFatChain(uint aFirstEntry, long aDataSize = 0)
}
}

/*
string xChain = "";
for (int i = 0; i < xReturn.Length; i++)
{
Expand All @@ -156,6 +158,7 @@ public uint[] GetFatChain(uint aFirstEntry, long aDataSize = 0)
}
Global.Debugger.SendInternal("Fat xChain:");
Global.Debugger.SendInternal(xChain);
*/

SetFatEntry(xCurrentEntry, FatEntryEofValue());

Expand Down Expand Up @@ -385,7 +388,8 @@ internal void GetFatEntry(uint aEntryNumber, out uint aValue)
break;

case FatTypeEnum.Fat32:
aValue = BitConverter.ToUInt32(xData, (int)xEntryOffset) & 0x0FFFFFFF;
int localOffset = (int)(xEntryOffset % mFileSystem.BytesPerSector);
aValue = BitConverter.ToUInt32(xData, localOffset) & 0x0FFFFFFF;
break;

default:
Expand Down Expand Up @@ -414,23 +418,23 @@ internal void SetFatEntry(ulong aEntryNumber, ulong aValue)
ulong xEntryOffset = aEntryNumber * xEntrySize;

ulong xSector = xEntryOffset / mFileSystem.BytesPerSector;
//ulong xSectorOffset = (xSector * mFileSystem.BytesPerSector) - xEntryOffset;
int localOffset = (int)(xEntryOffset % mFileSystem.BytesPerSector);

byte[] xData;
ReadFatSector(xSector, out xData);

switch (mFileSystem.mFatType)
{
case FatTypeEnum.Fat12:
xData.SetUInt16(xEntryOffset, (ushort)aValue);
xData.SetUInt16((ulong)localOffset, (ushort)aValue);
break;

case FatTypeEnum.Fat16:
xData.SetUInt16(xEntryOffset, (ushort)aValue);
xData.SetUInt16((ulong)localOffset, (ushort)aValue);
break;

case FatTypeEnum.Fat32:
xData.SetUInt32(xEntryOffset, (uint)aValue);
xData.SetUInt32((ulong)localOffset, (uint)aValue);
break;

default:
Expand Down

0 comments on commit 64db699

Please sign in to comment.