with Interfaces.C;
with Interfaces.C.Strings;

use Interfaces.C;

package body FS.FILO.VFS
with
   SPARK_Mode => Off
is

   State : T := Initial;

   function C_Mount return int
   is
      Success : Boolean;
   begin
      if not Is_Mounted (State) then
         State := Initial; -- Work around not having an unmount in FILO.
      end if;
      Mount (State, Part_Len, Success);
      return (if Success then 1 else 0);
   end C_Mount;

   function C_Open (File_Path : Strings.chars_ptr) return int
   is
      File_Len : File_Length;
      Success : Boolean;
   begin
      if Is_Mounted (State) and not Is_Open (State) then
         Open (State, File_Len, Strings.Value (File_Path), Success);
         Set_File_Max (File_Len);
      else
         Success := False;
      end if;
      return (if Success then 1 else 0);
   end C_Open;

   procedure C_Close is
   begin
      if Is_Open (State) then
         Close (State);
      end if;
   end C_Close;
   
   function C_Read (Buf : System.Address; Len : int) return int
   is
      subtype Buffer_Range is Natural range 0 .. Integer (Len) - 1;
      Buffer : Buffer_Type (Buffer_Range)
      with
         Convention => C,
         Address => Buf;

      File_Pos : File_Offset := FILO.File_Pos;
      Read_Len : Natural;
   begin
      if Is_Open (State) then
         Read (State, File_Max, File_Pos, Buffer, Read_Len);
         Set_File_Pos (File_Pos);
      else
         Read_Len := 0;
      end if;
      return int (Read_Len);
   end C_Read;

end FS.FILO.VFS;
