Skip to content

Commit

Permalink
Btrfs: fix file clone ioctl for bookend extents
Browse files Browse the repository at this point in the history
The file clone ioctl was incorrectly taking the offset into the
extent on disk into account when calculating the length of the
cloned extent.

The length never changes based on the offset into the physical extent.

Test case:

fallocate -l 1g image
mke2fs image
bcp image image2
e2fsck -f image2

(errors on image2)

The math bug ends up wrapping the length of the extent, and things
go wrong from there.

Signed-off-by: Chris Mason <[email protected]>
  • Loading branch information
chrismason-xx committed Oct 9, 2009
1 parent e9061e2 commit ac6889c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,8 +1123,10 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
datao += off - key.offset;
datal -= off - key.offset;
}
if (key.offset + datao + datal > off + len)
datal = off + len - key.offset - datao;

if (key.offset + datal > off + len)
datal = off + len - key.offset;

/* disko == 0 means it's a hole */
if (!disko)
datao = 0;
Expand Down

0 comments on commit ac6889c

Please sign in to comment.