From b84f8a4aa7489b57d9216ca20f113770d5fe8c47 Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+Szymekk44@users.noreply.github.com> Date: Sat, 21 Sep 2024 12:06:58 +0200 Subject: [PATCH 1/2] Graphics drivers are public, FileSystemType enum --- source/Cosmos.System2/FileSystem/Disk.cs | 27 +++++++++++-------- .../FileSystem/FAT/FatFileSystem.cs | 18 ++++++------- .../Cosmos.System2/FileSystem/FileSystem.cs | 3 ++- .../FileSystem/ISO9660/ISO9660FileSystem.cs | 2 +- .../FileSystem/VFS/VFSManager.cs | 2 +- .../Graphics/FullScreenCanvas.cs | 2 +- .../Cosmos.System2/Graphics/SVGAIICanvas.cs | 2 +- source/Cosmos.System2/Graphics/VBECanvas.cs | 2 +- source/Cosmos.System2/Graphics/VGAScreen.cs | 2 +- 9 files changed, 33 insertions(+), 27 deletions(-) diff --git a/source/Cosmos.System2/FileSystem/Disk.cs b/source/Cosmos.System2/FileSystem/Disk.cs index a69292c0f3..69a67c14f9 100644 --- a/source/Cosmos.System2/FileSystem/Disk.cs +++ b/source/Cosmos.System2/FileSystem/Disk.cs @@ -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 parts = new(); + public readonly List parts = new(); public bool IsMBR => !GPT.IsGPTPartition(Host); /// @@ -263,21 +264,25 @@ public void Clear() } } - public void FormatPartition(int index, string format, bool quick = true) + /// + /// Formats the specified partition with the given file system format. + /// + /// The index of the partition to format. + /// The file system format to use (e.g., FAT32). + /// Indicates whether to perform a quick format. Defaults to true. + /// + /// 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. + /// + /// Thrown if the partition index is invalid. + 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]; diff --git a/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs b/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs index 40ba64c891..d3aae34f84 100644 --- a/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs +++ b/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs @@ -24,14 +24,14 @@ internal class FatFileSystem : FileSystem /// internal class Fat { - private readonly FatFileSystem mFileSystem; + public readonly FatFileSystem mFileSystem; - private readonly ulong mFatSector; + public readonly ulong mFatSector; /// /// A reused buffer for s read operations to save on allocations. /// - private byte[] _getFatEntryReadBuffer; + public byte[] _getFatEntryReadBuffer; /// /// Initializes a new instance of the class. @@ -56,7 +56,7 @@ public Fat(FatFileSystem aFileSystem, ulong aFatSector) /// /// The size of a FAT entry in bytes. /// Thrown when FAT type is unknown. - private uint GetFatEntrySizeInBytes() + public uint GetFatEntrySizeInBytes() { switch (mFileSystem.mFatType) { @@ -766,7 +766,7 @@ public FatFileSystem(Partition aDevice, string aRootPath, long aSize, bool fileS /// /// /// Thrown on fatal error. - 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) { @@ -1465,7 +1465,7 @@ internal enum FatTypeEnum /// Thrown on fatal error. /// Thrown when the data in aData is corrupted. /// Thrown when FAT type is unknown. - public override void Format(string aDriveFormat, bool aQuick) + public override void Format(FileSystemFormat aDriveFormat, bool aQuick) { /* Parmaters check */ if (Device == null) @@ -1473,15 +1473,15 @@ public override void Format(string aDriveFormat, bool aQuick) 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."); } diff --git a/source/Cosmos.System2/FileSystem/FileSystem.cs b/source/Cosmos.System2/FileSystem/FileSystem.cs index 64c0db0593..bb037e6daa 100644 --- a/source/Cosmos.System2/FileSystem/FileSystem.cs +++ b/source/Cosmos.System2/FileSystem/FileSystem.cs @@ -252,6 +252,7 @@ protected FileSystem(Partition aDevice, string aRootPath, long aSize) /// Thrown on fatal error. /// Thrown when the data in aData is corrupted. /// Thrown when FAT type is unknown. - public abstract void Format(string aDriveFormat, bool aQuick); + public abstract void Format(FileSystemFormat aDriveFormat, bool aQuick); + public enum FileSystemFormat { FAT12, FAT16, FAT32 }; } } diff --git a/source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs b/source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs index 96ed44c18b..c2d3659580 100644 --- a/source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs +++ b/source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs @@ -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(); } diff --git a/source/Cosmos.System2/FileSystem/VFS/VFSManager.cs b/source/Cosmos.System2/FileSystem/VFS/VFSManager.cs index 7fbb7a4a71..5018bd9d58 100644 --- a/source/Cosmos.System2/FileSystem/VFS/VFSManager.cs +++ b/source/Cosmos.System2/FileSystem/VFS/VFSManager.cs @@ -13,7 +13,7 @@ namespace Cosmos.System.FileSystem.VFS /// public static class VFSManager { - private static VFSBase mVFS; + public static VFSBase mVFS; /// diff --git a/source/Cosmos.System2/Graphics/FullScreenCanvas.cs b/source/Cosmos.System2/Graphics/FullScreenCanvas.cs index 1733e970d2..89d4c22dec 100644 --- a/source/Cosmos.System2/Graphics/FullScreenCanvas.cs +++ b/source/Cosmos.System2/Graphics/FullScreenCanvas.cs @@ -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); /// diff --git a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs index 4980d7b1fd..d7e5fb41f1 100644 --- a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs +++ b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs @@ -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; /// /// Initializes a new instance of the class. diff --git a/source/Cosmos.System2/Graphics/VBECanvas.cs b/source/Cosmos.System2/Graphics/VBECanvas.cs index ed277226a1..0743363175 100644 --- a/source/Cosmos.System2/Graphics/VBECanvas.cs +++ b/source/Cosmos.System2/Graphics/VBECanvas.cs @@ -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; /// diff --git a/source/Cosmos.System2/Graphics/VGAScreen.cs b/source/Cosmos.System2/Graphics/VGAScreen.cs index 8702099f54..e5a4c9867b 100644 --- a/source/Cosmos.System2/Graphics/VGAScreen.cs +++ b/source/Cosmos.System2/Graphics/VGAScreen.cs @@ -9,7 +9,7 @@ namespace Cosmos.System.Graphics /// public class VGAScreen { - static readonly VGADriver screen = new(); + public static readonly VGADriver screen = new(); /// /// Sets the currently used graphics mode. From e80d1e0fe61519986bad001158fe115796517c3a Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+Szymekk44@users.noreply.github.com> Date: Sat, 21 Sep 2024 12:23:12 +0200 Subject: [PATCH 2/2] Graphics drivers are public, FilsSystemType enum --- source/Cosmos.System2/FileSystem/Disk.cs | 27 +++++++++++-------- .../FileSystem/FAT/FatFileSystem.cs | 18 ++++++------- .../Cosmos.System2/FileSystem/FileSystem.cs | 3 ++- .../FileSystem/ISO9660/ISO9660FileSystem.cs | 2 +- .../FileSystem/VFS/VFSManager.cs | 2 +- .../Graphics/FullScreenCanvas.cs | 2 +- .../Cosmos.System2/Graphics/SVGAIICanvas.cs | 2 +- source/Cosmos.System2/Graphics/VBECanvas.cs | 2 +- source/Cosmos.System2/Graphics/VGAScreen.cs | 2 +- 9 files changed, 33 insertions(+), 27 deletions(-) diff --git a/source/Cosmos.System2/FileSystem/Disk.cs b/source/Cosmos.System2/FileSystem/Disk.cs index a69292c0f3..69a67c14f9 100644 --- a/source/Cosmos.System2/FileSystem/Disk.cs +++ b/source/Cosmos.System2/FileSystem/Disk.cs @@ -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 parts = new(); + public readonly List parts = new(); public bool IsMBR => !GPT.IsGPTPartition(Host); /// @@ -263,21 +264,25 @@ public void Clear() } } - public void FormatPartition(int index, string format, bool quick = true) + /// + /// Formats the specified partition with the given file system format. + /// + /// The index of the partition to format. + /// The file system format to use (e.g., FAT32). + /// Indicates whether to perform a quick format. Defaults to true. + /// + /// 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. + /// + /// Thrown if the partition index is invalid. + 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]; diff --git a/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs b/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs index 40ba64c891..d3aae34f84 100644 --- a/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs +++ b/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs @@ -24,14 +24,14 @@ internal class FatFileSystem : FileSystem /// internal class Fat { - private readonly FatFileSystem mFileSystem; + public readonly FatFileSystem mFileSystem; - private readonly ulong mFatSector; + public readonly ulong mFatSector; /// /// A reused buffer for s read operations to save on allocations. /// - private byte[] _getFatEntryReadBuffer; + public byte[] _getFatEntryReadBuffer; /// /// Initializes a new instance of the class. @@ -56,7 +56,7 @@ public Fat(FatFileSystem aFileSystem, ulong aFatSector) /// /// The size of a FAT entry in bytes. /// Thrown when FAT type is unknown. - private uint GetFatEntrySizeInBytes() + public uint GetFatEntrySizeInBytes() { switch (mFileSystem.mFatType) { @@ -766,7 +766,7 @@ public FatFileSystem(Partition aDevice, string aRootPath, long aSize, bool fileS /// /// /// Thrown on fatal error. - 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) { @@ -1465,7 +1465,7 @@ internal enum FatTypeEnum /// Thrown on fatal error. /// Thrown when the data in aData is corrupted. /// Thrown when FAT type is unknown. - public override void Format(string aDriveFormat, bool aQuick) + public override void Format(FileSystemFormat aDriveFormat, bool aQuick) { /* Parmaters check */ if (Device == null) @@ -1473,15 +1473,15 @@ public override void Format(string aDriveFormat, bool aQuick) 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."); } diff --git a/source/Cosmos.System2/FileSystem/FileSystem.cs b/source/Cosmos.System2/FileSystem/FileSystem.cs index 64c0db0593..bb037e6daa 100644 --- a/source/Cosmos.System2/FileSystem/FileSystem.cs +++ b/source/Cosmos.System2/FileSystem/FileSystem.cs @@ -252,6 +252,7 @@ protected FileSystem(Partition aDevice, string aRootPath, long aSize) /// Thrown on fatal error. /// Thrown when the data in aData is corrupted. /// Thrown when FAT type is unknown. - public abstract void Format(string aDriveFormat, bool aQuick); + public abstract void Format(FileSystemFormat aDriveFormat, bool aQuick); + public enum FileSystemFormat { FAT12, FAT16, FAT32 }; } } diff --git a/source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs b/source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs index 96ed44c18b..c2d3659580 100644 --- a/source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs +++ b/source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs @@ -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(); } diff --git a/source/Cosmos.System2/FileSystem/VFS/VFSManager.cs b/source/Cosmos.System2/FileSystem/VFS/VFSManager.cs index 7fbb7a4a71..5018bd9d58 100644 --- a/source/Cosmos.System2/FileSystem/VFS/VFSManager.cs +++ b/source/Cosmos.System2/FileSystem/VFS/VFSManager.cs @@ -13,7 +13,7 @@ namespace Cosmos.System.FileSystem.VFS /// public static class VFSManager { - private static VFSBase mVFS; + public static VFSBase mVFS; /// diff --git a/source/Cosmos.System2/Graphics/FullScreenCanvas.cs b/source/Cosmos.System2/Graphics/FullScreenCanvas.cs index 1733e970d2..89d4c22dec 100644 --- a/source/Cosmos.System2/Graphics/FullScreenCanvas.cs +++ b/source/Cosmos.System2/Graphics/FullScreenCanvas.cs @@ -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); /// diff --git a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs index 4980d7b1fd..d7e5fb41f1 100644 --- a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs +++ b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs @@ -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; /// /// Initializes a new instance of the class. diff --git a/source/Cosmos.System2/Graphics/VBECanvas.cs b/source/Cosmos.System2/Graphics/VBECanvas.cs index ed277226a1..0743363175 100644 --- a/source/Cosmos.System2/Graphics/VBECanvas.cs +++ b/source/Cosmos.System2/Graphics/VBECanvas.cs @@ -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; /// diff --git a/source/Cosmos.System2/Graphics/VGAScreen.cs b/source/Cosmos.System2/Graphics/VGAScreen.cs index 8702099f54..e5a4c9867b 100644 --- a/source/Cosmos.System2/Graphics/VGAScreen.cs +++ b/source/Cosmos.System2/Graphics/VGAScreen.cs @@ -9,7 +9,7 @@ namespace Cosmos.System.Graphics /// public class VGAScreen { - static readonly VGADriver screen = new(); + public static readonly VGADriver screen = new(); /// /// Sets the currently used graphics mode.