]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
Make extent_goto() deterministic when logical block not found
authorEric Sandeen <sandeen@redhat.com>
Tue, 8 Apr 2008 03:00:59 +0000 (22:00 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 17 Apr 2008 21:16:39 +0000 (17:16 -0400)
Make sure that extent_goto() leaves us at the last extent
prior to the requested logical block, if the logical block
requested lands in a hole.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/extent.c

index 9f19e7b614a44c5517752f689286ed5dbcf300f0..e7b7e855602b357b24a634f440b98e7e1e60372a 100644 (file)
@@ -553,6 +553,12 @@ errcode_t ext2fs_extent_free_path(ext2_extent_path_t path)
 }
 #endif
 
+/*
+ * Go to the node at leaf_level which contains logical block blk.
+ *
+ * If "blk" has no mapping (hole) then handle is left at last
+ * extent before blk.
+ */
 static errcode_t extent_goto(ext2_extent_handle_t handle,
                             int leaf_level, blk64_t blk)
 {
@@ -566,11 +572,16 @@ static errcode_t extent_goto(ext2_extent_handle_t handle,
        dbg_print_extent("root", &extent);
        while (1) {
                if (handle->level - leaf_level == handle->max_depth) {
+                       /* block is in this &extent */
                        if ((blk >= extent.e_lblk) &&
                            (blk < extent.e_lblk + extent.e_len))
                                return 0;
-                       if (blk < extent.e_lblk)
+                       if (blk < extent.e_lblk) {
+                               retval = ext2fs_extent_get(handle,
+                                                          EXT2_EXTENT_PREV_SIB,
+                                                          &extent);
                                return EXT2_ET_EXTENT_NOT_FOUND;
+                       }
                        retval = ext2fs_extent_get(handle,
                                                   EXT2_EXTENT_NEXT_SIB,
                                                   &extent);