]> git.proxmox.com Git - mirror_spl.git/blobdiff - include/linux/file_compat.h
Linux 4.14 compat: vfs_read & vfs_write
[mirror_spl.git] / include / linux / file_compat.h
index 7d61ba5f9ce29044527f29127f549caa1764982f..55ba2cc7681c5a57064b28f0e01f2dc9e52d5bf9 100644 (file)
@@ -26,6 +26,7 @@
 #define        _SPL_FILE_COMPAT_H
 
 #include <linux/fs.h>
+#include <linux/uaccess.h>
 #ifdef HAVE_FDTABLE_HEADER
 #include <linux/fdtable.h>
 #endif
@@ -70,6 +71,46 @@ spl_filp_fallocate(struct file *fp, int mode, loff_t offset, loff_t len)
        return (error);
 }
 
+static inline ssize_t
+spl_kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
+{
+#if defined(HAVE_KERNEL_WRITE_PPOS)
+       return (kernel_write(file, buf, count, pos));
+#else
+       mm_segment_t saved_fs;
+       ssize_t ret;
+
+       saved_fs = get_fs();
+       set_fs(get_ds());
+
+       ret = vfs_write(file, (__force const char __user *)buf, count, pos);
+
+       set_fs(saved_fs);
+
+       return (ret);
+#endif
+}
+
+static inline ssize_t
+spl_kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
+{
+#if defined(HAVE_KERNEL_READ_PPOS)
+       return (kernel_read(file, buf, count, pos));
+#else
+       mm_segment_t saved_fs;
+       ssize_t ret;
+
+       saved_fs = get_fs();
+       set_fs(get_ds());
+
+       ret = vfs_read(file, (void __user *)buf, count, pos);
+
+       set_fs(saved_fs);
+
+       return (ret);
+#endif
+}
+
 #ifdef HAVE_2ARGS_VFS_FSYNC
 #define        spl_filp_fsync(fp, sync)        vfs_fsync(fp, sync)
 #else