Skip to content

Commit bfd7e5f

Browse files
Anuj Guptakawasaki
authored andcommitted
fs/read_write: Generalize generic_copy_file_checks()
Prepare for adding copy_file_range() support for block devices by making the following changes: - Change file_inode(file) into file->f_mapping->host. Although only one inode is associated with regular files, two inodes are associated with block devices. file->f_mapping->host is the primary block device inode. - Change S_ISREG() into S_ISREG() || S_ISBLK(). - Add an inode->i_mode & S_IFMT check that verifies that source and destination have the same type (block device or regular file). Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Anuj Gupta <[email protected]> Signed-off-by: Nitesh Shetty <[email protected]> [ bvanassche: rewrote patch description ] Signed-off-by: Bart Van Assche <[email protected]>
1 parent 0ea7840 commit bfd7e5f

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

fs/read_write.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,8 +1484,8 @@ static int generic_copy_file_checks(struct file *file_in, loff_t pos_in,
14841484
struct file *file_out, loff_t pos_out,
14851485
size_t *req_count, unsigned int flags)
14861486
{
1487-
struct inode *inode_in = file_inode(file_in);
1488-
struct inode *inode_out = file_inode(file_out);
1487+
struct inode *inode_in = file_in->f_mapping->host;
1488+
struct inode *inode_out = file_out->f_mapping->host;
14891489
uint64_t count = *req_count;
14901490
loff_t size_in;
14911491
int ret;
@@ -1791,7 +1791,9 @@ int generic_file_rw_checks(struct file *file_in, struct file *file_out)
17911791
/* Don't copy dirs, pipes, sockets... */
17921792
if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode))
17931793
return -EISDIR;
1794-
if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode))
1794+
if (!S_ISREG(inode_in->i_mode) && !S_ISBLK(inode_in->i_mode))
1795+
return -EINVAL;
1796+
if ((inode_in->i_mode & S_IFMT) != (inode_out->i_mode & S_IFMT))
17951797
return -EINVAL;
17961798

17971799
if (!(file_in->f_mode & FMODE_READ) ||

0 commit comments

Comments
 (0)