How to use FileSystem in Cosmos??

Topics: Developing Cosmos (Working on Cosmos source code directly), Using Cosmos (Developing your own OS, projects, etc)
Jun 2, 2013 at 6:09 AM
Hi. I'm new with Cosmos. I don't know how to use FileSystem. For example try to browse files or create files and stuff. Can anyone help me?
Jun 2, 2013 at 6:12 AM
They have a FAT implementation, and there are several user created filesystems. I do not think they have working FAT in the last release though.
Jun 2, 2013 at 6:13 AM
Also I have to say, I'm using Visual Studio 2010 and the latest version(Just in case, some codes I've seen on the internet that were written for 2008 version)
Coordinator
Jun 2, 2013 at 9:06 AM
Our latest release (not the promoted one) has support for FAT.
Problem with that release is, that we (tried to) switched to SQL localdb for storing debug information, which doesn't work too well..
We're working on switching to sqlite, which is faster, and easier to deploy. However, we need more people on devkit to test and improve this support...




Op 2 jun. 2013 08:13 schreef "hydarnes" <[email removed]> het volgende:

From: hydarnes

Also I have to say, I'm using Visual Studio 2010 and the latest version(Just in case, some codes I've seen on the internet that were written for 2008 version)

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Jun 2, 2013 at 9:14 AM
I mean is there any codes or classes that could help me browse the partitions, and create files and stuff in?
Coordinator
Jun 2, 2013 at 9:16 AM
With latest release (not the advertised one), yes..




Jun 2, 2013 at 10:12 AM
Could you tell me what it is. What class it is. How to use it?
Coordinator
Jun 2, 2013 at 10:14 AM
See the sources. In Source2\Users\Kudzu there's a playground project showing how to use..



Jun 2, 2013 at 10:37 AM
What's its name?I found Kudzu but I can't understand anything in its projects. I'm new to Cosmos. Isn't there like a class to find the partitions like simple C# Windows programs?(Like using foreach or something)
Coordinator
Jun 2, 2013 at 10:56 AM
foreach doesn't work (reliably) as it uses interfaces..

See BreakpointsOS.cs, the TestATA method


Developer
Jun 2, 2013 at 2:39 PM
Edited Jun 2, 2013 at 2:40 PM
Well, Cosmos FAT is not fully implemented yet..It can read only root directory files & it doesn't have write supports :(

