mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
synced 2024-11-16 00:34:32 +08:00
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>
This commit is contained in:
parent
1e28ed2f84
commit
1bbd40a1bb
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user