@@ -1747,11 +1747,12 @@ int vfs_clone_file_prep(struct file *file_in, loff_t pos_in,
isize = i_size_read(inode_in);
- /* Zero length dedupe exits immediately; reflink goes to EOF. */
- if (*len == 0) {
- if (is_dedupe || pos_in == isize)
- return 0;
- if (pos_in > isize)
+ /*
+ * If the caller asked to go all the way to the end of the source file,
+ * set *len now that we have the file locked.
+ */
+ if ((flags & CLONERANGE_EOF) && *len == 0) {
+ if (pos_in >= isize)
return -EINVAL;
*len = isize - pos_in;
}
@@ -1836,6 +1837,9 @@ int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
if (ret)
return ret;
+ if (len == 0)
+ flags |= CLONERANGE_EOF;
+
cloned = file_in->f_op->clone_file_range(file_in, pos_in,
file_out, pos_out, len, flags);
if (cloned < 0)