static void check_tree(struct rb_root *root, const char *msg)
{
- struct rb_node *new_node, *node, *next;
+ struct rb_node *node;
struct bmap_rb_extent *ext, *old = NULL;
for (node = ext2fs_rb_first(root); node;
{
struct ext2fs_rb_private *bp;
- if (new_real_end >= bmap->real_end) {
- bmap->end = new_end;
- bmap->real_end = new_real_end;
- return 0;
- }
-
bp = (struct ext2fs_rb_private *) bmap->private;
bp->rcursor = NULL;
bp->wcursor = NULL;
- /* truncate tree to new_real_end size */
- rb_truncate(new_real_end, &bp->root);
+ rb_truncate(((new_end < bmap->end) ? new_end : bmap->end) - bmap->start,
+ &bp->root);
bmap->end = new_end;
bmap->real_end = new_real_end;
+
+ if (bmap->end < bmap->real_end)
+ rb_insert_extent(bmap->end + 1 - bmap->start,
+ bmap->real_end - bmap->end, bp);
return 0;
}
__u64 new_start, new_count;
int retval = 0;
- if (EXT2FS_RB_EMPTY_ROOT(root))
+ if (ext2fs_rb_empty_root(root))
return 0;
while (*n) {
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;
/*
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) {
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)
__u64 start, __u64 end, __u64 *out)
{
struct rb_node *parent = NULL, **n;
- struct rb_node *node, *next;
struct ext2fs_rb_private *bp;
struct bmap_rb_extent *ext;
- int retval = 1;
bp = (struct ext2fs_rb_private *) bitmap->private;
n = &bp->root.rb_node;
if (start > end)
return EINVAL;
- if (EXT2FS_RB_EMPTY_ROOT(&bp->root))
+ if (ext2fs_rb_empty_root(&bp->root))
return ENOENT;
while (*n) {
__u64 start, __u64 end, __u64 *out)
{
struct rb_node *parent = NULL, **n;
- struct rb_node *node, *next;
+ struct rb_node *node;
struct ext2fs_rb_private *bp;
struct bmap_rb_extent *ext;
- int retval = 1;
bp = (struct ext2fs_rb_private *) bitmap->private;
n = &bp->root.rb_node;
if (start > end)
return EINVAL;
- if (EXT2FS_RB_EMPTY_ROOT(&bp->root))
+ if (ext2fs_rb_empty_root(&bp->root))
return ENOENT;
while (*n) {