From: Qu Wenruo Date: Wed, 17 Jun 2015 07:49:03 +0000 (+0800) Subject: Btrfs-progs: map-logical: introduce write_extent_content function X-Git-Tag: upstream/4.16.1~2155 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1bbd40a1bb79906ce112b07baf389e9824dca543;p=platform%2Fupstream%2Fbtrfs-progs.git 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 --- diff --git a/btrfs-map-logical.c b/btrfs-map-logical.c index 22ece82..1ee101c 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) {