2013-01-31 125 views
0

我是C#的新手,目前正在使用COSMOS为我的操作系统类创建一个简单的FileSystem。目前,我试图实现一个“重新格式化”功能,当“控制台重新格式化”一词输入到控制台中时,操作系统(通过QEMU模拟)对磁盘进行分区。目前,这是我的代码:Cosmos自定义操作系统,addmapping?

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. 
       } 
      } 
     } 
    } 

最重要的是该位:

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. 
       } 
      } 

这类似于什么位置为:http://cosmos-tutorials.webs.com/atafat.html

然而,当我运行它,我得到这个错误:

enter image description here

我相信牛逼他是因为我缺少这条线:

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

位于上面的链接。有没有其他方法可以映射?或者我完全错过了什么? COSMOS的文档并没有多少意义,源代码对于像我这样的初学者来说,确实令人困惑,因为它对于函数的工作方式或者它们的功能没有任何评论。我使用的是旧版本的COSMOS(Milestone 4),因为它是唯一适用于Visual Studio C#2008的版本。较新的版本只能在Visual Studio C#2010中运行。

+0

这是不对的。你说VMWare和你在QEMU中模拟它: - |。 –

+0

你对对不起 – Erasmus

回答

0

啊,我意识到这一点...必须调试在我自己工作的一个Cosmos项目(我使用VS2010兼容的Cosmos,但同样的情况也可能适用于旧版本,以及...)的情况类似的情况下)

这可能会发生如果您尝试呼叫一个空对象的方法。键入0x ........,方法0x ........特别提到编译代码中调用失败的位置。 “未找到!”意味着找不到它正在查找的方法,可能是因为您将它称为空引用。

我使用VirtualBox自己测试,发现如果您使用的是全新的空白硬盘映像,那么将不会有分区。因此,条件将永远不会满足,您的分区将永远不会被设置,然后Cosmos将尝试在空分区上执行一个方法!

仔细看看你如何设置分区(它已初始化为空)。对于初学者,每次“if(block device is partition)”条件满足时,我都会打印一条简单的消息......我愿意打赌它永远不会打印。

希望这会有所帮助......我仍然在学习有关Cosmos和自定义内核的知识,但是修复了我的案例中的空引用,解决了我发生的问题。如果这是问题,那么下一步,当然,是搞清楚为什么你没有得到任何分区的第一位...

其余的代码看起来好,但我不知道如何你实现了你的其他课程。内核调试可能是一场噩梦,祝你好运!