mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-22 22:51:37 +00:00
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>
This commit is contained in:
parent
64bf5ff58d
commit
a31713517d
3 changed files with 36 additions and 27 deletions
24
mm/filemap.c
24
mm/filemap.c
|
@ -3041,6 +3041,30 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in,
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Performs common checks before doing a file copy/clone
|
||||
* from @file_in to @file_out.
|
||||
*/
|
||||
int generic_file_rw_checks(struct file *file_in, struct file *file_out)
|
||||
{
|
||||
struct inode *inode_in = file_inode(file_in);
|
||||
struct inode *inode_out = file_inode(file_out);
|
||||
|
||||
/* Don't copy dirs, pipes, sockets... */
|
||||
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;
|
||||
|
||||
if (!(file_in->f_mode & FMODE_READ) ||
|
||||
!(file_out->f_mode & FMODE_WRITE) ||
|
||||
(file_out->f_flags & O_APPEND))
|
||||
return -EBADF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pagecache_write_begin(struct file *file, struct address_space *mapping,
|
||||
loff_t pos, unsigned len, unsigned flags,
|
||||
struct page **pagep, void **fsdata)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue