CosmosOS/Cosmos

File.Exists() causes CPU Exception

Opened this issue · 8 comments

Area of Cosmos - What area of Cosmos are we dealing with?

FileSystem

Expected Behaviour - What do you think that should happen?

File.Exists should return a bool

Actual Behaviour - What unexpectedly happens?

I get Cosmos CPU Exception, invalid opcode

Reproduction - How did you get this error to appear?

Use System.IO.File.Exists()

Version - Were you using the User Kit or Dev Kit? And what User Kit version or Dev Kit commit (Cosmos, IL2CPU, X#)?

Latest dev kit, running using vmware on linux

Here's my code:

using System;
using System.Collections.Generic;
using System.Text;
using Cosmos.System.FileSystem.VFS;
using Sys = Cosmos.System;

namespace TestKernel
{
    public class Kernel: Sys.Kernel
    {
        Sys.FileSystem.CosmosVFS fs = new Cosmos.System.FileSystem.CosmosVFS();

        protected override void BeforeRun()
        {
            Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);
            Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back.");
            Console.WriteLine("Testing FileExists");
            try
            {
                Console.WriteLine(System.IO.File.Exists(@"0:\test.txt"));
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e);
            }
        }
        
        protected override void Run()
        {
            Console.Write("Input: ");
            var input = Console.ReadLine();
            Console.Write("Text typed: ");
            Console.WriteLine(input);
        }
    }
}

here's a screenshot of the error
image

Try instead of initializing the fs immediately set it to null first and then in beforerun set it to a new instance

Since it probaly needs to do some more initialization in OnBoot which is called before BeforeRun but if you just init it immediately then its probaly not gonna work. @JeffTheK

Just tried doing it the way you told me, I still get the same error

In the first code i copied the initialization code from the docs, so i thought it would work

Also Directory.Exists works fine, but File.Exists does not

from memory there is a bug in the exception handler where it will some times kill the system i think it was something to do with stack corruption

Weird, I'm using old devkit and it's works...

it works most of the time