How do you use the Cosmos.System.Filesystem.FAT library to read a file?

Topics: Other, Using Cosmos (Developing your own OS, projects, etc)
Developer
Feb 11, 2013 at 6:07 PM
Edited Feb 11, 2013 at 6:08 PM
At the moment I have code to list all the files in the root directory but beyond there I am stumped.
        Cosmos.System.Filesystem.FAT.FatFileSystem fs = new Cosmos.System.Filesystem.FAT.FatFileSystem(Cosmos.Hardware.BlockDevice.BlockDevice.Devices[pn]);
        Console.WriteLine("Well we've successfully made a FAT filesystem on that partition! Exciting, non? Lets see if we can list these files...");
        for (int i = 0; i < fs.GetRoot().Count; i++)
        {
           Console.WriteLine(fs.GetRoot()[i].Name + ", " + (uint)fs.GetRoot()[i].Size);
        }
This doesn't work, all it returns is null values, I have fixed the AtaPio.ReadBlock method so it isn't that, I just don't think I'm using the library correctly:
                Cosmos.System.Filesystem.FAT.Listing.FatFile file = new Cosmos.System.Filesystem.FAT.Listing.FatFile(fs, fs.GetRoot()[i].Name, (uint)fs.GetRoot()[i].Size, 0);
                Cosmos.System.Filesystem.FAT.FatStream reader = new Cosmos.System.Filesystem.FAT.FatStream(file);
                Console.WriteLine("File Contents [");
                byte[] fileb = new byte[file.Size];
                reader.Read(fileb, 0, (int)file.Size);
                for (int j = 0; j < fileb.Length; j++)
                {
                    Console.Write(fileb[j].ToString() + " , ");
                }
                Console.WriteLine("]");
Any help would be appreciated!
Coordinator
Feb 11, 2013 at 6:17 PM
<p dir="ltr">What cosmos version are you using? </p> <div>Op 11 feb. 2013 20:07 schreef &quot;melikesPCcheese&quot; &lt;<a href="mailto:notifications@codeplex.com">notifications@codeplex.com</a>&gt; het volgende:<br type="attribution"> <blockquote style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex"> <div> <p>From: melikesPCcheese</p> <div>At the moment I have code to list all the files in the root directory but beyond there I am stumped.<br> <pre><code> Cosmos.System.Filesystem.FAT.FatFileSystem fs = new Cosmos.System.Filesystem.FAT.FatFileSystem(Cosmos.Hardware.BlockDevice.BlockDevice.Devices[pn]); Console.WriteLine(&quot;Well we've successfully made a FAT filesystem on that partition! Exciting, non? Lets see if we can list these files...&quot;); for (int i = 0; i &lt; fs.GetRoot().Count; i&#43;&#43;) { Console.WriteLine(fs.GetRoot()[i].Name &#43; &quot;, &quot; &#43; (uint)fs.GetRoot()[i].Size); } </code></pre> This doesn't work, all it returns is null values, I have fixed the ATA.ReadBlock method so it isn't that, I just don't think I'm using the library correctly:<br> <pre><code> Cosmos.System.Filesystem.FAT.Listing.FatFile file = new Cosmos.System.Filesystem.FAT.Listing.FatFile(fs, fs.GetRoot()[i].Name, (uint)fs.GetRoot()[i].Size, 0); Cosmos.System.Filesystem.FAT.FatStream reader = new Cosmos.System.Filesystem.FAT.FatStream(file); Console.WriteLine(&quot;File Contents [&quot;); byte[] fileb = new byte[file.Size]; reader.Read(fileb, 0, (int)file.Size); for (int j = 0; j &lt; fileb.Length; j&#43;&#43;) { Console.Write(fileb[j].ToString() &#43; &quot; , &quot;); } Console.WriteLine(&quot;]&quot;);</code></pre> </div> <div> <p>Read the <a href="http://cosmos.codeplex.com/discussions/432739#post999677" target="_blank"> full discussion online</a>.</p> <p>To add a post to this discussion, reply to this email (<a href="mailto:Cosmos@discussions.codeplex.com?subject=[Cosmos:432739]" target="_blank">Cosmos@discussions.codeplex.com</a>)</p> <p>To start a new discussion for this project, email <a href="mailto:Cosmos@discussions.codeplex.com" target="_blank"> Cosmos@discussions.codeplex.com</a></p> <p>You are receiving this email because you subscribed to this discussion on CodePlex. You can <a href="https://cosmos.codeplex.com/subscriptions/thread/project/edit" target="_blank"> unsubscribe or change your settings</a> on codePlex.com.</p> <p>Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at <a href="http://codeplex.com" target="_blank">codeplex.com</a></p> </div> </div> </blockquote> </div>
Developer
Feb 11, 2013 at 6:19 PM
The latest userkit with a plugged AtaPio.Readblock method. But I haven't got a clue on how it works seeing as there is no documentation or examples for it.
Coordinator
Feb 13, 2013 at 11:48 AM
On 2/11/2013 3:20 PM, melikesPCcheese wrote:<br>
> The latest userkit with a plugged AtaPio.Readblock method. But I haven't<br>
> got a clue on how it works seeing as there is no documentation or<br>
> examples for it.<br>
<br>
Look at my PG, but there is a compiler bug that will hit you...
Developer
Feb 13, 2013 at 5:03 PM
I have worked around that by plugging the ATAPio class with itself plus a little code of my own that checks the returned values to see if they match and it keeps trying until it gets values that are the same a couple of times over. I just couldn't work the classes for FAT. I might do some /// intellisense documentation if it works.