But you can still use Cosmos FAT :-
Partition xPartition = null;
                if (BlockDevice.Devices.Count > 0)
                {
                    for (int i = 0; i < BlockDevice.Devices.Count; i++)
                    {
                        var xDevice = BlockDevice.Devices[i];
                        if (xDevice is Partition)
                        {
                            xPartition = (Partition)xDevice;
                            var xFS = new FAT.FatFileSystem(xPartition);

                            for (int j = 0; j < xListing.Count; j++)
                            {
                                var xItem = xListing[j];
                                if (xItem is Sys.Filesystem.Listing.Directory)
                                {
                                    //Detecting Dir in HDD
                                    Console.WriteLine("<DIR> " + xListing[j].Name);
                                }
                                else if (xItem is Sys.Filesystem.Listing.File)
                                {
                                    //Detecting File in HDD
                                    Console.WriteLine("<FILE> " + xListing[j].Name + " (" + xListing[j].Size + ")");
                                }
                            }

                           // And For reading files
                            try
                            {   var xStream = new Sys.Filesystem.FAT.FatStream("File Streme Goes here");
                                var xData = new byte[xRootFile.Size];
                                xStream.Read(xData, 0, (int)xRootFile.Size);
                                var xText = Encoding.ASCII.GetString(xData);
                                Console.WriteLine(xText);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Error: " + e.Message);
                            }
Regards
Aman Priyadarshi
Jun 3, 2013 at 6:32 AM
Thanks, Aman. But I couldn't be able to find some of the libraries you used. Could u upload 'em for me please?I exactly have syntax errors in these lines:
1Partition xPartition = null;
2                if (BlockDevice.Devices.Count > 0)
3                {
4                    for (int i = 0; i < BlockDevice.Devices.Count; i++)
5                    {
6                        var xDevice = BlockDevice.Devices[i];
7                        if (xDevice is Partition)
8                        {
9                            xPartition = (Partition)xDevice;
10                            var xFS = new FAT.FatFileSystem(xPartition);//Doesn't find FAT.FatFile....
11
12                            for (int j = 0; j < xListing.Count; j++)//Doesn't find xListing.Count...
13                            {
14                                var xItem = xListing[j];//Doesn't find xListing
15                                if (xItem is Cosmos.System.Filesystem.Listing.Directory)
16                                {
17                                    
18                                    System.Console.WriteLine("<DIR> " + xListing[j].Name);//Doesn't find xListing
19                                }
20                                else if (xItem is Cosmos.System.Filesystem.Listing.File)
21                                {
22                                    //Detecting File in HDD
23                                    System.Console.WriteLine("<FILE> " + xListing[j].Name + " (" + xListing[j].Size + ")");//Doesn't find xListings
24                                }
25                            }
26                          
27                            try
28                            {   var xStream = new Cosmos.System.Filesystem.FAT.FatStream("File Streme Goes here");//Error from new to the end of the line
29                                var xData = new byte[xRootFile.Size];//Doesn't find xRootFile
30                                xStream.Read(xData, 0, (int)xRootFile.Size);//Doesn't find xRootFile
31                                var xText = Encoding.ASCII.GetString(xData);
32                                System.Console.WriteLine(xText);
33                            }
34                            catch (Exception e)
35                            {
36                                System.Console.WriteLine("Error: " + e.Message);
37                            }

Coordinator
Jun 3, 2013 at 6:34 AM
So, what lines you get errors? Seems you're not using latest release then.. but maybe that's because latest release (advertised one) doesn't yet contain the full fat stuff..



Jun 3, 2013 at 6:35 AM
Could you please send me a link to the latest version?
Coordinator
Jun 3, 2013 at 6:38 AM
see codeplex.. but i'm not sure if it works good with the sqllocaldb.
If you have some time to spare, please consider joining the development channel and help us out on development. Before thinking it's way beyond your knowledge level, there's much non-OS-dev related stuff going on (installers, testing, etc)
:)


Jun 3, 2013 at 6:40 AM
I have a CosmosUserKit-101070.exe file. Is that it?
Coordinator
Jun 3, 2013 at 6:42 AM
yes


Jun 3, 2013 at 6:47 AM
Thanks. I'm installin' it.
Jun 3, 2013 at 6:49 AM
I installed it. Should I import the libraries all over again?
Coordinator
Jun 3, 2013 at 6:52 AM
should not be necessary, but best to just give a try...

How about joining the dev channel? you'll be on the latest version then.. :)


Jun 3, 2013 at 6:53 AM
Sorry, I didn't get you. Joining what?
Coordinator
Jun 3, 2013 at 6:54 AM
join development team, help us move forward faster.. :)


Jun 3, 2013 at 7:01 AM
really? Wow, sure
Coordinator
Jun 3, 2013 at 7:04 AM
send an email to cosmos-dev-subscribe at yahoogroups.com

send a short intro message about interests experiences etc (1-2 lines). then uninstall the userkit and (try to) install the devkit..
:)


Jun 3, 2013 at 7:04 AM
just one thing. I installed the new version and replaced the libraries but still gives the same errors. Maybe there's a library I didn't Import to codes"like:using cosmos...."
Coordinator
Jun 3, 2013 at 7:06 AM
then vs should give you a hint to do the using..



Jun 3, 2013 at 7:14 AM
I sent it
Jun 3, 2013 at 7:16 AM
vs???
Coordinator
Jun 3, 2013 at 7:18 AM
sending messages to dev list by sending to cosmos-dev at yahoogroups.com
please send a message asking how to get started.. :)


Jun 3, 2013 at 7:21 AM
I sent it. I joined the group on yahoo and it is pending... So what libraries did you say I use?
Coordinator
Jun 3, 2013 at 7:24 AM
not sre, i think Cosmos.System


Jun 3, 2013 at 7:27 AM
Edited Jun 3, 2013 at 7:29 AM
I am using it. But it gives the error again
Jun 3, 2013 at 7:29 AM
And is there a way, not by partition, that I could save user data anywhere?
Coordinator
Jun 3, 2013 at 7:33 AM
only way an os can save user data on a machine is on disk...



Jun 3, 2013 at 7:36 AM
Do you have any example codes?
Jun 3, 2013 at 7:37 AM
I've got it. It has to be using FAT=Cosmos....
Jun 3, 2013 at 8:46 AM
I can browse all the partitions but do you have an example to write a file in them?
Coordinator
Jun 3, 2013 at 8:49 AM
not sure if writing is supported yet..



Jun 3, 2013 at 8:56 AM
I mean writing on the disk for saving data and stuff.
Coordinator
Jun 3, 2013 at 9:00 AM
yes, me too.. :)


Jun 3, 2013 at 10:39 AM
Hey, I'm havin' a little problem in VS2010. you see I wanna release a version of my OS and I put my build mode on Release but it is still on debug when I run it. and also there are 2 objects in config manager that one is OS one is OSBOOT that OS boot has got only one debug mode and no release mode!!!
Developer
Jun 3, 2013 at 2:03 PM
Currently FAT write support didn't work
Developer
Jun 3, 2013 at 3:03 PM
hydarnes: You can simply write things/stuffs to disk by using following code
using Cosmos.Hardware.BlockDevices;

public static class Test
{
      public static bool WriteData(byte[] aData)
      {
            if (BlockDevice.Devices.Count > 0)
            {
                 for (int i = 0; i < BlockDevices.Devices.Count; i++)
                 {
                       var xDevice = BlockDevices.Devices[i];
                       if (xDevice is partition)
                       {
                            //It will write all your data to the first partition 0th block
                             xDevice.Writeblock(0UL,(uint)(aData.length/512), aData);
                       }
                 }

            }
      }
}
And using cosmos fat...didn't make sense because it only read files of root directory and can't write any files to disk...it didn't have format support etc...
So use other file systems made for cosmos

Atom File System (written by me for AtomOS)
http://www.youtube.com/watch?v=D6h5iUkfJg0

you can find source here: http://www.atomos.tk/atom-file-system.html
it is only tested with the last changeset of mine of cosmos (changeset 101070)

Or you can help us to improve cosmos FAT driver...


Regards
Aman Priyadarshi
Jun 3, 2013 at 3:25 PM
Thanks Aman. I really appreciate your support but I just don't get it. What about file name? I mean for example I want the user to type in a password and it'll be saved in a block as pass.txt or somethin'... and then in the next time I could read it. Know what I mean?
Developer
Jun 3, 2013 at 3:31 PM
Edited Jun 3, 2013 at 3:32 PM
hard disk only save binary's (or can we say array of bytes)...So if you want save files in managed way...you must write a file system for that...
Apr 15, 2015 at 8:09 PM
That little piece of code will probably work, but I can't figure out how to use it. Can you provide an explaination about how to use this code?
Apr 16, 2015 at 9:13 AM
A question but in future when the FAT filesystem will be implemented you could use the normal C# classes to access them? I mean this example code will work in the future?
// For Directory.GetFiles and Directory.GetDirectories 
// For File.Exists, Directory.Exists 
using System;
using System.IO;
using System.Collections;

public class RecursiveFileProcessor 
{
    public static void Main(string[] args) 
    {
        foreach(string path in args) 
        {
            if(File.Exists(path)) 
            {
                // This path is a file
                ProcessFile(path); 
            }               
            else if(Directory.Exists(path)) 
            {
                // This path is a directory
                ProcessDirectory(path);
            }
            else 
            {
                Console.WriteLine("{0} is not a valid file or directory.", path);
            }        
        }        
    }


    // Process all files in the directory passed in, recurse on any directories  
    // that are found, and process the files they contain. 
    public static void ProcessDirectory(string targetDirectory) 
    {
        // Process the list of files found in the directory. 
        string [] fileEntries = Directory.GetFiles(targetDirectory);
        foreach(string fileName in fileEntries)
            ProcessFile(fileName);

        // Recurse into subdirectories of this directory. 
        string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
        foreach(string subdirectory in subdirectoryEntries)
            ProcessDirectory(subdirectory);
    }

    // Insert logic for processing found files here. 
    public static void ProcessFile(string path) 
    {
        Console.WriteLine("Processed file '{0}'.", path);       
    }
}
Regarding the Atom FS and in general other file systems what is the corrected method to integrate them in the kernel?
Apr 16, 2015 at 1:12 PM
After the Cosmos people come up with a suitable plug for System.IO, you can just use the System.IO functions normally. I wish that day comes soon :)

