#include "transaction.h"
#include "list.h"
#include "utils.h"
+#include "help.h"
-#define BUFFER_SIZE (64 * 1024)
+#define BUFFER_SIZE SZ_64K
/* we write the mirror info to stdout unless they are dumping the data
* to stdout
}
logical = key.objectid;
if (key.type == BTRFS_METADATA_ITEM_KEY)
- len = fs_info->tree_root->nodesize;
+ len = fs_info->nodesize;
else
len = key.offset;
int i;
cur_len = len - cur_offset;
- ret = btrfs_map_block(&fs_info->mapping_tree, READ,
- logical + cur_offset, &cur_len,
- &multi, mirror_num, NULL);
+ ret = btrfs_map_block(fs_info, READ, logical + cur_offset,
+ &cur_len, &multi, mirror_num, NULL);
if (ret) {
fprintf(info_file,
"Error: fails to map mirror%d logical %llu: %s\n",
multi->stripes[0].physical,
device->name);
}
- kfree(multi);
+ free(multi);
multi = NULL;
cur_offset += cur_len;
}
int mirror_num;
int ret = 0;
- num_copies = btrfs_num_copies(&fs_info->mapping_tree, logical, len);
+ num_copies = btrfs_num_copies(fs_info, logical, len);
for (mirror_num = 1; mirror_num <= num_copies; mirror_num++) {
ret = __print_mapping_info(fs_info, logical, len, mirror_num);
if (ret < 0)
static void print_usage(void) __attribute__((noreturn));
static void print_usage(void)
{
- fprintf(stderr, "usage: btrfs-map-logical [options] device\n");
- fprintf(stderr, "\t-l Logical extent to map\n");
- fprintf(stderr, "\t-c Copy of the extent to read (usually 1 or 2)\n");
- fprintf(stderr, "\t-o Output file to hold the extent\n");
- fprintf(stderr, "\t-b Number of bytes to read\n");
+ printf("usage: btrfs-map-logical [options] device\n");
+ printf("\t-l Logical extent to map\n");
+ printf("\t-c Copy of the extent to read (usually 1 or 2)\n");
+ printf("\t-o Output file to hold the extent\n");
+ printf("\t-b Number of bytes to read\n");
exit(1);
}
}
if (bytes == 0)
- bytes = root->nodesize;
+ bytes = root->fs_info->nodesize;
cur_logical = logical;
cur_len = bytes;
goto out_close_fd;
if (ret > 0)
break;
+ /* check again if there is overlap. */
+ if (cur_logical + cur_len < logical ||
+ cur_logical >= logical + bytes)
+ break;
+
real_logical = max(logical, cur_logical);
real_len = min(logical + bytes, cur_logical + cur_len) -
real_logical;