ext2: Extract Cache_FSBlock procedure
diff --git a/src/filo-fs-ext2.adb b/src/filo-fs-ext2.adb
index 46cd4cc..d0f91cb 100644
--- a/src/filo-fs-ext2.adb
+++ b/src/filo-fs-ext2.adb
@@ -148,6 +148,38 @@
Blockdev.Read (Buf, Blockdev_Length (FSBlock) * Block_Size, Success);
end Read_FSBlock;
+ procedure Cache_FSBlock
+ (State : in out T;
+ Phys : in FSBlock_Offset;
+ Level : in Block_Cache_Index;
+ Logical_Off : in FSBlock_Logical;
+ Cache_Start : out Max_Block_Index;
+ Cache_End : out Max_Block_Index;
+ Success : out Boolean)
+ with
+ Post => Cache_End = Cache_Start + 2 ** State.Block_Size_Bits
+ is
+ Block_Size : constant Natural := 2 ** State.Block_Size_Bits;
+ -- Limit cache usage depending on block size:
+ Max_Level : constant Block_Cache_Index :=
+ 2 ** (Log_Block_Size'Last - State.Block_Size_Bits) - 1;
+ Cache_Level : constant Block_Cache_Index :=
+ Block_Cache_Index'Min (Level, Max_Level);
+ begin
+ Cache_Start := Cache_Level * Block_Size;
+ Cache_End := Cache_Start + Block_Size - 1;
+ if State.Block_Cache_Index (Cache_Level) = Logical_Off then
+ Success := True;
+ else
+ Read_FSBlock
+ (State => State,
+ Buf => State.Block_Cache (Cache_Start .. Cache_End),
+ FSBlock => Phys,
+ Success => Success);
+ State.Block_Cache_Index (Cache_Level) := Logical_Off;
+ end if;
+ end Cache_FSBlock;
+
procedure Ext2_Block_Map
(State : in out T;
Logical : in FSBlock_Logical;
@@ -169,30 +201,19 @@
with
Pre => FSBlock_Logical (Addr_In_Block) < Addr_Per_Block
is
- -- Limit cache usage depending on block size:
- Max_Level : constant Block_Cache_Index :=
- 2 ** (Log_Block_Size'Last - State.Block_Size_Bits) - 1;
- Cache_Level : constant Block_Cache_Index :=
- Block_Cache_Index'Min (Level, Max_Level);
- Cache_Start : constant Index_Type := Cache_Level * Block_Size;
- Cache_End : constant Index_Type := Cache_Start + Block_Size - 1;
+ Cache_Start, Cache_End : Max_Block_Index;
begin
- if State.Block_Cache_Index (Cache_Level) /= Logical_Off then
- Read_FSBlock
- (State => State,
- Buf => State.Block_Cache (Cache_Start .. Cache_End),
- FSBlock => Indirect_Block_Phys,
- Success => Success);
- State.Block_Cache_Index (Cache_Level) := Logical_Off;
- if not Success then
- return;
- end if;
- end if;
-
+ Cache_FSBlock
+ (State => State,
+ Phys => Indirect_Block_Phys,
+ Level => Level,
+ Logical_Off => Logical_Off,
+ Cache_Start => Cache_Start,
+ Cache_End => Cache_End,
+ Success => Success);
Next_Physical := FSBlock_Offset (Read_LE32
(Buf => State.Block_Cache (Cache_Start .. Cache_End),
Off => Natural (Addr_In_Block) * 4));
- Success := True;
end Indirect_Block_Lookup;
Logical_Rest : FSBlock_Logical := Logical;