File system fixes and code cleanup.

This commit is contained in:
José Pedro 2018-07-21 21:06:18 +01:00
parent daa40d38e2
commit 4a801eb167
No known key found for this signature in database
GPG key ID: B8247B9301707B83
5 changed files with 42 additions and 34 deletions

View file

@ -410,7 +410,7 @@ namespace Cosmos.System.FileSystem
if (fs.IsType(mPartitions[i])) if (fs.IsType(mPartitions[i]))
{ {
Global.mFileSystemDebugger.SendInternal($"Partion {i} has a {fs.Name} filesystem"); 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));
} }
} }

View file

@ -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() public override void DisplayFileSystemInfo()
{ {
global::System.Console.WriteLine("-------File System--------"); global::System.Console.WriteLine("-------File System--------");

View file

@ -155,7 +155,10 @@ namespace Cosmos.System.FileSystem.FAT.Listing
string xShortName = aName; string xShortName = aName;
uint[] xDirectoryEntriesToAllocate = null; 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 x1 = aEntryType == DirectoryEntryTypeEnum.File;
var x2 = aName.Contains("."); var x2 = aName.Contains(".");
var x3 = x2 ? aName.Substring(0, aName.LastIndexOf('.')).Contains(".") : false; var x3 = x2 ? aName.Substring(0, aName.LastIndexOf('.')).Contains(".") : false;

View file

@ -1,14 +1,27 @@
using Cosmos.HAL.BlockDevice; using System;
using Cosmos.HAL.BlockDevice;
using Cosmos.System.FileSystem.FAT; using Cosmos.System.FileSystem.FAT;
using System;
using System.Collections.Generic;
using System.Text;
namespace Cosmos.System.FileSystem namespace Cosmos.System.FileSystem
{ {
public class FatFileSystemFactory : FileSystemFactory 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;
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FatFileSystem"/> class. /// Initializes a new instance of the <see cref="FatFileSystem"/> class.
@ -17,7 +30,5 @@ namespace Cosmos.System.FileSystem
/// <param name="aRootPath">The root path.</param> /// <param name="aRootPath">The root path.</param>
/// <exception cref="Exception">FAT signature not found.</exception> /// <exception cref="Exception">FAT signature not found.</exception>
public override FileSystem Create(Partition aDevice, string aRootPath, long aSize) => new FatFileSystem(aDevice, aRootPath, aSize); public override FileSystem Create(Partition aDevice, string aRootPath, long aSize) => new FatFileSystem(aDevice, aRootPath, aSize);
public override bool IsType(Partition aDevice) => FatFileSystem.IsDeviceFat(aDevice);
} }
} }

View file

@ -1,16 +1,27 @@
using Cosmos.HAL.BlockDevice; using Cosmos.HAL.BlockDevice;
using System;
using System.Collections.Generic;
using System.Text;
namespace Cosmos.System.FileSystem namespace Cosmos.System.FileSystem
{ {
public class FileSystemFactory public abstract class FileSystemFactory
{ {
public virtual string Name { get; private set; } /// <summary>
/// The name of the file system.
/// </summary>
public abstract string Name { get; }
public virtual FileSystem Create(Partition aDevice, string aRootPath, long aSize) => null; /// <summary>
/// Checks if the file system can handle the partition.
public virtual bool IsType(Partition aDevice) => false; /// </summary>
/// <param name="aDevice">The partition.</param>
/// <returns>Returns true if the file system can handle the partition, false otherwise.</returns>
public abstract bool IsType(Partition aDevice);
/// <summary>
/// Creates a new <see cref="FileSystem"/> object for the given partition, root path, and size.
/// </summary>
/// <param name="aDevice">The partition.</param>
/// <param name="aRootPath">The root path.</param>
/// <param name="aSize">The size, in MB.</param>
/// <returns></returns>
public abstract FileSystem Create(Partition aDevice, string aRootPath, long aSize);
} }
} }