Question

I am new to C# and is currently using COSMOS to make a simple FileSystem for my OS class. Currently I'm trying to implement a "reformat" function that, when the word "reformat" is typed into the console, the OS (emulated via QEMU), partitions the disk. Currently this is my code:

   public static void console()
    {            
        while (true)
        {
            Console.WriteLine("Console: ");
            String input = Console.ReadLine();
            if (input == "exit")
            {
                Cosmos.Sys.Deboot.ShutDown();
            }
            else if (input == "cpumem")
            {
                Console.WriteLine(Cosmos.Kernel.CPU.AmountOfMemory.ToString());
            }
            else if (input == "restart")
            {
                Cosmos.Sys.Deboot.Reboot();
            }
            else if (input == "devices")
            {
                var devices = Cosmos.Sys.FileSystem.Disk.Devices.ToArray();   
            }
            else if (input == "reformat")
            {
                try
                {
                    Partition part = null;
                    for (int j = 0; j < Cosmos.Hardware.BlockDevice.Devices.Count; j++)
                    {
                        if (Cosmos.Hardware.BlockDevice.Devices[j] is Partition)
                        {
                            part = (Partition)Cosmos.Hardware.BlockDevice.Devices[j];
                        }
                    }
                    var fs = new Cosmos.Sys.FileSystem.FAT32.FAT32(part);
                    uint cluster = 100;
                    fs.Format("newCluster", cluster);
                }
                catch
                {
                    //Do Something warn user.
                }
            }
        }
    }

Most important is this bit:

   else if (input == "reformat")
            {
                try
                {
                    Partition part = null;
                    for (int j = 0; j < Cosmos.Hardware.BlockDevice.Devices.Count; j++)
                    {
                        if (Cosmos.Hardware.BlockDevice.Devices[j] is Partition)
                        {
                            part = (Partition)Cosmos.Hardware.BlockDevice.Devices[j];
                        }
                    }
                    var fs = new Cosmos.Sys.FileSystem.FAT32.FAT32(part);
                    uint cluster = 100;
                    fs.Format("newCluster", cluster);
                }
                catch
                {
                    //Do Something warn user.
                }
            }

Which is analogous to what is located here: http://cosmos-tutorials.webs.com/atafat.html

However, when I run it, I get this error:

enter image description here

I believe this is because I lack this line:

Cosmos.System.Filesystem.FileSystem.AddMapping("C", FATFS);
FATFileList = FATFS.GetRoot();

Located in the link above. Is there any other way to map? Or am I missing something completely? The COSMOS documentation doesn't really tell much, the source code is honestly confusing for a beginner like me as it has no comments whatsoever on how the functions work or what they do. I am using an older version of COSMOS (Milestone 4) as it's the only one that works for Visual Studio C# 2008. Newer versions run only in Visual Studio C# 2010.

No correct solution

OTHER TIPS

Ah, I recognize this... had to debug a similar situation on a Cosmos project I'm working on myself (I'm using the VS2010-compatible Cosmos but the same situation might apply to older versions as well...)

This can happen if you try to call a method on a null object. Type 0x........, Method 0x........ is specifically mentioning the location in the compiled code where the call failed. "Not FOUND!" means that the method it is looking for cannot be found, presumably because you called it on a null reference.

I'm testing with VirtualBox myself, and found that if you're using a brand-new blank hard disk image, there will be no Partitions on it. Thus, the condition will never get satisfied, your Partition will never get set and then Cosmos will try to execute a method on the null Partition!

Look closely at how you set the Partition (it's initialized to null). For starters I would print a simple message each time the "if (block device is partition)" condition is satisfied... I would be willing to bet it will never print.

Hope this helps... I am still learning about Cosmos and custom kernels myself but fixing the null reference in my case solved my occurrence of the problem. If that's the problem, then the next step, of course, is figuring out why you're not getting any Partitions in the first place...

The rest of your code looks fine but I am not sure how you implemented the rest of your classes. Kernel debugging can be a nightmare, good luck to you!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top