When src and dst is the same file, and the latter part of source region
overlaps with the former part of destination region, current implement
will overwrite data which hasn't been moved yet and truncate data in
overlapped region.
This patch return -EINVAL when such cases occur and return 0 when
source region and destination region is actually the same part of
the same file.

Signed-off-by: Fan li <fanofcode...@samsung.com>
---
 fs/f2fs/file.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index d5f60ad..116946b 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2168,6 +2168,13 @@ static int f2fs_move_file_range(struct file *file_in, 
loff_t pos_in,
        if (f2fs_encrypted_inode(src) || f2fs_encrypted_inode(dst))
                return -EOPNOTSUPP;
 
+       if (src == dst) {
+               if (pos_in == pos_out)
+                       return 0;
+               if (pos_out > pos_in && pos_out < pos_in + len)
+                       return -EINVAL;
+       }
+
        inode_lock(src);
        if (src != dst) {
                if (!inode_trylock(dst)) {
-- 
1.7.9.5


------------------------------------------------------------------------------
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to