using System;
using Cosmos.HAL.BlockDevice;
using Cosmos.System.FileSystem.FAT;
namespace Cosmos.System.FileSystem
{
public class FatFileSystemFactory : FileSystemFactory
{
public override string Name => "FAT";
///
/// Checks if the file system can handle the partition.
///
/// The partition.
/// Returns true if the file system can handle the partition, false otherwise.
/// Thrown if partition is null.
/// Thrown when data lenght is greater then Int32.MaxValue.
/// Thrown on memory error.
/// Thrown on memory error.
/// Thrown on memory error.
public override bool IsType(Partition aDevice)
{
if (aDevice == null)
{
throw new ArgumentNullException(nameof(aDevice));
}
var xBPB = aDevice.NewBlockArray(1);
aDevice.ReadBlock(0UL, 1U, ref xBPB);
var xSig = BitConverter.ToUInt16(xBPB, 510);
return xSig == 0xAA55;
}
///
/// Initializes a new instance of the class.
///
/// The partition.
/// The root path.
///
///
/// - Thrown when aDevice is null.
/// - Thrown when FatFileSystem is null.
/// - Thrown on fatal error (contact support).
///
///
///
///
/// - Thrown when aRootPath is null.
/// - Thrown on fatal error (contact support).
///
///
/// Thrown on fatal error (contact support).
///
///
/// - Thrown on fatal error (contact support).
/// - >FAT signature not found.
///
///
/// Thrown on fatal error (contact support).
public override FileSystem Create(Partition aDevice, string aRootPath, long aSize) => new FatFileSystem(aDevice, aRootPath, aSize);
}
}