How do you make A Virtual File System?

Jun 21, 2011 at 11:29 AM

Hi can anyone give me a start on making a vfs(virtual file system).

Jun 21, 2011 at 5:40 PM
Edited Jun 21, 2011 at 6:27 PM

Well, you could use my implementation:

 
If you use it, dont forget to give credit to me! ;)

 Edit: I left a bug in the code, just to see what kind of a coder you are :) Let me know if you find it!

    public class File
    {
        public string Contents;
        public string Name;

        public File(string Name, string Contents)
        {
            this.Contents = Contents;
            this.Name = Name;
        }

        ~File()
        {
            this.Contents = string.Empty;
            this.Name = string.Empty;
        }
    }

    public class FileSystem
    {
        private static File[] FileStack = new File[256];
        private static uint NextFile = 0;

        public static void Init()
        {
            for (int i = 0; i < FileStack.Length; i++)
            {
                FileStack[i] = new File("", "");
            }
        }

        public static void CreateFile(string Name, string Contents)
        {
            if (NextFile == 256)
            {
                Console.WriteLine("Error, max file limit reached!");
                return;
            }

            for (int i = 0; i < FileStack.Length; i++)
            {
                if (FileStack[i].Name == Name)
                {
                    Console.WriteLine("Error, file already exists!");
                }
            }

            FileStack[NextFile].Name     = Name;
            FileStack[NextFile].Contents = Contents;
            NextFile++;
        }

        public static void SaveFile(string Name, string Data)
        {
            for (int i = 0; i < FileStack.Length; i++)
            {
                if (FileStack[i].Name == Name)
                    FileStack[i].Contents = Data;
            }
        }

        public static void DeleteFile(string Name)
        {
            // Find file position (0 - 255) and assign it
            int FilePos = -1;

            for (int i = 0; i < FileStack.Length; i++)
            {
                if (FileStack[i].Name == Name)
                {
                    FilePos = i;
                    break;
                }
            }

            if (FilePos == -1)
            {
                Console.WriteLine("Error file not found!");
            }

            // Nullify the file
            FileStack[FilePos].Name     = "";
            FileStack[FilePos].Contents = "";

            // Move each registered file before 'Name' down one 
            string TempName     = "";
            string TempContents = "";

            for (int i = FilePos; i > 0; i--)
            {
                FileStack[i].Name     = TempName;
                FileStack[i].Contents = TempContents;

                TempName              = FileStack[i + 1].Name;
                TempContents          = FileStack[i + 1].Contents;
            }    
        }

        public static void DisplayFiles()
        {
            for (int i = 0; i < FileStack.Length; i++)
            {
                if (FileStack[i].Name != "")
                    Console.WriteLine(FileStack[i].Name);
            }
        }

        public static string GetFileContents(string Name)
        {
            for (int i = 0; i < FileStack.Length; i++)
            {
                if (FileStack[i].Name == Name)
                    return FileStack[i].Contents;
            }
            return "";
        }
    }
Coordinator
Jun 21, 2011 at 5:58 PM
So basically, it's a ramdisk?

On Tue, Jun 21, 2011 at 6:40 PM, blackfireize <notifications@codeplex.com> wrote:

From: blackfireize

