Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File System changes #3085

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reverted to string, added custom FilesystemLetter
  • Loading branch information
Szymekk44 committed Sep 21, 2024
commit 726f63d012964b21c895a92c5cf8a1bbcd6fa7ce
26 changes: 22 additions & 4 deletions source/Cosmos.System2/FileSystem/Disk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,32 @@ public void Clear()
}
}

public void FormatPartition(int index, FileSystemType format, bool quick = true)
/// <summary>
/// Formats a partition to the specified file system type.
/// </summary>
/// <param name="index">The index of the partition to format.</param>
/// <param name="format">The file system type to format the partition to (e.g., "FAT32").</param>
/// <param name="quick">Indicates whether the formatting should be quick. Defaults to true.</param>
/// <param name="FilesystemLetter">The drive letter for the partition. If empty, one will be automatically assigned.</param>
/// <exception cref="NotImplementedException">Thrown when the specified formatting type is not supported.</exception>
public virtual void FormatPartition(int index, string format, bool quick = true, string FilesystemLetter = "")
{
var part = Partitions[index];

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

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

private readonly FileSystem[] mountedPartitions = new FileSystem[4];
Expand Down
14 changes: 9 additions & 5 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, FileSystemType aDriveFormat)
public static FatFileSystem CreateFatFileSystem(Partition aDevice, string aRootPath, long aSize, string aDriveFormat)
{
if (aDevice == null)
{
Expand Down Expand Up @@ -1465,26 +1465,30 @@ 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(FileSystemType aDriveFormat, bool aQuick)
public override void Format(string aDriveFormat, bool aQuick)
{
/* Parmaters check */
if (Device == null)
{
throw new ArgumentNullException(nameof(Device));
}

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

/* FAT Configuration */
BytesPerSector = (uint)Device.BlockSize;
Expand Down
7 changes: 3 additions & 4 deletions source/Cosmos.System2/FileSystem/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ protected FileSystem(Partition aDevice, string aRootPath, long aSize)
/// <summary>
/// Format drive. (delete all)
/// </summary>
/// <param name="aDriveFormat">unused.</param>
/// <param name="aQuick">unused.</param>
/// <param name="aDriveFormat">Drive format. E.g. FAT32, FAT16...</param>
/// <param name="aQuick">Quick format. If false, partition is filled with 0.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// <list type = "bullet" >
/// <item>Thrown when the data length is 0 or greater then Int32.MaxValue.</item>
Expand Down Expand Up @@ -252,7 +252,6 @@ 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(FileSystemType aDriveFormat, bool aQuick);
public abstract void Format(string 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(FileSystemType aDriveFormat, bool aQuick)
public override void Format(string aDriveFormat, bool aQuick)
{
throw new NotImplementedException();
}
Expand Down
Loading