* Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
*
* %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
* %End-Header%
*/
+#include "config.h"
#include <stdio.h>
#include <string.h>
#if HAVE_UNISTD_H
ctx->bcount += limit;
return ret;
}
- if (*ind_block >= ctx->fs->super->s_blocks_count ||
+ if (*ind_block >= ext2fs_blocks_count(ctx->fs->super) ||
*ind_block < ctx->fs->super->s_first_data_block) {
ctx->errcode = EXT2_ET_BAD_IND_BLOCK;
ret |= BLOCK_ERROR;
} else {
for (i = 0; i < limit; i++, ctx->bcount++, block_nr++) {
if (*block_nr == 0)
- continue;
+ goto skip_sparse;
blk64 = *block_nr;
flags = (*ctx->func)(ctx->fs, &blk64, ctx->bcount,
*ind_block, offset,
ret |= BLOCK_ABORT;
break;
}
+ skip_sparse:
offset += sizeof(blk_t);
}
}
ctx->bcount += limit*limit;
return ret;
}
- if (*dind_block >= ctx->fs->super->s_blocks_count ||
+ if (*dind_block >= ext2fs_blocks_count(ctx->fs->super) ||
*dind_block < ctx->fs->super->s_first_data_block) {
ctx->errcode = EXT2_ET_BAD_DIND_BLOCK;
ret |= BLOCK_ERROR;
ctx->bcount += limit*limit*limit;
return ret;
}
- if (*tind_block >= ctx->fs->super->s_blocks_count ||
+ if (*tind_block >= ext2fs_blocks_count(ctx->fs->super) ||
*tind_block < ctx->fs->super->s_first_data_block) {
ctx->errcode = EXT2_ET_BAD_TIND_BLOCK;
ret |= BLOCK_ERROR;
if (inode.i_flags & EXT4_EXTENTS_FL) {
ext2_extent_handle_t handle;
- struct ext2fs_extent extent;
+ struct ext2fs_extent extent, next;
e2_blkcnt_t blockcnt = 0;
blk64_t blk, new_blk;
int op = EXT2_EXTENT_ROOT;
goto abort_exit;
while (1) {
- ctx.errcode = ext2fs_extent_get(handle, op, &extent);
+ if (op == EXT2_EXTENT_CURRENT)
+ ctx.errcode = 0;
+ else
+ ctx.errcode = ext2fs_extent_get(handle, op,
+ &extent);
if (ctx.errcode) {
if (ctx.errcode != EXT2_ET_EXTENT_NO_NEXT)
break;
ctx.errcode = 0;
if (!(flags & BLOCK_FLAG_APPEND))
break;
+ next_block_set:
blk = 0;
r = (*ctx.func)(fs, &blk, blockcnt,
0, 0, priv_data);
ret |= r;
check_for_ro_violation_goto(&ctx, ret,
- extent_errout);
+ extent_done);
if (r & BLOCK_CHANGED) {
ctx.errcode =
ext2fs_extent_set_bmap(handle,
(blk64_t) blk, 0);
if (ctx.errcode || (ret & BLOCK_ABORT))
break;
- continue;
+ if (blk)
+ goto next_block_set;
}
break;
}
if (ctx.errcode)
break;
}
+ if (ret & BLOCK_ABORT)
+ break;
}
continue;
}
uninit = 0;
if (extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT)
uninit = EXT2_EXTENT_SET_BMAP_UNINIT;
+
+ /*
+ * Get the next extent before we start messing
+ * with the current extent
+ */
+ retval = ext2fs_extent_get(handle, op, &next);
+
+#if 0
+ printf("lblk %llu pblk %llu len %d blockcnt %llu\n",
+ extent.e_lblk, extent.e_pblk,
+ extent.e_len, blockcnt);
+#endif
+ if (extent.e_lblk + extent.e_len <= (blk64_t) blockcnt)
+ continue;
+ if (extent.e_lblk > (blk64_t) blockcnt)
+ blockcnt = extent.e_lblk;
+ j = blockcnt - extent.e_lblk;
+ blk += j;
for (blockcnt = extent.e_lblk, j = 0;
j < extent.e_len;
blk++, blockcnt++, j++) {
0, 0, priv_data);
ret |= r;
check_for_ro_violation_goto(&ctx, ret,
- extent_errout);
+ extent_done);
if (r & BLOCK_CHANGED) {
ctx.errcode =
ext2fs_extent_set_bmap(handle,
(blk64_t) blockcnt,
new_blk, uninit);
if (ctx.errcode)
- goto extent_errout;
+ goto extent_done;
}
if (ret & BLOCK_ABORT)
- break;
+ goto extent_done;
+ }
+ if (retval == 0) {
+ extent = next;
+ op = EXT2_EXTENT_CURRENT;
}
}
- extent_errout:
+ extent_done:
ext2fs_extent_free(handle);
- ret |= BLOCK_ERROR | BLOCK_ABORT;
+ ret |= BLOCK_ERROR; /* ctx.errcode is always valid here */
goto errout;
}