ext2: Use a more generic cache index
diff --git a/src/filo-fs-ext2.adb b/src/filo-fs-ext2.adb
index aeff958..46cd4cc 100644
--- a/src/filo-fs-ext2.adb
+++ b/src/filo-fs-ext2.adb
@@ -169,19 +169,18 @@
       with
          Pre => FSBlock_Logical (Addr_In_Block) < Addr_Per_Block
       is
-         -- Limit cache usage in case of incredibly huge block size:
+         -- 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 :=
-           (if    State.Block_Size_Bits > 15                   then Any
-            elsif State.Block_Size_Bits > 14 and Level > Any   then Last_Level
-                                                               else Level);
-         Cache_Index : constant Index_Type :=
-            Block_Cache_Index'Pos (Cache_Level) * Block_Size;
-         Cache_End : constant Index_Type := Cache_Index + Block_Size - 1;
+            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;
       begin
          if State.Block_Cache_Index (Cache_Level) /= Logical_Off then
             Read_FSBlock
               (State    => State,
-               Buf      => State.Block_Cache (Cache_Index .. Cache_End),
+               Buf      => State.Block_Cache (Cache_Start .. Cache_End),
                FSBlock  => Indirect_Block_Phys,
                Success  => Success);
             State.Block_Cache_Index (Cache_Level) := Logical_Off;
@@ -191,7 +190,7 @@
          end if;
 
          Next_Physical := FSBlock_Offset (Read_LE32
-           (Buf => State.Block_Cache (Cache_Index .. Cache_End),
+           (Buf => State.Block_Cache (Cache_Start .. Cache_End),
             Off => Natural (Addr_In_Block) * 4));
          Success := True;
       end Indirect_Block_Lookup;
@@ -209,7 +208,7 @@
          Indirect_Block_Lookup
            (Indirect_Block_Phys  => FSBlock_Offset (State.Indirect_Block),
             Addr_In_Block        => Addr_In_Block_Range (Logical_Rest),
-            Level                => Last_Level,
+            Level                => 0,
             Logical_Off          => Logical - Logical_Rest,
             Next_Physical        => Physical,
             Success              => Success);
@@ -221,7 +220,7 @@
          Indirect_Block_Lookup
            (Indirect_Block_Phys  => FSBlock_Offset (State.Double_Indirect),
             Addr_In_Block        => Addr_In_Block_Range (Logical_Rest / Addr_Per_Block),
-            Level                => Second_Last_Level,
+            Level                => 1,
             Logical_Off          => Logical - Logical_Rest,
             Next_Physical        => Physical,
             Success              => Success);
@@ -232,7 +231,7 @@
          Indirect_Block_Lookup
            (Indirect_Block_Phys  => Physical,
             Addr_In_Block        => Addr_In_Block_Range (Logical_Rest mod Addr_Per_Block),
-            Level                => Last_Level,
+            Level                => 0,
             Logical_Off          => Logical - (Logical_Rest mod Addr_Per_Block),
             Next_Physical        => Physical,
             Success              => Success);
@@ -244,7 +243,7 @@
          Indirect_Block_Lookup
            (Indirect_Block_Phys  => FSBlock_Offset (State.Triple_Indirect),
             Addr_In_Block        => Addr_In_Block_Range (Logical_Rest / Addr_Per_Block ** 2),
-            Level                => First_Level,
+            Level                => 2,
             Logical_Off          => Logical - Logical_Rest,
             Next_Physical        => Physical,
             Success              => Success);
@@ -255,7 +254,7 @@
          Indirect_Block_Lookup
            (Indirect_Block_Phys  => Physical,
             Addr_In_Block        => Addr_In_Block_Range (Logical_Rest / Addr_Per_Block mod Addr_Per_Block),
-            Level                => Second_Last_Level,
+            Level                => 1,
             Logical_Off          => Logical - (Logical_Rest mod Addr_Per_Block ** 2),
             Next_Physical        => Physical,
             Success              => Success);
@@ -266,7 +265,7 @@
          Indirect_Block_Lookup
            (Indirect_Block_Phys  => Physical,
             Addr_In_Block        => Addr_In_Block_Range (Logical_Rest mod Addr_Per_Block),
-            Level                => Last_Level,
+            Level                => 0,
             Logical_Off          => Logical - (Logical_Rest mod Addr_Per_Block),
             Next_Physical        => Physical,
             Success              => Success);