]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - lib/ext2fs/blkmap64_rb.c
Merge branch 'old-maint' into maint
[thirdparty/e2fsprogs.git] / lib / ext2fs / blkmap64_rb.c
index 7964fdb8c54356e49af6bb367fc54f183b268822..1fd552745b02abd9c19c670f55d565cdbf91b06a 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"
@@ -70,15 +74,15 @@ static void print_tree(struct rb_root *root)
        struct rb_node *node = NULL;
        struct bmap_rb_extent *ext;
 
-       printf("\t\t\t=================================\n");
+       fprintf(stderr, "\t\t\t=================================\n");
        node = ext2fs_rb_first(root);
        for (node = ext2fs_rb_first(root); node != NULL; 
             node = ext2fs_rb_next(node)) {
                ext = node_to_extent(node);
-               printf("\t\t\t--> (%llu -> %llu)\n",
+               fprintf(stderr, "\t\t\t--> (%llu -> %llu)\n",
                        ext->start, ext->start + ext->count);
        }
-       printf("\t\t\t=================================\n");
+       fprintf(stderr, "\t\t\t=================================\n");
 }
 
 static void check_tree(struct rb_root *root, const char *msg)
@@ -90,35 +94,41 @@ static void check_tree(struct rb_root *root, const char *msg)
             node = ext2fs_rb_next(node)) {
                ext = node_to_extent(node);
                if (ext->count == 0) {
-                       printf("Tree Error: count is zero\n");
-                       printf("extent: %llu -> %llu (%llu)\n", ext->start,
-                               ext->start + ext->count, ext->count);
+                       fprintf(stderr, "Tree Error: count is zero\n");
+                       fprintf(stderr, "extent: %llu -> %llu (%llu)\n",
+                               ext->start, ext->start + ext->count,
+                               ext->count);
                        goto err_out;
                }
                if (ext->start + ext->count < ext->start) {
-                       printf("Tree Error: start or count is crazy\n");
-                       printf("extent: %llu -> %llu (%llu)\n", ext->start,
-                               ext->start + ext->count, ext->count);
+                       fprintf(stderr,
+                               "Tree Error: start or count is crazy\n");
+                       fprintf(stderr, "extent: %llu -> %llu (%llu)\n",
+                               ext->start, ext->start + ext->count,
+                               ext->count);
                        goto err_out;
                }
 
                if (old) {
                        if (old->start > ext->start) {
-                               printf("Tree Error: start is crazy\n");
-                               printf("extent: %llu -> %llu (%llu)\n",
+                               fprintf(stderr, "Tree Error: start is crazy\n");
+                               fprintf(stderr, "extent: %llu -> %llu (%llu)\n",
                                        old->start, old->start + old->count,
                                        old->count);
-                               printf("extent next: %llu -> %llu (%llu)\n",
+                               fprintf(stderr,
+                                       "extent next: %llu -> %llu (%llu)\n",
                                        ext->start, ext->start + ext->count,
                                        ext->count);
                                goto err_out;
                        }
                        if ((old->start + old->count) >= ext->start) {
-                               printf("Tree Error: extent is crazy\n");
-                               printf("extent: %llu -> %llu (%llu)\n",
+                               fprintf(stderr,
+                                       "Tree Error: extent is crazy\n");
+                               fprintf(stderr, "extent: %llu -> %llu (%llu)\n",
                                        old->start, old->start + old->count,
                                        old->count);
-                               printf("extent next: %llu -> %llu (%llu)\n",
+                               fprintf(stderr,
+                                       "extent next: %llu -> %llu (%llu)\n",
                                        ext->start, ext->start + ext->count,
                                        ext->count);
                                goto err_out;
@@ -129,7 +139,7 @@ static void check_tree(struct rb_root *root, const char *msg)
        return;
 
 err_out:
-       printf("%s\n", msg);
+       fprintf(stderr, "%s\n", msg);
        print_tree(root);
        exit(1);
 }
@@ -167,7 +177,7 @@ static void rb_free_extent(struct ext2fs_rb_private *bp,
        ext2fs_free_mem(&ext);
 }
 
-static errcode_t rb_alloc_private_data (ext2fs_generic_bitmap bitmap)
+static errcode_t rb_alloc_private_data (ext2fs_generic_bitmap_64 bitmap)
 {
        struct ext2fs_rb_private *bp;
        errcode_t       retval;
@@ -191,7 +201,7 @@ static errcode_t rb_alloc_private_data (ext2fs_generic_bitmap bitmap)
 }
 
 static errcode_t rb_new_bmap(ext2_filsys fs EXT2FS_ATTR((unused)),
-                            ext2fs_generic_bitmap bitmap)
+                            ext2fs_generic_bitmap_64 bitmap)
 {
        errcode_t       retval;
 
@@ -215,7 +225,7 @@ static void rb_free_tree(struct rb_root *root)
        }
 }
 
-static void rb_free_bmap(ext2fs_generic_bitmap bitmap)
+static void rb_free_bmap(ext2fs_generic_bitmap_64 bitmap)
 {
        struct ext2fs_rb_private *bp;
 
@@ -226,8 +236,8 @@ static void rb_free_bmap(ext2fs_generic_bitmap bitmap)
        bp = 0;
 }
 
-static errcode_t rb_copy_bmap(ext2fs_generic_bitmap src,
-                             ext2fs_generic_bitmap dest)
+static errcode_t rb_copy_bmap(ext2fs_generic_bitmap_64 src,
+                             ext2fs_generic_bitmap_64 dest)
 {
        struct ext2fs_rb_private *src_bp, *dest_bp;
        struct bmap_rb_extent *src_ext, *dest_ext;
@@ -292,7 +302,7 @@ static void rb_truncate(__u64 new_max, struct rb_root *root)
        }
 }
 
-static errcode_t rb_resize_bmap(ext2fs_generic_bitmap bmap,
+static errcode_t rb_resize_bmap(ext2fs_generic_bitmap_64 bmap,
                                __u64 new_end, __u64 new_real_end)
 {
        struct ext2fs_rb_private *bp;
@@ -387,6 +397,9 @@ static int rb_insert_extent(__u64 start, __u64 count,
        struct bmap_rb_extent *ext;
        int retval = 0;
 
+       if (count == 0)
+               return 0;
+
        bp->rcursor_next = NULL;
        ext = bp->wcursor;
        if (ext) {
@@ -488,7 +501,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 +564,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;
@@ -562,7 +575,7 @@ static int rb_remove_extent(__u64 start, __u64 count,
        return retval;
 }
 
-static int rb_mark_bmap(ext2fs_generic_bitmap bitmap, __u64 arg)
+static int rb_mark_bmap(ext2fs_generic_bitmap_64 bitmap, __u64 arg)
 {
        struct ext2fs_rb_private *bp;
        int retval;
@@ -575,7 +588,7 @@ static int rb_mark_bmap(ext2fs_generic_bitmap bitmap, __u64 arg)
        return retval;
 }
 
-static int rb_unmark_bmap(ext2fs_generic_bitmap bitmap, __u64 arg)
+static int rb_unmark_bmap(ext2fs_generic_bitmap_64 bitmap, __u64 arg)
 {
        struct ext2fs_rb_private *bp;
        int retval;
@@ -590,7 +603,7 @@ static int rb_unmark_bmap(ext2fs_generic_bitmap bitmap, __u64 arg)
 }
 
 inline
-static int rb_test_bmap(ext2fs_generic_bitmap bitmap, __u64 arg)
+static int rb_test_bmap(ext2fs_generic_bitmap_64 bitmap, __u64 arg)
 {
        struct ext2fs_rb_private *bp;
 
@@ -600,7 +613,7 @@ static int rb_test_bmap(ext2fs_generic_bitmap bitmap, __u64 arg)
        return rb_test_bit(bp, arg);
 }
 
-static void rb_mark_bmap_extent(ext2fs_generic_bitmap bitmap, __u64 arg,
+static void rb_mark_bmap_extent(ext2fs_generic_bitmap_64 bitmap, __u64 arg,
                                unsigned int num)
 {
        struct ext2fs_rb_private *bp;
@@ -612,7 +625,7 @@ static void rb_mark_bmap_extent(ext2fs_generic_bitmap bitmap, __u64 arg,
        check_tree(&bp->root, __func__);
 }
 
-static void rb_unmark_bmap_extent(ext2fs_generic_bitmap bitmap, __u64 arg,
+static void rb_unmark_bmap_extent(ext2fs_generic_bitmap_64 bitmap, __u64 arg,
                                  unsigned int num)
 {
        struct ext2fs_rb_private *bp;
@@ -624,7 +637,7 @@ static void rb_unmark_bmap_extent(ext2fs_generic_bitmap bitmap, __u64 arg,
        check_tree(&bp->root, __func__);
 }
 
-static int rb_test_clear_bmap_extent(ext2fs_generic_bitmap bitmap,
+static int rb_test_clear_bmap_extent(ext2fs_generic_bitmap_64 bitmap,
                                     __u64 start, unsigned int len)
 {
        struct rb_node *parent = NULL, **n;
@@ -637,7 +650,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;
 
        /*
@@ -680,7 +693,7 @@ static int rb_test_clear_bmap_extent(ext2fs_generic_bitmap bitmap,
        return retval;
 }
 
-static errcode_t rb_set_bmap_range(ext2fs_generic_bitmap bitmap,
+static errcode_t rb_set_bmap_range(ext2fs_generic_bitmap_64 bitmap,
                                     __u64 start, size_t num, void *in)
 {
        struct ext2fs_rb_private *bp;
@@ -726,7 +739,7 @@ static errcode_t rb_set_bmap_range(ext2fs_generic_bitmap bitmap,
        return 0;
 }
 
-static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap,
+static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap_64 bitmap,
                                     __u64 start, size_t num, void *out)
 {
 
@@ -739,7 +752,7 @@ static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap,
        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) {
@@ -791,7 +804,7 @@ static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap,
        return 0;
 }
 
-static void rb_clear_bmap(ext2fs_generic_bitmap bitmap)
+static void rb_clear_bmap(ext2fs_generic_bitmap_64 bitmap)
 {
        struct ext2fs_rb_private *bp;
 
@@ -804,7 +817,7 @@ static void rb_clear_bmap(ext2fs_generic_bitmap bitmap)
        check_tree(&bp->root, __func__);
 }
 
-static errcode_t rb_find_first_zero(ext2fs_generic_bitmap bitmap,
+static errcode_t rb_find_first_zero(ext2fs_generic_bitmap_64 bitmap,
                                   __u64 start, __u64 end, __u64 *out)
 {
        struct rb_node *parent = NULL, **n;
@@ -819,7 +832,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) {
@@ -840,7 +853,7 @@ static errcode_t rb_find_first_zero(ext2fs_generic_bitmap bitmap,
        return 0;
 }
 
-static errcode_t rb_find_first_set(ext2fs_generic_bitmap bitmap,
+static errcode_t rb_find_first_set(ext2fs_generic_bitmap_64 bitmap,
                                   __u64 start, __u64 end, __u64 *out)
 {
        struct rb_node *parent = NULL, **n;
@@ -856,7 +869,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) {
@@ -889,7 +902,7 @@ static errcode_t rb_find_first_set(ext2fs_generic_bitmap bitmap,
 }
 
 #ifdef ENABLE_BMAP_STATS
-static void rb_print_stats(ext2fs_generic_bitmap bitmap)
+static void rb_print_stats(ext2fs_generic_bitmap_64 bitmap)
 {
        struct ext2fs_rb_private *bp;
        struct rb_node *node = NULL;
@@ -950,7 +963,7 @@ static void rb_print_stats(ext2fs_generic_bitmap bitmap)
                eff);
 }
 #else
-static void rb_print_stats(ext2fs_generic_bitmap bitmap EXT2FS_ATTR((unused)))
+static void rb_print_stats(ext2fs_generic_bitmap_64 bitmap EXT2FS_ATTR((unused)))
 {
 }
 #endif