Skip to content

Commit

Permalink
Disk formatting type as enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymekk44 committed Sep 21, 2024
1 parent 1f3bb52 commit 63e875c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
13 changes: 3 additions & 10 deletions source/Cosmos.System2/FileSystem/Disk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,14 @@ public void Clear()
}
}

public void FormatPartition(int index, string format, bool quick = true)
public void FormatPartition(int index, FileSystemType format, bool quick = true)
{
var part = Partitions[index];

var xSize = (long)(Host.BlockCount * Host.BlockSize / 1024 / 1024);

if (format.StartsWith("FAT"))
{
FatFileSystem.CreateFatFileSystem(part.Host, VFSManager.GetNextFilesystemLetter() + ":\\", xSize, format);
Mount();
}
else
{
throw new NotImplementedException(format + " formatting not supported.");
}
FatFileSystem.CreateFatFileSystem(part.Host, VFSManager.GetNextFilesystemLetter() + ":\\", xSize, format);
Mount();
}

private readonly FileSystem[] mountedPartitions = new FileSystem[4];
Expand Down
14 changes: 5 additions & 9 deletions source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ public FatFileSystem(Partition aDevice, string aRootPath, long aSize, bool fileS
/// </list>
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">Thrown on fatal error.</exception>
public static FatFileSystem CreateFatFileSystem(Partition aDevice, string aRootPath, long aSize, string aDriveFormat)
public static FatFileSystem CreateFatFileSystem(Partition aDevice, string aRootPath, long aSize, FileSystemType aDriveFormat)
{
if (aDevice == null)
{
Expand Down Expand Up @@ -1465,30 +1465,26 @@ internal enum FatTypeEnum
/// <exception cref="ArrayTypeMismatchException">Thrown on fatal error.</exception>
/// <exception cref="InvalidCastException">Thrown when the data in aData is corrupted.</exception>
/// <exception cref="NotSupportedException">Thrown when FAT type is unknown.</exception>
public override void Format(string aDriveFormat, bool aQuick)
public override void Format(FileSystemType aDriveFormat, bool aQuick)
{
/* Parmaters check */
if (Device == null)
{
throw new ArgumentNullException(nameof(Device));
}

if (aDriveFormat == "FAT32")
if (aDriveFormat == FileSystemType.FAT32)
{
mFatType = FatTypeEnum.Fat32;
}
else if (aDriveFormat == "FAT16")
else if (aDriveFormat == FileSystemType.FAT16)
{
throw new NotImplementedException("FAT16 formatting not supported yet.");
}
else if (aDriveFormat == "FAT12")
else if (aDriveFormat == FileSystemType.FAT12)
{
throw new NotImplementedException("FAT12 formatting not supported yet.");
}
else
{
throw new Exception("Unknown FAT type.");
}

/* FAT Configuration */
BytesPerSector = (uint)Device.BlockSize;
Expand Down
3 changes: 2 additions & 1 deletion source/Cosmos.System2/FileSystem/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ protected FileSystem(Partition aDevice, string aRootPath, long aSize)
/// <exception cref="ArrayTypeMismatchException">Thrown on fatal error.</exception>
/// <exception cref="InvalidCastException">Thrown when the data in aData is corrupted.</exception>
/// <exception cref="NotSupportedException">Thrown when FAT type is unknown.</exception>
public abstract void Format(string aDriveFormat, bool aQuick);
public abstract void Format(FileSystemType aDriveFormat, bool aQuick);
}
public enum FileSystemType { FAT12, FAT16, FAT32 }
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public override void DeleteFile(DirectoryEntry aPath)
{
throw new NotImplementedException("Read only file system");
}
public override void Format(string aDriveFormat, bool aQuick)
public override void Format(FileSystemType aDriveFormat, bool aQuick)
{
throw new NotImplementedException();
}
Expand Down

0 comments on commit 63e875c

Please sign in to comment.