+ if (ext2fs_has_feature_shared_blocks(ctx->fs->super) &&
+ (ctx->options & E2F_OPT_UNSHARE_BLOCKS) &&
+ (ctx->options & E2F_OPT_NO))
+ should_write = 0;
+
+ c = EXT2FS_B2C(fs, blockcnt);
+ if (check_if_fs_cluster(ctx, EXT2FS_B2C(fs, *block_nr)))
+ is_meta = 1;
+
+ if (c == cs->dup_cluster && cs->alloc_block) {
+ new_block = cs->alloc_block;
+ goto got_block;
+ }
+
+ if (ext2fs_test_block_bitmap2(ctx->block_dup_map, *block_nr)) {
+ n = dict_lookup(&clstr_dict,
+ INT_TO_VOIDPTR(EXT2FS_B2C(fs, *block_nr)));
+ if (!n) {
+ com_err("clone_file_block", 0,
+ _("internal error: can't find dup_blk for %llu\n"),
+ *block_nr);
+ return 0;
+ }
+
+ p = (struct dup_cluster *) dnode_get(n);
+
+ cs->dup_cluster = c;
+ /*
+ * Let's try an implied cluster allocation. If we get the same
+ * cluster back, then we need to find a new block; otherwise,
+ * we're merely fixing the problem of one logical cluster being
+ * mapped to multiple physical clusters.
+ */
+ new_block = 0;
+ retval = ext2fs_map_cluster_block(fs, cs->ino,
+ EXT2_INODE(cs->inode),
+ blockcnt, &new_block);
+ if (retval == 0 && new_block != 0 &&
+ EXT2FS_B2C(ctx->fs, new_block) !=
+ EXT2FS_B2C(ctx->fs, *block_nr))
+ goto cluster_alloc_ok;
+ retval = ext2fs_new_block2(fs, 0, ctx->block_found_map,
+ &new_block);
+ if (retval) {
+ cs->errcode = retval;
+ return BLOCK_ABORT;
+ }
+ if (ext2fs_has_feature_shared_blocks(fs->super)) {
+ /*
+ * Update the block stats so we don't get a prompt to fix block
+ * counts in the final pass.
+ */
+ ext2fs_block_alloc_stats2(fs, new_block, +1);
+ }
+cluster_alloc_ok:
+ cs->alloc_block = new_block;
+
+ got_block:
+ new_block &= ~EXT2FS_CLUSTER_MASK(fs);
+ new_block += EXT2FS_CLUSTER_MASK(fs) & blockcnt;
+ if (cs->dir && (blockcnt >= 0)) {
+ retval = ext2fs_set_dir_block2(fs->dblist,
+ cs->dir, new_block, blockcnt);