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

Filesystem #13

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions Medli/Boot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ protected override void BeforeRun()
Kernel.Running = true;
Console.Clear();
Hardware.AddDisks.Detect();
Kernel.FileSystemINIT();
Console.Write(Kernel.logo);
Console.WriteLine(Kernel.welcome);
Console.WriteLine("");
Console.WriteLine("Current system date and time:");
Time.printDate();
Time.printTime();
DateTime.printDate();
DateTime.printTime();
SystemFunctions.PrintInfo();
}
catch (Exception ex)
Expand Down
57 changes: 57 additions & 0 deletions Medli/Hardware/DiskUtility/MDFS.Physical/MFSU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,62 @@ public static void CreatePartitions()
DiskPartInfo();
}
}

public static void CreatePartitions(IDE[] IDEs)
{
int PartitionNumber = 0;
ulong DisplayCount = SelectedDisk.Disk.BlockCount - 1;
MDUtils.WriteLine("How many primary partitions do you want to have? (Max. 4)");
do
{
String nums = MDUtils.ReadLine("Insert number:");
PartitionNumber = int.Parse(nums);
}
while (PartitionNumber == 0 || PartitionNumber > 4);

uint mbrpos = 446;
Byte[] type = new Byte[] { 0x00, 0x00, 0x00, 0x00 };
uint[] StartBlock = new uint[] { 1, 0, 0, 0 };
uint[] BlockNum = new uint[] { 0, 0, 0, 0 };
for (int i = 0; i < PartitionNumber; i++)
{
// Filesystem type 0xFA (250 DEC)
type[i] = 0xFA;
String nums = MDUtils.ReadLine("How many blocks for Partition N. " + (i + 1) + "? (Max: " + ((uint)(DisplayCount - (uint)(PartitionNumber - (i + 1)))).ToString() + "): ");
uint num = (uint)int.Parse(nums);
if (num >= 0 && num <= DisplayCount - (uint)(PartitionNumber - (i + 1)))
{
BlockNum[i] = num;
if (i < PartitionNumber - 1)
{
StartBlock[i + 1] = (num) + StartBlock[i];
}
DisplayCount = DisplayCount - (num);
}
else
{
i--;
}
}


Byte[] data = SelectedDisk.Disk.NewBlockArray(1);
SelectedDisk.Disk.ReadBlock(0, 1, data);
for (int i = 0; i < 4; i++)
{
mbrpos += 4;
data[mbrpos] = type[i];
mbrpos += 4;
Byte[] b = BitConverter.GetBytes(StartBlock[i]);
Utilities.CopyByteToByte(b, 0, data, (int)mbrpos, b.Length);
mbrpos += 4;
b = BitConverter.GetBytes(BlockNum[i]);
Utilities.CopyByteToByte(b, 0, data, (int)mbrpos, b.Length);
mbrpos += 4;
SelectedDisk.Disk.WriteBlock(StartBlock[i], 1, SelectedDisk.Disk.NewBlockArray(1));
}
SelectedDisk.Disk.WriteBlock(0, 1, data);
DiskPartInfo();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,20 @@ public static void WriteOnLastLine(String str)
WriteLine(s);
}

/// <summary>
/// Reads a single key from the input
/// <summary>
/// Writes a string on the last line of the screeen without creating a new one
/// </summary>
public static ConsoleKeyInfo ReadAKey()
/// <param name="str">The string to write</param>
public static void WriteOnLastLine(Char chr)
{
String str = chr + "";
WriteOnLastLine(str);
}

/// <summary>
/// Reads a single key from the input
/// </summary>
public static ConsoleKeyInfo ReadAKey()
{
ConsoleKeyInfo k = Console.ReadKey(true);
if (k.Modifiers == ConsoleModifiers.Alt || k.Modifiers == ConsoleModifiers.Control)
Expand Down
95 changes: 0 additions & 95 deletions Medli/Hardware/MFS.cs

This file was deleted.

52 changes: 50 additions & 2 deletions Medli/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,59 @@
using Sys = Cosmos.System;
using Medli.Common;
using Medli.System;
using Medli.System.MDFS;
using MDFS.Physical;

namespace Medli
{
public static partial class Kernel
{
public static List<Service> Services = new List<Service>();
}
/// <summary>
/// The filesystem object which will allow access to files on MDFS partition
/// </summary>
public static MDFileSystem fs;

/// <summary>
/// Development bool as to whether or not MDFS is to be used
/// </summary>
private static bool UseMDFS = true;

/// <summary>
/// List of kernel services
/// </summary>
public static List<Service> Services = new List<Service>();

/// <summary>
/// The partition that is to be formatted with MDFS
/// </summary>
private static PrimaryPartition FSPartition;
public static void FileSystemINIT()
{
if (UseMDFS == true)
{
IDE[] IDEs = IDE.Devices.ToArray();
MDFS.MDUtils.WriteLine("Number of IDE disks: " + IDEs.Length);
MDFS.MDUtils.WriteLine("Looking for valid partitions...");
for (int i = 0; i < IDEs.Length; i++)
{
PrimaryPartition[] parts = IDEs[i].PrimaryPartitions;
for (int j = 0; j < parts.Length; j++)
{
if (parts[j].Infos.SystemID == 0xFA)
{
FSPartition = parts[j];
}
}
}
if (FSPartition == null)
{
FS.MFSU();
MDFS.MDUtils.WriteLine("The machine needs to be restarted.");
}

fs = new MDFileSystem(FSPartition);
MDFileSystem.MapFS("/", fs);
}
}
}
}
2 changes: 1 addition & 1 deletion Medli/Kernel/Commands/Date.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override string Summary

public override void Execute(string param)
{
Medli.Time.printDate();
DateTime.printDate();
}
}
}
2 changes: 1 addition & 1 deletion Medli/Kernel/Commands/Time.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override string Summary

public override void Execute(string param)
{
Medli.Time.printTime();
DateTime.printTime();
}
}
}
Loading