Fiemap: fix get_(un)mapped_ranges for file parts
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Wed, 28 Nov 2012 13:27:44 +0000 (15:27 +0200)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Wed, 28 Nov 2012 15:15:20 +0000 (17:15 +0200)
The functions worked incorrectly when the ranges were requested for part of the
file. Fix this.

Change-Id: Ib979c06a05dcbad1825b98199d23441d236fe5e4
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
bmaptools/Fiemap.py

index 8144903..a5b3735 100644 (file)
@@ -205,8 +205,11 @@ class Fiemap:
                 assert extent_start % self.block_size == 0
                 assert extent_len % self.block_size == 0
 
+                if extent_block > start + count - 1:
+                    return
+
                 first = max(extent_block, block)
-                last = first + min(extent_count, count) - 1
+                last = min(extent_block + extent_count, start + count) - 1
                 yield (first, last)
 
                 extent += 1