CosmosOS / Cosmos

Cosmos is an operating system "construction kit". Build your own OS using managed languages such as C#, VB.NET, and more!
https://www.goCosmos.org
BSD 3-Clause "New" or "Revised" License
2.93k stars 554 forks source link

File System crashes unexpectedly #2117

Closed astromediaonly closed 2 years ago

astromediaonly commented 2 years ago

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

File System

Expected Behaviour - What do you think that should happen?

I should get list of files and probably some initiation message from VFSManager.RegisterVFS(fs);

Actual Behaviour - What unexpectedly happens?

I have got no initialization text from VFSManager.RegisterVFS(fs); and unexpected incomplete exception is happening viz output: What Im buffled most about is fact that e.Message is empty in first mDebugger.Send and contains "S" in second judging from the output ... wtf :D

Before Run
Mounting disk
Mounted partition.
Mounting disk
ATAPI: Reading block. Sector: 1 SectorCount: 1
ATAPI: Polling
ATAPI: Polling complete
ATAPI: Reading block. Sector: 0 SectorCount: 1
ATAPI: Polling
ATAPI: Polling complete
Run
Not yet stopped
ATAPI: Reading block. Sector: 1 SectorCount: 1
ATAPI: Polling
ATAPI: Polling complete
ATAPI: Reading block. Sector: 0 SectorCount: 1
ATAPI: Polling
ATAPI: Polling complete
Exception occurred: 
S

Reproduction - How did you get this error to appear?

Code:

public class Kernel : Sys.Kernel
{
    CosmosVFS fs = new CosmosVFS();

    protected override void BeforeRun()
    {
        VFSManager.RegisterVFS(fs);
    }

    protected override void Run()
    {
        Console.WriteLine("Files:");
        try
        {
            string[] files = Directory.GetFiles("0:/");
            foreach (string file in files) 
            {
                Console.WriteLine(file);
            }
        }
        catch (Exception e)
        {
            mDebugger.Send("Exception occurred: " + e.Message);
            mDebugger.Send(e.Message);
        }
        Console.WriteLine("--------------------");
    }
}

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

User Kit 20220209

quajak commented 2 years ago

RegisterVFS was updated to no longer post the text. If you want the text to still be displayed there is a separate method for that now.

The other issue you noticed seems like an actual issue and will need to be investigated.

quajak commented 2 years ago

I think the issue is that you wrote Directory.GetFiles("0:/"); and not Directory.GetFiles("0:\\");

astromediaonly commented 2 years ago

Hmm, this seems to work, thanks. Weird is most materials on your page and so I was reading were using 0:/ like this page https://github.com/CosmosOS/Cosmos/wiki/FAT-FileSystem first 4ish examples ... as Im scrolling down the rest is using @"0:\" .. it should be probably updated to be consistent and right?

Also can something be done about it crashing in this weird way if 0:/ is used? I have feeling there is some underlaying memory managment issue and/or exception handling issue with more wide spreading consequences considering e.Message was different between two lines of code ... also when I was using Dictionary of objects (with only two kinda small objects tho) it stopped to do anything without telling any info or throwing exception or crashing in similar way this does. And now im trying to figure out third case when it stops to do anything without throwing any exception again but Im not yet sure why this time.

But I have to admit debugger does not respect breakpoints in my case so there could be also some setup issue ... output was working fine tho so I would expect exceptions to appear normaly (usually they do).

quajak commented 2 years ago

Thanks for the heads up on the wiki. I fixed it there. In future the articles on the website https://cosmosos.github.io/articles/Kernel/VFS.html should be accurate, albeit they can also be outdated.

Exception handling is not very advanced, although the message of the exception should be maintained. If you can find a simple case where it breaks, I am happy to take a closer look. Could you please open issue regarding the Dictionary problem?

The debugger is quite outdated and is currently broken.

astromediaonly commented 2 years ago

I see, thanks for info.

The code I posted in my initial topic should lead to that ouptut (using User Kit 20220209)

Exception occurred: 
S

from

mDebugger.Send("Exception occurred: " + e.Message);
mDebugger.Send(e.Message);

if you are talking about that (simple case).

That Dictionary problem happened a while back and I dont have code for it anymore. I had tryed to simulated it again from memory but I could have just made wrong conclusion from other factors back then. Only thing I can say for sure now is Guid.NewGuid() returns always set of zeroes (probably not suppored yet) which was my first problem with dictionary I did not figured out back then because I was probably more paranoid about what is supported and what is not and so and I moved to simplier collection without figuring out its just throwing me duplicate key exceptions :) . Its probably fine and was on my end but if I encounter something with it again I will let you know.

The last problem mentioned I was investigating was probably also partialy my fault because I figured only recently protected override void Run() is continuous/repeating method and did not accounted for it properly in my code structure (was used to from assembler if I need loop I have to create it my self) ... if I have to guess there was multiple unncecessary object initialization resulting in kinda memory leak in my code ... it should have not left my while(true) loop inside but probably it was not as sure as I thought it was ... I made some structure changes to be more safe and now it does not hangs after that so hopefully it will be also OK. - just to let you know

I see, I hope it will be fixed soon-ish then :)

Thanks for your time and help.