Skip to contentSkip to conversation

Btrfs-progs: fix restore of files with compressed extents

PATCH New Filipe David Borba Manana 1 participant 1 message Feb 25, 2014 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 cmds-restore.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
cmds-restore.c +6 -3
index 1748262..e620ee7 100644
@@ -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;
Signature · 1 line
1.7.9.5