From 1bbd40a1bb79906ce112b07baf389e9824dca543 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 17 Jun 2015 15:49:03 +0800 Subject: Btrfs-progs: map-logical: introduce write_extent_content function This function will write extent content info desired file. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- btrfs-map-logical.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'btrfs-map-logical.c') diff --git a/btrfs-map-logical.c b/btrfs-map-logical.c index 22ece82e..1ee101c6 100644 --- a/btrfs-map-logical.c +++ b/btrfs-map-logical.c @@ -30,6 +30,8 @@ #include "list.h" #include "utils.h" +#define BUFFER_SIZE (64 * 1024) + /* we write the mirror info to stdout unless they are dumping the data * to stdout * */ @@ -156,6 +158,38 @@ static int print_mapping_info(struct btrfs_fs_info *fs_info, u64 logical, return ret; } +/* Same requisition as print_mapping_info function */ +static int write_extent_content(struct btrfs_fs_info *fs_info, int out_fd, + u64 logical, u64 length, int mirror) +{ + char buffer[BUFFER_SIZE]; + u64 cur_offset = 0; + u64 cur_len; + int ret = 0; + + while (cur_offset < length) { + cur_len = min_t(u64, length - cur_offset, BUFFER_SIZE); + ret = read_extent_data(fs_info->tree_root, buffer, + logical + cur_offset, &cur_len, mirror); + if (ret < 0) { + fprintf(stderr, + "Failed to read extent at [%llu, %llu]: %s\n", + logical, logical + length, strerror(-ret)); + return ret; + } + ret = write(out_fd, buffer, cur_len); + if (ret < 0 || ret != cur_len) { + if (ret > 0) + ret = -EINTR; + fprintf(stderr, "output file write failed: %s\n", + strerror(-ret)); + return ret; + } + cur_offset += cur_len; + } + return ret; +} + static struct extent_buffer * debug_read_block(struct btrfs_root *root, u64 bytenr, u32 blocksize, u64 copy) { -- cgit v1.2.3