diff options
author | Qu Wenruo <quwenruo@cn.fujitsu.com> | 2015-06-17 15:49:03 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2015-06-17 16:10:09 +0200 |
commit | 1bbd40a1bb79906ce112b07baf389e9824dca543 (patch) | |
tree | 732d57141804d1022724401c2742dcae9d0275de | |
parent | 1e28ed2f8497263fe7bf8f9c7b4bc71c3f001a0f (diff) |
Btrfs-progs: map-logical: introduce write_extent_content function
This function will write extent content info desired file.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
-rw-r--r-- | btrfs-map-logical.c | 34 |
1 files changed, 34 insertions, 0 deletions
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) { |