Add NullFS
Signed-off-by: Thomas Heijligen <src@posteo.de>
diff --git a/src/filo-fs-nullfs.adb b/src/filo-fs-nullfs.adb
index dc0ca28..73195ba 100644
--- a/src/filo-fs-nullfs.adb
+++ b/src/filo-fs-nullfs.adb
@@ -1,59 +1,13 @@
+with FILO.Blockdev;
+
package body FILO.FS.NullFS is
- Global_NullFS : NullFS_Type := (
- State => Unmounted
- );
-
- procedure Mount
- (Item : in out NullFS_Type;
- Success : out Boolean)
- is
- begin
- Success := True;
- Item.State := Mounted;
- end Mount;
-
- procedure Open
- (Item : in out NullFS_Type;
- Path : in String;
- Success : out Boolean)
- is
- begin
- Success := True;
- Item.State := File_Open;
- end Open;
-
- procedure Read
- (Item : in out NullFS_Type;
- Buffer : in out Buffer_Type;
- Offset : in Natural;
- Success : out Boolean)
- is
- begin
- Success := True;
- null;
- end Read;
-
- procedure Close
- (Item : in out NullFS_Type;
- Success : out Boolean)
- is
- begin
- Success := True;
- Item.State := Mounted;
- end Close;
-
- ---------------------------------------------------------------------A
-
function To_Int (Success : Boolean) return Interfaces.C.int is
(if Success then 1 else 0);
- function C_Mount return Interfaces.C.int
- is
- Success : Boolean;
+ function C_Mount return Interfaces.C.int is
begin
- Mount(Global_NullFS, Success);
- return To_Int (Success);
+ return To_Int (True);
end C_Mount;
function C_Read
@@ -62,38 +16,26 @@
return Interfaces.C.int
with SPARK_Mode => Off
is
- use FILO.FS;
Buffer : Buffer_Type (0 .. Integer(len) - 1) with Address => buf;
- Offset : constant Natural := Natural(File_Pos);
+ Offset : constant Blockdev_Offset := Blockdev_Offset(File_Pos);
Success : Boolean;
begin
- Read (Global_NullFS, Buffer, Offset, Success);
- if Success then
- Set_File_Pos (File_Length (Offset + Buffer'Length));
- end if;
- return To_Int (Success);
-
+ FILO.Blockdev.Read (Buffer, Offset, Success);
+ return To_Int (Success);
end C_Read;
+
function C_Dir
- (Path : Interfaces.C.Strings.chars_ptr)
+ (Path : System.Address)
return Interfaces.C.int
with SPARK_Mode => Off
is
- use Interfaces.C.Strings;
- Success : Boolean;
+ First_Byte : Unsigned_8 with Address => Path;
begin
- Open (Global_NullFS, Value (Path), Success);
- return To_Int (Success);
+ if First_Byte = 0 then
+ return To_Int (True);
+ end if;
+ return To_Int (False);
end C_Dir;
- function C_Close return Interfaces.C.int
- with SPARK_Mode => Off
- is
- Success : Boolean;
- begin
- Close (Global_NullFS, Success);
- return To_Int (Success);
- end C_Close;
-
end FILO.FS.NullFS;
diff --git a/src/filo-fs-nullfs.ads b/src/filo-fs-nullfs.ads
index 5f0bd5b..95b6d16 100644
--- a/src/filo-fs-nullfs.ads
+++ b/src/filo-fs-nullfs.ads
@@ -3,38 +3,15 @@
with System;
package FILO.FS.NullFS is
- type NullFS_Type is private;
-
-
- procedure Mount
- (Item : in out NullFS_Type;
- Success : out Boolean);
-
- procedure Open
- (Item : in out NullFS_Type;
- Path : in String;
- Success : out Boolean);
-
- procedure Read
- (Item : in out NullFS_Type;
- Buffer : in out Buffer_Type;
- Offset : in Natural;
- Success : out Boolean);
-
- procedure Close
- (Item : in out NullFS_Type;
- Success : out Boolean);
-
- ---------------------------------------------------------------------
-
+ -- noop init
function C_Mount return Interfaces.C.int
with
Export,
Convention => C,
External_Name => "nullfs_mount";
- function C_Read
- (buf : System.Address;
+ function C_Read -- read from blockdev
+ (buf : System.Address; -- char*
len : Interfaces.C.int)
return Interfaces.C.int
with
@@ -42,25 +19,12 @@
Convention => C,
External_Name => "nullfs_read";
- function C_Dir
- (Path : Interfaces.C.Strings.chars_ptr)
+ function C_Dir -- noop like open
+ (Path : System.Address) -- char*
return Interfaces.C.int
with
Export,
Convention => C,
External_Name => "nullfs_dir";
- function C_Close return Interfaces.C.int
- with
- Export,
- Convention => C,
- External_Name => "nullfs_close";
-
-private
- type State_Type is (Unmounted, Mounted, File_Open);
-
- type NullFS_Type is record
- State : State_Type;
- end record;
-
end FILO.FS.NullFS;
diff --git a/src/vfs.c b/src/vfs.c
index 03e9374..f4c7851 100644
--- a/src/vfs.c
+++ b/src/vfs.c
@@ -11,6 +11,7 @@
int (*dir_func) (char *dirname);
int (*close_func) (void);
} static const fsys_table[] = {
+ { "nullfs", nullfs_mount, nullfs_read, nullfs_dir, NULL },
{ "ext2", ext2fs_mount, ext2fs_read, ext2fs_dir, NULL },
{ "iso9660", iso9660_mount, iso9660_read, iso9660_dir, NULL },
};
diff --git a/src/vfs.h b/src/vfs.h
index cff04cd..a40bb7e 100644
--- a/src/vfs.h
+++ b/src/vfs.h
@@ -28,6 +28,10 @@
void file_close(void);
+int nullfs_mount(void);
+int nullfs_read(char*, int);
+int nullfs_dir(char*);
+
int ext2fs_mount(void);
int ext2fs_read(char *buf, int len);
int ext2fs_dir(char *path);