Skip to content

Commit

Permalink
blkdev_write_iter: expand generic_file_checks() call in there
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Apr 12, 2015
1 parent 5f380c7 commit 7ec7b94
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1595,18 +1595,21 @@ static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg)
ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
struct file *file = iocb->ki_filp;
struct inode *bd_inode = file->f_mapping->host;
loff_t size = i_size_read(bd_inode);
struct blk_plug plug;
ssize_t ret;
size_t count = iov_iter_count(from);

ret = generic_write_checks(file, &iocb->ki_pos, &count, 1);
if (ret)
return ret;
if (bdev_read_only(I_BDEV(bd_inode)))
return -EPERM;

if (count == 0)
if (!iov_iter_count(from))
return 0;

iov_iter_truncate(from, count);
if (iocb->ki_pos >= size)
return -ENOSPC;

iov_iter_truncate(from, size - iocb->ki_pos);

blk_start_plug(&plug);
ret = __generic_file_write_iter(iocb, from);
Expand Down

0 comments on commit 7ec7b94

Please sign in to comment.