diff --git a/source/Cosmos.System2/FileSystem/CosmosVFS.cs b/source/Cosmos.System2/FileSystem/CosmosVFS.cs index 602920f05..616cff276 100644 --- a/source/Cosmos.System2/FileSystem/CosmosVFS.cs +++ b/source/Cosmos.System2/FileSystem/CosmosVFS.cs @@ -410,7 +410,7 @@ namespace Cosmos.System.FileSystem if (fs.IsType(mPartitions[i])) { Global.mFileSystemDebugger.SendInternal($"Partion {i} has a {fs.Name} filesystem"); - mFileSystems.Add(new FatFileSystem(mPartitions[i], xRootPath, xSize)); + mFileSystems.Add(fs.Create(mPartitions[i], xRootPath, xSize)); } } diff --git a/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs b/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs index a5fc1c150..1e97c6066 100644 --- a/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs +++ b/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs @@ -543,23 +543,6 @@ namespace Cosmos.System.FileSystem.FAT } } - public static bool IsDeviceFat(Partition aDevice) - { - if (aDevice == null) - { - throw new ArgumentNullException(nameof(aDevice)); - } - - var xBPB = aDevice.NewBlockArray(1); - aDevice.ReadBlock(0UL, 1U, xBPB); - ushort xSig = BitConverter.ToUInt16(xBPB, 510); - if (xSig != 0xAA55) - { - return false; - } - return true; - } - public override void DisplayFileSystemInfo() { global::System.Console.WriteLine("-------File System--------"); diff --git a/source/Cosmos.System2/FileSystem/FAT/Listing/FatDiretoryEntry.cs b/source/Cosmos.System2/FileSystem/FAT/Listing/FatDiretoryEntry.cs index 53167ae0e..b45917abb 100644 --- a/source/Cosmos.System2/FileSystem/FAT/Listing/FatDiretoryEntry.cs +++ b/source/Cosmos.System2/FileSystem/FAT/Listing/FatDiretoryEntry.cs @@ -155,7 +155,10 @@ namespace Cosmos.System.FileSystem.FAT.Listing string xShortName = aName; uint[] xDirectoryEntriesToAllocate = null; - //Stack corruption, just delete everything from this until commented if when it's fixed + // Stack corruption, just delete everything from this until commented if when it's fixed + // + // https://github.com/CosmosOS/IL2CPU/issues/8 + // var x1 = aEntryType == DirectoryEntryTypeEnum.File; var x2 = aName.Contains("."); var x3 = x2 ? aName.Substring(0, aName.LastIndexOf('.')).Contains(".") : false; diff --git a/source/Cosmos.System2/FileSystem/FatFileSystemFactory.cs b/source/Cosmos.System2/FileSystem/FatFileSystemFactory.cs index 68c84fd2d..276b6bb53 100644 --- a/source/Cosmos.System2/FileSystem/FatFileSystemFactory.cs +++ b/source/Cosmos.System2/FileSystem/FatFileSystemFactory.cs @@ -1,14 +1,27 @@ -using Cosmos.HAL.BlockDevice; +using System; + +using Cosmos.HAL.BlockDevice; using Cosmos.System.FileSystem.FAT; -using System; -using System.Collections.Generic; -using System.Text; namespace Cosmos.System.FileSystem { public class FatFileSystemFactory : FileSystemFactory { - public override string Name { get => "FAT"; } + public override string Name => "FAT"; + + public override bool IsType(Partition aDevice) + { + if (aDevice == null) + { + throw new ArgumentNullException(nameof(aDevice)); + } + + var xBPB = aDevice.NewBlockArray(1); + aDevice.ReadBlock(0UL, 1U, xBPB); + + var xSig = BitConverter.ToUInt16(xBPB, 510); + return xSig == 0xAA55; + } /// /// Initializes a new instance of the class. @@ -17,7 +30,5 @@ namespace Cosmos.System.FileSystem /// The root path. /// FAT signature not found. public override FileSystem Create(Partition aDevice, string aRootPath, long aSize) => new FatFileSystem(aDevice, aRootPath, aSize); - - public override bool IsType(Partition aDevice) => FatFileSystem.IsDeviceFat(aDevice); } } diff --git a/source/Cosmos.System2/FileSystem/FileSystemFactory.cs b/source/Cosmos.System2/FileSystem/FileSystemFactory.cs index ce2471798..caae985df 100644 --- a/source/Cosmos.System2/FileSystem/FileSystemFactory.cs +++ b/source/Cosmos.System2/FileSystem/FileSystemFactory.cs @@ -1,16 +1,27 @@ using Cosmos.HAL.BlockDevice; -using System; -using System.Collections.Generic; -using System.Text; namespace Cosmos.System.FileSystem { - public class FileSystemFactory + public abstract class FileSystemFactory { - public virtual string Name { get; private set; } + /// + /// The name of the file system. + /// + public abstract string Name { get; } - public virtual FileSystem Create(Partition aDevice, string aRootPath, long aSize) => null; - - public virtual bool IsType(Partition aDevice) => false; + /// + /// Checks if the file system can handle the partition. + /// + /// The partition. + /// Returns true if the file system can handle the partition, false otherwise. + public abstract bool IsType(Partition aDevice); + /// + /// Creates a new object for the given partition, root path, and size. + /// + /// The partition. + /// The root path. + /// The size, in MB. + /// + public abstract FileSystem Create(Partition aDevice, string aRootPath, long aSize); } }