btrfs-progs: convert: move csum_disk_extent

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2016-08-23 17:38:55 +02:00
parent 3ec64ddf00
commit 70b5221bfb
1 changed files with 29 additions and 29 deletions

View File

@ -189,6 +189,35 @@ fail:
return ret; return ret;
} }
static int csum_disk_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 disk_bytenr, u64 num_bytes)
{
u32 blocksize = root->sectorsize;
u64 offset;
char *buffer;
int ret = 0;
buffer = malloc(blocksize);
if (!buffer)
return -ENOMEM;
for (offset = 0; offset < num_bytes; offset += blocksize) {
ret = read_disk_extent(root, disk_bytenr + offset,
blocksize, buffer);
if (ret)
break;
ret = btrfs_csum_file_block(trans,
root->fs_info->csum_root,
disk_bytenr + num_bytes,
disk_bytenr + offset,
buffer, blocksize);
if (ret)
break;
}
free(buffer);
return ret;
}
/* /*
* Open Ext2fs in readonly mode, read block allocation bitmap and * Open Ext2fs in readonly mode, read block allocation bitmap and
* inode bitmap into memory. * inode bitmap into memory.
@ -430,35 +459,6 @@ error:
return -1; return -1;
} }
static int csum_disk_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 disk_bytenr, u64 num_bytes)
{
u32 blocksize = root->sectorsize;
u64 offset;
char *buffer;
int ret = 0;
buffer = malloc(blocksize);
if (!buffer)
return -ENOMEM;
for (offset = 0; offset < num_bytes; offset += blocksize) {
ret = read_disk_extent(root, disk_bytenr + offset,
blocksize, buffer);
if (ret)
break;
ret = btrfs_csum_file_block(trans,
root->fs_info->csum_root,
disk_bytenr + num_bytes,
disk_bytenr + offset,
buffer, blocksize);
if (ret)
break;
}
free(buffer);
return ret;
}
struct blk_iterate_data { struct blk_iterate_data {
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
struct btrfs_root *root; struct btrfs_root *root;