static int dry_run = 0;
#define LZO_LEN 4
-#define PAGE_CACHE_SIZE 4096
#define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
static int decompress_zlib(char *inbuf, char *outbuf, u64 compress_len,
return le32_to_cpu(dlen);
}
-static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len,
- u64 *decompress_len)
+static int decompress_lzo(struct btrfs_root *root, unsigned char *inbuf,
+ char *outbuf, u64 compress_len, u64 *decompress_len)
{
size_t new_len;
size_t in_len;
inbuf += LZO_LEN;
tot_in += LZO_LEN;
-
- new_len = lzo1x_worst_compress(PAGE_CACHE_SIZE);
+ new_len = lzo1x_worst_compress(root->sectorsize);
ret = lzo1x_decompress_safe((const unsigned char *)inbuf, in_len,
(unsigned char *)outbuf,
(void *)&new_len, NULL);
* If the 4 byte header does not fit to the rest of the page we
* have to move to the next one, unless we read some garbage
*/
- mod_page = tot_in % PAGE_CACHE_SIZE;
- rem_page = PAGE_CACHE_SIZE - mod_page;
+ mod_page = tot_in % root->sectorsize;
+ rem_page = root->sectorsize - mod_page;
if (rem_page < LZO_LEN) {
inbuf += rem_page;
tot_in += rem_page;
return 0;
}
-static int decompress(char *inbuf, char *outbuf, u64 compress_len,
- u64 *decompress_len, int compress)
+static int decompress(struct btrfs_root *root, char *inbuf, char *outbuf,
+ u64 compress_len, u64 *decompress_len, int compress)
{
switch (compress) {
case BTRFS_COMPRESS_ZLIB:
return decompress_zlib(inbuf, outbuf, compress_len,
*decompress_len);
case BTRFS_COMPRESS_LZO:
- return decompress_lzo((unsigned char *)inbuf, outbuf, compress_len,
- decompress_len);
+ return decompress_lzo(root, (unsigned char *)inbuf, outbuf,
+ compress_len, decompress_len);
default:
break;
}
return 0;
}
-static int copy_one_inline(int fd, struct btrfs_path *path, u64 pos)
+static int copy_one_inline(struct btrfs_root *root, int fd,
+ struct btrfs_path *path, u64 pos)
{
struct extent_buffer *leaf = path->nodes[0];
struct btrfs_file_extent_item *fi;
return -ENOMEM;
}
- ret = decompress(buf, outbuf, len, &ram_size, compress);
+ ret = decompress(root, buf, outbuf, len, &ram_size, compress);
if (ret) {
free(outbuf);
return ret;
goto out;
}
- ret = decompress(inbuf, outbuf, disk_size, &ram_size, compress);
+ ret = decompress(root, inbuf, outbuf, disk_size, &ram_size, compress);
if (ret) {
num_copies = btrfs_num_copies(&root->fs_info->mapping_tree,
bytenr, length);
if (extent_type == BTRFS_FILE_EXTENT_PREALLOC)
goto next;
if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
- ret = copy_one_inline(fd, path, found_key.offset);
+ ret = copy_one_inline(root, fd, path, found_key.offset);
if (ret)
goto out;
} else if (extent_type == BTRFS_FILE_EXTENT_REG) {
for (i = super_mirror; i < BTRFS_SUPER_MIRROR_MAX; i++) {
bytenr = btrfs_sb_offset(i);
- fs_info = open_ctree_fs_info(dev, bytenr, root_location,
+ fs_info = open_ctree_fs_info(dev, bytenr, root_location, 0,
OPEN_CTREE_PARTIAL);
if (fs_info)
break;
root_location = btrfs_super_root(fs_info->super_copy);
generation = btrfs_super_generation(fs_info->super_copy);
root->node = read_tree_block(root, root_location,
- root->leafsize, generation);
+ root->nodesize, generation);
if (!extent_buffer_uptodate(root->node)) {
fprintf(stderr, "Error opening tree root\n");
close_ctree(root);
if (fs_location != 0) {
free_extent_buffer(root->node);
- root->node = read_tree_block(root, fs_location, root->leafsize, 0);
+ root->node = read_tree_block(root, fs_location, root->nodesize, 0);
if (!extent_buffer_uptodate(root->node)) {
fprintf(stderr, "Failed to read fs location\n");
ret = 1;