]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - fs/read_write.c
m68k/mm: sun3 - Modernize printing of kernel messages
[linux.git] / fs / read_write.c
index dbf3f7ffdf3f69201f90314daac7f75d221650cf..5816d4c4cab09c22274c2cdc40f4176f16426f0a 100644 (file)
@@ -20,7 +20,7 @@
 #include <linux/fs.h>
 #include "internal.h"
 
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include <asm/unistd.h>
 
 typedef ssize_t (*io_fn_t)(struct file *, char __user *, size_t, loff_t *);
@@ -1538,9 +1538,7 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
        if (len == 0)
                return 0;
 
-       ret = mnt_want_write_file(file_out);
-       if (ret)
-               return ret;
+       sb_start_write(inode_out->i_sb);
 
        /*
         * Try cloning first, this is supported by more file systems, and
@@ -1576,7 +1574,7 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
        inc_syscr(current);
        inc_syscw(current);
 
-       mnt_drop_write_file(file_out);
+       sb_end_write(inode_out->i_sb);
 
        return ret;
 }
@@ -1671,6 +1669,9 @@ static int clone_verify_area(struct file *file, loff_t pos, u64 len, bool write)
  * Check that the two inodes are eligible for cloning, the ranges make
  * sense, and then flush all dirty data.  Caller must ensure that the
  * inodes have been locked against any other modifications.
+ *
+ * Returns: 0 for "nothing to clone", 1 for "something to clone", or
+ * the usual negative error code.
  */
 int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in,
                               struct inode *inode_out, loff_t pos_out,
@@ -1697,17 +1698,15 @@ int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in,
 
        /* Are we going all the way to the end? */
        isize = i_size_read(inode_in);
-       if (isize == 0) {
-               *len = 0;
+       if (isize == 0)
                return 0;
-       }
 
        /* Zero length dedupe exits immediately; reflink goes to EOF. */
        if (*len == 0) {
-               if (is_dedupe) {
-                       *len = 0;
+               if (is_dedupe || pos_in == isize)
                        return 0;
-               }
+               if (pos_in > isize)
+                       return -EINVAL;
                *len = isize - pos_in;
        }
 
@@ -1771,7 +1770,7 @@ int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in,
                        return -EBADE;
        }
 
-       return 0;
+       return 1;
 }
 EXPORT_SYMBOL(vfs_clone_file_prep_inodes);
 
@@ -1782,15 +1781,19 @@ int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
        struct inode *inode_out = file_inode(file_out);
        int ret;
 
-       if (inode_in->i_sb != inode_out->i_sb ||
-           file_in->f_path.mnt != file_out->f_path.mnt)
-               return -EXDEV;
-
        if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode))
                return -EISDIR;
        if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode))
                return -EINVAL;
 
+       /*
+        * FICLONE/FICLONERANGE ioctls enforce that src and dest files are on
+        * the same mount. Practically, they only need to be on the same file
+        * system.
+        */
+       if (inode_in->i_sb != inode_out->i_sb)
+               return -EXDEV;
+
        if (!(file_in->f_mode & FMODE_READ) ||
            !(file_out->f_mode & FMODE_WRITE) ||
            (file_out->f_flags & O_APPEND))
@@ -1810,10 +1813,6 @@ int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
        if (pos_in + len > i_size_read(inode_in))
                return -EINVAL;
 
-       ret = mnt_want_write_file(file_out);
-       if (ret)
-               return ret;
-
        ret = file_in->f_op->clone_file_range(file_in, pos_in,
                        file_out, pos_out, len);
        if (!ret) {
@@ -1821,7 +1820,6 @@ int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
                fsnotify_modify(file_out);
        }
 
-       mnt_drop_write_file(file_out);
        return ret;
 }
 EXPORT_SYMBOL(vfs_clone_file_range);
@@ -1958,6 +1956,9 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same)
                goto out;
        ret = 0;
 
+       if (off + len > i_size_read(src))
+               return -EINVAL;
+
        /* pre-format output fields to sane values */
        for (i = 0; i < count; i++) {
                same->info[i].bytes_deduped = 0ULL;