public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Filipe David Borba Manana <fdmanana@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Filipe David Borba Manana <fdmanana@gmail.com>
Subject: [PATCH] Btrfs-progs: fix restore of files with compressed extents
Date: Tue, 25 Feb 2014 18:25:39 +0000	[thread overview]
Message-ID: <1393352739-25073-1-git-send-email-fdmanana@gmail.com> (raw)

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 <fdmanana@gmail.com>
---
 cmds-restore.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/cmds-restore.c b/cmds-restore.c
index 1748262..e620ee7 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -297,7 +297,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);
@@ -387,8 +388,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;
-- 
1.7.9.5


                 reply	other threads:[~2014-02-25 18:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1393352739-25073-1-git-send-email-fdmanana@gmail.com \
    --to=fdmanana@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox