diff options
author | Amir Goldstein <amir73il@gmail.com> | 2019-06-05 11:04:48 -0400 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2019-06-09 13:06:19 -0400 |
commit | a31713517dac0862a3f0ec9006df9160ce022b0c (patch) | |
tree | 020aa1dc2d4ad9c646a15c23f12f765271f459a7 /mm/filemap.c | |
parent | 64bf5ff58dff757253cf2142542672de4b21cd1a (diff) |
vfs: introduce generic_file_rw_checks()
Factor out helper with some checks on in/out file that are
common to clone_file_range and copy_file_range.
Suggested-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Diffstat (limited to 'mm/filemap.c')
-rw-r--r-- | mm/filemap.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/mm/filemap.c b/mm/filemap.c index df2006ba0cfa..a38619a4a6af 100644 --- a/mm/filemap.c +++ b/mm/filemap.c | |||
@@ -3041,6 +3041,30 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, | |||
3041 | return 0; | 3041 | return 0; |
3042 | } | 3042 | } |
3043 | 3043 | ||
3044 | |||
3045 | /* | ||
3046 | * Performs common checks before doing a file copy/clone | ||
3047 | * from @file_in to @file_out. | ||
3048 | */ | ||
3049 | int generic_file_rw_checks(struct file *file_in, struct file *file_out) | ||
3050 | { | ||
3051 | struct inode *inode_in = file_inode(file_in); | ||
3052 | struct inode *inode_out = file_inode(file_out); | ||
3053 | |||
3054 | /* Don't copy dirs, pipes, sockets... */ | ||
3055 | if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode)) | ||
3056 | return -EISDIR; | ||
3057 | if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode)) | ||
3058 | return -EINVAL; | ||
3059 | |||
3060 | if (!(file_in->f_mode & FMODE_READ) || | ||
3061 | !(file_out->f_mode & FMODE_WRITE) || | ||
3062 | (file_out->f_flags & O_APPEND)) | ||
3063 | return -EBADF; | ||
3064 | |||
3065 | return 0; | ||
3066 | } | ||
3067 | |||
3044 | int pagecache_write_begin(struct file *file, struct address_space *mapping, | 3068 | int pagecache_write_begin(struct file *file, struct address_space *mapping, |
3045 | loff_t pos, unsigned len, unsigned flags, | 3069 | loff_t pos, unsigned len, unsigned flags, |
3046 | struct page **pagep, void **fsdata) | 3070 | struct page **pagep, void **fsdata) |