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

use Interfaces.C;

package body FS.FILO.VFS
with
   SPARK_Mode => Off,
   Convention => C
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;
