From: Filipe David Borba Manana Date: Tue, 25 Feb 2014 18:25:39 +0000 (+0000) Subject: Btrfs-progs: fix restore of files with compressed extents X-Git-Tag: upstream/4.16.1~2938 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4314116bae30d2e9376b07929e6b0e58cddbd9f7;p=platform%2Fupstream%2Fbtrfs-progs.git Btrfs-progs: fix restore of files with compressed extents The code was incorrectly adding the file extent items' data offset to the logical disk address of the extent (bytenr) when the extent is compressed. The offset is relative to the uncompressed data and not to what we store on disk (compressed). Also it attempted to copy ram_bytes to destination, which is incorrect when the data offset field is non-zero, it must use num_bytes instead. A test case for xfstests follows. Signed-off-by: Filipe David Borba Manana Signed-off-by: David Sterba Signed-off-by: Chris Mason --- diff --git a/cmds-restore.c b/cmds-restore.c index 6659c75..41a2bee 100644 --- a/cmds-restore.c +++ b/cmds-restore.c @@ -298,7 +298,8 @@ static int copy_one_extent(struct btrfs_root *root, int fd, offset = btrfs_file_extent_offset(leaf, fi); num_bytes = btrfs_file_extent_num_bytes(leaf, fi); size_left = num_bytes; - bytenr += offset; + if (compress == BTRFS_COMPRESS_NONE) + bytenr += offset; if (offset) printf("offset is %Lu\n", offset); @@ -388,8 +389,10 @@ again: goto again; } - while (total < ram_size) { - done = pwrite(fd, outbuf+total, ram_size-total, pos+total); + while (total < num_bytes) { + done = pwrite(fd, outbuf + offset + total, + num_bytes - total, + pos + total); if (done < 0) { ret = -1; goto out;