]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - lib/ext2fs/blkmap64_rb.c
Merge branch 'maint' into next
[thirdparty/e2fsprogs.git] / lib / ext2fs / blkmap64_rb.c
index 8d1778d61892970b2583749b00948622c15fc530..557047749d55a76cb8ca69146864945efa10c7a6 100644 (file)
@@ -9,6 +9,7 @@
  * %End-Header%
  */
 
+#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #if HAVE_UNISTD_H
@@ -22,6 +23,9 @@
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
+#if HAVE_LINUX_TYPES_H
+#include <linux/types.h>
+#endif
 
 #include "ext2_fs.h"
 #include "ext2fsP.h"
@@ -488,7 +492,7 @@ static int rb_remove_extent(__u64 start, __u64 count,
        __u64 new_start, new_count;
        int retval = 0;
 
-       if (EXT2FS_RB_EMPTY_ROOT(root))
+       if (ext2fs_rb_empty_root(root))
                return 0;
 
        while (*n) {
@@ -551,7 +555,7 @@ static int rb_remove_extent(__u64 start, __u64 count,
                        retval = 1;
                        continue;
                } else {
-                       /* modify the last extent in reigon to be removed */
+                       /* modify the last extent in region to be removed */
                        ext->count -= ((start + count) - ext->start);
                        ext->start = start + count;
                        retval = 1;
@@ -637,7 +641,7 @@ static int rb_test_clear_bmap_extent(ext2fs_generic_bitmap bitmap,
        n = &bp->root.rb_node;
        start -= bitmap->start;
 
-       if ((len == 0) || EXT2FS_RB_EMPTY_ROOT(&bp->root))
+       if (len == 0 || ext2fs_rb_empty_root(&bp->root))
                return 1;
 
        /*
@@ -733,14 +737,13 @@ static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap,
        struct rb_node *parent = NULL, *next, **n;
        struct ext2fs_rb_private *bp;
        struct bmap_rb_extent *ext;
-       int count;
-       __u64 pos;
+       __u64 count, pos;
 
        bp = (struct ext2fs_rb_private *) bitmap->private;
        n = &bp->root.rb_node;
        start -= bitmap->start;
 
-       if (EXT2FS_RB_EMPTY_ROOT(&bp->root))
+       if (ext2fs_rb_empty_root(&bp->root))
                return 0;
 
        while (*n) {
@@ -765,9 +768,9 @@ static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap,
                if (pos >= start + num)
                        break;
                if (pos < start) {
-                       count -= start - pos;
-                       if (count < 0)
+                       if (pos + count <  start)
                                continue;
+                       count -= start - pos;
                        pos = start;
                }
                if (pos + count > start + num)
@@ -820,7 +823,7 @@ static errcode_t rb_find_first_zero(ext2fs_generic_bitmap bitmap,
        if (start > end)
                return EINVAL;
 
-       if (EXT2FS_RB_EMPTY_ROOT(&bp->root))
+       if (ext2fs_rb_empty_root(&bp->root))
                return ENOENT;
 
        while (*n) {
@@ -857,7 +860,7 @@ static errcode_t rb_find_first_set(ext2fs_generic_bitmap bitmap,
        if (start > end)
                return EINVAL;
 
-       if (EXT2FS_RB_EMPTY_ROOT(&bp->root))
+       if (ext2fs_rb_empty_root(&bp->root))
                return ENOENT;
 
        while (*n) {