Well, you could use my implementation:

    public class File
    {
        public string Contents;
        public string Name;

        public File(string Name, string Contents)
        {
            this.Contents = Contents;
            this.Name = Name;
        }

        ~File()
        {
            this.Contents = string.Empty;
            this.Name = string.Empty;
        }
    }

    public class FileSystem
    {
        private static File[] FileStack = new File[256];
        private static uint NextFile = 0;

        public static void Init()
        {
            for (int i = 0; i < FileStack.Length; i++)
            {
                FileStack[i] = new File("", "");
            }
        }

        public static void CreateFile(string Name, string Contents)
        {
            if (NextFile == 256)
            {
                Console.WriteLine("Error, max file limit reached!");
                return;
            }

            for (int i = 0; i < FileStack.Length; i++)
            {
                if (FileStack[i].Name == Name)
                {
                    Console.WriteLine("Error, file already exists!");
                }
            }

            FileStack[NextFile].Name     = Name;
            FileStack[NextFile].Contents = Contents;
            NextFile++;
        }

        public static void SaveFile(string Name, string Data)
        {
            for (int i = 0; i < FileStack.Length; i++)
            {
                if (FileStack[i].Name == Name)
                    FileStack[i].Contents = Data;
            }
        }

        public static void DeleteFile(string Name)
        {
            // Find file position (0 - 255) and assign it
            int FilePos = -1;

            for (int i = 0; i < FileStack.Length; i++)
            {
                if (FileStack[i].Name == Name)
                {
                    FilePos = i;
                    break;
                }
            }

            if (FilePos == -1)
            {
                Console.WriteLine("Error file not found!");
            }

            // Nullify the file
            FileStack[FilePos].Name     = "";
            FileStack[FilePos].Contents = "";

            // Move each registered file before 'Name' down one 
            string TempName     = "";
            string TempContents = "";

            for (int i = FilePos; i > 0; i--)
            {
                FileStack[i].Name     = TempName;
                FileStack[i].Contents = TempContents;

                TempName              = FileStack[i + 1].Name;
                TempContents          = FileStack[i + 1].Contents;
            }    
        }

        public static void DisplayFiles()
        {
            for (int i = 0; i < FileStack.Length; i++)
            {
                if (FileStack[i].Name != "")
                    Console.WriteLine(FileStack[i].Name);
            }
        }

        public static string GetFileContents(string Name)
        {
            for (int i = 0; i < FileStack.Length; i++)
            {
                if (FileStack[i].Name == Name)
                    return FileStack[i].Contents;
            }
            return "";
        }
    }
If you use it, dont forget to give credit to me! ;)

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

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 21, 2011 at 6:03 PM

Yep, it's okay I guess but it never integrates with anything outside of userspace so its kind of pointless..xD

Jun 21, 2011 at 9:33 PM

I guess its kind of cool, but what would be cool is to see this kind of code running a real filesystem :) Thats a little ways down the road but ill be there when it happens. Good work blackfireize this code is quite impressive. Thanks - Matt 

Jun 21, 2011 at 10:44 PM
Thanks exactly what i was looking for great work

On Wed, Jun 22, 2011 at 6:33 AM, civilwarrock <notifications@codeplex.com> wrote:

From: civilwarrock

I guess its kind of cool, but what would be cool is to see this kind of code running a real filesystem :) Thats a little ways down the road but ill be there when it happens. Good work blackfireize this code is quite impressive. Thanks - Matt

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

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




--
---------------------------
Jacksen Kline
Super Byte

Coordinator
Jun 22, 2011 at 8:48 AM
real filesystem isn't that far down the road, we're working on that...

On Tue, Jun 21, 2011 at 11:45 PM, SuperByte <notifications@codeplex.com> wrote:

From: SuperByte

Thanks exactly what i was looking for great work


On Wed, Jun 22, 2011 at 6:33 AM, civilwarrock <notifications@codeplex.com> wrote:

From: civilwarrock

I guess its kind of cool, but what would be cool is to see this kind of code running a real filesystem :) Thats a little ways down the road but ill be there when it happens. Good work blackfireize this code is quite impressive. Thanks - Matt

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

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




--
---------------------------
Jacksen Kline
Super Byte

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

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 22, 2011 at 8:50 AM

Really? Cool I cannot wait. Maybe I could help? Thanks - Matt

Coordinator
Jun 22, 2011 at 3:10 PM
On 6/22/2011 3:48 AM, mterwoord wrote:
> real filesystem isn't that far down the road, we're working on that...

Its partially working already.. what blocks it are a few bugs in the
compiler that we found. Fixing them became very difficult so now we are
upgrading a specific debugger to assist...