Skip to content

Commit

Permalink
Merge pull request #2 from Szymekk44/CGE-Update2
Browse files Browse the repository at this point in the history
Cge update2
  • Loading branch information
Szymekk44 authored Sep 21, 2024
2 parents ac464df + e0e7f0b commit e58fdc5
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 27 deletions.
27 changes: 16 additions & 11 deletions source/Cosmos.System2/FileSystem/Disk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
using Cosmos.System.FileSystem.FAT;
using Cosmos.System.FileSystem.ISO9660;
using Cosmos.System.FileSystem.VFS;
using static Cosmos.System.FileSystem.FileSystem;

namespace Cosmos.System.FileSystem
{
public class Disk
{
private readonly List<ManagedPartition> parts = new();
public readonly List<ManagedPartition> parts = new();

public bool IsMBR => !GPT.IsGPTPartition(Host);
/// <summary>
Expand Down Expand Up @@ -263,21 +264,25 @@ public void Clear()
}
}

public void FormatPartition(int index, string format, bool quick = true)
/// <summary>
/// Formats the specified partition with the given file system format.
/// </summary>
/// <param name="index">The index of the partition to format.</param>
/// <param name="format">The file system format to use (e.g., FAT32).</param>
/// <param name="quick">Indicates whether to perform a quick format. Defaults to true.</param>
/// <remarks>
/// The method formats the partition by creating a new file system and mounting it.
/// The partition is referenced by its index from the list of partitions.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">Thrown if the partition index is invalid.</exception>
public void FormatPartition(int index, FileSystemFormat 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
18 changes: 9 additions & 9 deletions source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ internal class FatFileSystem : FileSystem
/// </summary>
internal class Fat
{
private readonly FatFileSystem mFileSystem;
public readonly FatFileSystem mFileSystem;

private readonly ulong mFatSector;
public readonly ulong mFatSector;

/// <summary>
/// A reused buffer for <see cref="GetFatEntry(uint, out uint)"/>s read operations to save on allocations.
/// </summary>
private byte[] _getFatEntryReadBuffer;
public byte[] _getFatEntryReadBuffer;

/// <summary>
/// Initializes a new instance of the <see cref="Fat"/> class.
Expand All @@ -56,7 +56,7 @@ public Fat(FatFileSystem aFileSystem, ulong aFatSector)
/// </summary>
/// <returns>The size of a FAT entry in bytes.</returns>
/// <exception cref="NotSupportedException">Thrown when FAT type is unknown.</exception>
private uint GetFatEntrySizeInBytes()
public uint GetFatEntrySizeInBytes()
{
switch (mFileSystem.mFatType)
{
Expand Down 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, FileSystemFormat aDriveFormat)
{
if (aDevice == null)
{
Expand Down Expand Up @@ -1465,23 +1465,23 @@ 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(FileSystemFormat aDriveFormat, bool aQuick)
{
/* Parmaters check */
if (Device == null)
{
throw new ArgumentNullException(nameof(Device));
}

if (aDriveFormat == "FAT32")
if (aDriveFormat == FileSystemFormat.FAT32)
{
mFatType = FatTypeEnum.Fat32;
}
else if (aDriveFormat == "FAT16")
else if (aDriveFormat == FileSystemFormat.FAT16)
{
throw new NotImplementedException("FAT16 formatting not supported yet.");
}
else if (aDriveFormat == "FAT12")
else if (aDriveFormat == FileSystemFormat.FAT12)
{
throw new NotImplementedException("FAT12 formatting not supported yet.");
}
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(FileSystemFormat aDriveFormat, bool aQuick);
public enum FileSystemFormat { 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(FileSystemFormat aDriveFormat, bool aQuick)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.System2/FileSystem/VFS/VFSManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Cosmos.System.FileSystem.VFS
/// </summary>
public static class VFSManager
{
private static VFSBase mVFS;
public static VFSBase mVFS;


/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.System2/Graphics/FullScreenCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private enum VideoDriver
VGADriver
}

static Canvas videoDriver = null;
public static Canvas videoDriver = null;
static readonly PCIDevice svgaIIDevice = PCI.GetDevice(VendorID.VMWare, DeviceID.SVGAIIAdapter);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.System2/Graphics/SVGAIICanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SVGAIICanvas : Canvas
static readonly Mode defaultMode = new(1024, 768, ColorDepth.ColorDepth32);

private Mode mode;
private readonly VMWareSVGAII driver;
public readonly VMWareSVGAII driver;

/// <summary>
/// Initializes a new instance of the <see cref="SVGAIICanvas"/> class.
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.System2/Graphics/VBECanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Cosmos.System.Graphics
public class VBECanvas : Canvas
{
static readonly Mode defaultMode = new(1024, 768, ColorDepth.ColorDepth32);
readonly VBEDriver driver;
public readonly VBEDriver driver;
Mode mode;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.System2/Graphics/VGAScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Cosmos.System.Graphics
/// </summary>
public class VGAScreen
{
static readonly VGADriver screen = new();
public static readonly VGADriver screen = new();

/// <summary>
/// Sets the currently used graphics mode.
Expand Down

0 comments on commit e58fdc5

Please sign in to comment.