In answer to your second question: I can't help you with the Atom FS because every time I click http://www.atomos.tk/atom-file-system.html, it redirects me to a lot of scam websites and viruses and "YOU'RE OUR LUCKY VISITOR!!!" sites. But speaking of the other file systems... you should just try to find all of the .cs files and DLL files that make up the file system. After that, you can use the file system normally. But you shouldn't put too much time into trying to make it work right; I played with it for hours and I kept getting error after error after error. It was so hard. I think the best course of action for anyone who wants a file system in their operating system is to either be a super-hero and write their own, or wait for the Cosmos people to make write a plug for System.IO.
Coordinator
Apr 21, 2015 at 7:11 AM
Like I described in the other question, we're close to having System.IO working, but we're currently blocked by a compiler bug..



2015-04-16 15:12 GMT+02:00 JackHalpin <[email removed]>:

From: JackHalpin

After the Cosmos people come up with a suitable plug for System.IO, you can just use the System.IO functions normally. I wish that day comes soon :)

In answer to your second question: I can't help you with the Atom FS because every time I click http://www.atomos.tk/atom-file-system.html, it redirects me to a lot of scam websites and viruses and "YOU'RE OUR LUCKY VISITOR!!!" sites. But speaking of the other file systems... you should just try to find all of the .cs files and DLL files that make up the file system. After that, you can use the file system normally. But you shouldn't put too much time into trying to make it work right; I played with it for hours and I kept getting error after error after error. It was so hard. I think the best course of action for anyone who wants a file system in their operating system is to either be a super-hero and write their own, or wait for the Cosmos people to make write a plug for System.IO.

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com