The Wayback Machine - https://web.archive.org/web/20190415043255/https://github.com/CosmosOS/Cosmos/wiki/FAT-FileSystem
Skip to content

FAT FileSystem

Rudra Saraswat edited this page Jul 27, 2018 · 9 revisions

File Allocation Table (FAT) is a computer file system architecture and a family of industry-standard file systems utilizing it. The FAT file system is a legacy file system which is simple and robust. It offers good performance even in light-weight implementations, but cannot deliver the same performance, reliability and scalability as some modern file systems. It is, however, supported for compatibility reasons by nearly all currently developed operating systems for personal computers and many mobile devices and embedded systems, and thus is a well-suited format for data exchange between computers and devices of almost any type and age from 1981 up to the present.

Referenced from File Allocation Table
FAT types are:

  • FAT12
  • FAT16
  • FAT32
  • ExFAT (Not supported by Cosmos)

FAT is under construction, and there are definitely issues right now, but here's how to set it up:

Cosmos is currently working on FAT. Almost done.

Using FAT

Initiating the FAT driver

First you want to initiate the FAT driver so that Cosmos can get an idea of the filesystems on the PC. This will also make it so that most things in System.IO will work.

To initiate the driver, add this to your kernel's BeforeRun():

var fs = new Sys.FileSystem.CosmosVFS();
Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);

Now you're able to do the following:

Read from a file

public string[] ReadLines(string FileAdr) //Returns the lines of text in string[].
{
     string[] FileRead;
     FileRead = File.ReadAllLines(FileAdr);
     return FileRead;
}

public string ReadText(string FileAddr) //Returns the file in a single string.
{
    string f_contents = "";
    f_contents = File.ReadAllText(FileAddr);
    return f_contents;
}

public byte[] ReadByte(string FileAdr) //Returns the read file in bytes.
{
     byte[] FileRead;
     FileRead = File.ReadAllBytes(FileAdr);
     return FileRead;
}

Getting all files and folders from address

public string[] GetFsFadr(string Adr) // Get Files From Address
{
    string[] Files = new string[256];
    if (Directory.GetFiles(Adr).Length > 0)
        Files = Directory.GetFiles(Adr);
    else
        Files[0] = "No files found.";
    return Files;
 }
public string[] GetDirFadr(string Adr) // Get Directories From Address
{
    var Dirs = Directory.GetDirectories(Adr);
    return Dirs;
}

Other System.IO methods

You can use most System.IO methods (File.WriteAllText(), Directory.CreateDirectory(), etc), and it should be straightforward to set up. The above methods prove that it's just as simple in Cosmos to access the filesystem as in normal .NET, besides the fact that you have to initiate the FAT driver first in Cosmos.

Warnings!

  • Path styles: Cosmos uses a DOS-like path style, where each filesystem has it's own drive letter. However, in Cosmos, drive letters are numeric and zero-based, i.e, the first filesystem will be 0:.
  • No GPT or USB support: Cosmos' FAT driver doesn't support GPT partition schemes, so, if you have a FAT partition set up on your PC's hard drive, and Cosmos doesn't automatically pick it up, your drive has a GPT partition scheme, and there is nothing you can do about it unless you want to reinstall your main OS, and say goodbye to everything on the drive. Cosmos also does not support USB, so you can't just plug in a flash-drive and have it recognized. This is because there are multiple interfaces and different versions of each to interact with USB and it's a bit complicated.
  • DON'T USE THIS ON REAL HARDWARE. IT COULD DAMAGE ALL YOUR DATA, FILES AND OTHER. BETTER USE VMWARE OR BOCHS, MOST EFFICENT AND SAFEST WAYS TO DEBUG AND ENJOY YOUR OS.

If you cannot compile because it cannot find FAT, install the DevKit.

You can’t perform that action at this time.