summaryrefslogtreecommitdiff
path: root/disk-io.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2015-06-17 15:49:00 +0800
committerDavid Sterba <dsterba@suse.cz>2015-06-17 16:08:35 +0200
commit0074cd315c9e82e4f0ff8348b77d785da7eb487b (patch)
tree2fbf266c7761d048e80d2fa5ec52dc880be1c951 /disk-io.c
parentcf4eb9a90e44937b395200d78172411f16fe31af (diff)
downloadbtrfs-progs-0074cd315c9e82e4f0ff8348b77d785da7eb487b.tar.gz
btrfs-progs-0074cd315c9e82e4f0ff8348b77d785da7eb487b.tar.bz2
btrfs-progs-0074cd315c9e82e4f0ff8348b77d785da7eb487b.zip
btrfs-progs: export read_extent_data function
Export it for later btrfs-map-logical cleanup. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'disk-io.c')
-rw-r--r--disk-io.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/disk-io.c b/disk-io.c
index a6e6056c..6a538433 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -366,6 +366,40 @@ struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
return ERR_PTR(ret);
}
+int read_extent_data(struct btrfs_root *root, char *data,
+ u64 logical, u64 *len, int mirror)
+{
+ u64 offset = 0;
+ struct btrfs_multi_bio *multi = NULL;
+ struct btrfs_fs_info *info = root->fs_info;
+ struct btrfs_device *device;
+ int ret = 0;
+ u64 max_len = *len;
+
+ ret = btrfs_map_block(&info->mapping_tree, READ, logical, len,
+ &multi, mirror, NULL);
+ if (ret) {
+ fprintf(stderr, "Couldn't map the block %llu\n",
+ logical + offset);
+ goto err;
+ }
+ device = multi->stripes[0].dev;
+
+ if (device->fd == 0)
+ goto err;
+ if (*len > max_len)
+ *len = max_len;
+
+ ret = pread64(device->fd, data, *len, multi->stripes[0].physical);
+ if (ret != *len)
+ ret = -EIO;
+ else
+ ret = 0;
+err:
+ kfree(multi);
+ return ret;
+}
+
int write_and_map_eb(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct extent_buffer *eb)