Implement Ext2.Read_FSBlock
diff --git a/src/filo-fs-ext2.adb b/src/filo-fs-ext2.adb
index 7bd2c15..af6db70 100644
--- a/src/filo-fs-ext2.adb
+++ b/src/filo-fs-ext2.adb
@@ -33,6 +33,9 @@
FEATURE_INCOMPAT_EXTENTS : constant := 16#0040#;
FEATURE_INCOMPAT_64BIT : constant := 16#0080#;
+ -- Minimum ext2 block size is 1KiB (two 512B blocks)
+ type FSBlock_Offset is new Block_Offset range 0 .. Block_Offset'Last / 2;
+
procedure Mount
(State : in out T;
Part_Len : in Partition_Length;
@@ -127,6 +130,27 @@
State.S := Mounted;
end Mount;
+ procedure Read_FSBlock
+ (State : in T;
+ Buf : out Buffer_Type;
+ FSBlock : in FSBlock_Offset;
+ Success : out Boolean)
+ with
+ Pre =>
+ Is_Mounted (State) and
+ Buf'Length = 2 ** State.Block_Size_Bits
+ is
+ Block_Size : constant Blockdev_Length := 2 ** State.Block_Size_Bits;
+ Max_Block_Offset : constant FSBlock_Offset :=
+ FSBlock_Offset (State.Part_Len / Block_Size - 1);
+ begin
+ if FSBlock > Max_Block_Offset then
+ Success := False;
+ return;
+ end if;
+ Blockdev.Read (Buf, Blockdev_Length (FSBlock) * Block_Size, Success);
+ end Read_FSBlock;
+
procedure Open
(State : in out T;
File_Len : out File_Length;