summaryrefslogtreecommitdiff
path: root/btrfs-map-logical.c
diff options
context:
space:
mode:
Diffstat (limited to 'btrfs-map-logical.c')
-rw-r--r--btrfs-map-logical.c34
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)
{