Skip to content

Commit

Permalink
Btrfs: Fix file clone when source offset is not 0
Browse files Browse the repository at this point in the history
Suppose:
- the source extent is: [0, 100]
- the src offset is 10
- the clone length is 90
- the dest offset is 0

This statement:

	new_key.offset = key.offset + destoff - off

will produce such an extent for the dest file:

	[ino, BTRFS_EXTENT_DATA_KEY, -10]

, which is obviously wrong.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
  • Loading branch information
Li Zefan committed Jan 26, 2011
1 parent b897abe commit 4d728ec
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,10 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,

memcpy(&new_key, &key, sizeof(new_key));
new_key.objectid = inode->i_ino;
new_key.offset = key.offset + destoff - off;
if (off <= key.offset)
new_key.offset = key.offset + destoff - off;
else
new_key.offset = destoff;

trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans)) {
Expand Down

0 comments on commit 4d728ec

Please sign in to comment.