From c622fbdb8d37796c35ab1e08240a18b4222e5c9f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 17 Sep 2015 01:19:54 +0200 Subject: [PATCH] copy: be more careful when trying to reflink --- src/basic/copy.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/basic/copy.c b/src/basic/copy.c index b8cbe644d443a..019b2764b9509 100644 --- a/src/basic/copy.c +++ b/src/basic/copy.c @@ -37,7 +37,11 @@ int copy_bytes(int fdf, int fdt, uint64_t max_bytes, bool try_reflink) { assert(fdt >= 0); /* Try btrfs reflinks first. */ - if (try_reflink && max_bytes == (uint64_t) -1) { + if (try_reflink && + max_bytes == (uint64_t) -1 && + lseek(fdf, 0, SEEK_CUR) == 0 && + lseek(fdt, 0, SEEK_CUR) == 0) { + r = btrfs_reflink(fdf, fdt); if (r >= 0) return r;