Move fs-filo to filo-fs
Signed-off-by: Thomas Heijligen <src@posteo.de>
diff --git a/src/filo-fs-vfs.adb b/src/filo-fs-vfs.adb
new file mode 100644
index 0000000..838cddf
--- /dev/null
+++ b/src/filo-fs-vfs.adb
@@ -0,0 +1,65 @@
+with Interfaces.C;
+with Interfaces.C.Strings;
+
+use Interfaces.C;
+
+package body FILO.FS.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.FS.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 FILO.FS.VFS;