Created
June 18, 2021 12:07
-
-
Save valentinbreiz/5d6052c45a44a529a29147fbfb07d4bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Cosmos.HAL; | |
using Cosmos.HAL.BlockDevice; | |
using Cosmos.System.FileSystem; | |
using Cosmos.System.FileSystem.VFS; | |
using Cosmos.System.Network; | |
using Cosmos.System.Network.ARP; | |
using Cosmos.System.Network.Config; | |
using Cosmos.System.Network.IPv4; | |
using Cosmos.System.Network.IPv4.TCP; | |
using Cosmos.System.Network.IPv4.TCP.FTP; | |
using Cosmos.System.Network.IPv4.UDP; | |
using Cosmos.System.Network.IPv4.UDP.DHCP; | |
using Cosmos.System.Network.IPv4.UDP.DNS; | |
using Cosmos.TestRunner; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Text; | |
using Sys = Cosmos.System; | |
namespace NetworkTest | |
{ | |
public class Kernel : Sys.Kernel | |
{ | |
CosmosVFS fs; | |
protected override void BeforeRun() | |
{ | |
/*NetworkDevice nic = NetworkDevice.GetDeviceByName("eth0"); //get network device by name | |
//IPConfig.Enable(nic, Address.Parse("10.33.20.54"), new Address(255, 255, 255, 0), Address.Parse("10.33.20.254")); //enable IPv4 configuration | |
IPConfig.Enable(nic, new Address(10, 33, 20, 54), new Address(255, 255, 255, 0), new Address(10, 33, 20, 254)); //enable IPv4 configuration | |
Console.WriteLine("Network config done! IP=" + NetworkConfig.CurrentConfig.Value.IPAddress.ToString());*/ | |
fs = new CosmosVFS(); | |
VFSManager.RegisterVFS(fs); | |
} | |
protected override void Run() | |
{ | |
try | |
{ | |
var cmd = Console.ReadLine(); | |
if (cmd == "format") | |
{ | |
fs.Format("1" /*drive id*/, "FAT32" /*fat type*/, true /*use quick format*/); | |
} | |
else if (cmd == "list") | |
{ | |
ListFiles(); | |
} | |
else if (cmd == "info") | |
{ | |
var available_space = fs.GetAvailableFreeSpace(@"0:\"); | |
Console.WriteLine("Available Free Space: " + available_space); | |
var fs_type = fs.GetFileSystemType(@"0:\"); | |
Console.WriteLine("File System Type: " + fs_type); | |
} | |
else if (cmd.StartsWith("create ")) | |
{ | |
var dirname = cmd.Split(' ')[1]; | |
try | |
{ | |
var file_stream = File.Create(@"0:\" + dirname); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.ToString()); | |
} | |
try | |
{ | |
File.WriteAllText(@"0:\" + dirname, "Learning how to use VFS!"); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.ToString()); | |
} | |
try | |
{ | |
Console.WriteLine(File.ReadAllText(@"0:\" + dirname)); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.ToString()); | |
} | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("Exception: " + ex); | |
} | |
} | |
public void ListFiles() | |
{ | |
var directory_list = Directory.GetFiles(@"0:\"); | |
foreach (var file in directory_list) | |
{ | |
Console.WriteLine(file); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment