diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2014-02-11 17:49:24 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2014-05-06 17:32:55 -0400 |
commit | 7f7f25e82d54870df24d415a7007fbd327da027b (patch) | |
tree | bac50bd31cd0582a873e1429271299536fb768bc /fs/read_write.c | |
parent | b318891929c2750055a4002bee3e7636ca3684de (diff) |
replace checking for ->read/->aio_read presence with check in ->f_mode
Since we are about to introduce new methods (read_iter/write_iter), the
tests in a bunch of places would have to grow inconveniently. Check
once (at open() time) and store results in ->f_mode as FMODE_CAN_READ
and FMODE_CAN_WRITE resp. It might end up being a temporary measure -
once everything switches from ->aio_{read,write} to ->{read,write}_iter
it might make sense to return to open-coded checks. We'll see...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/read_write.c')
-rw-r--r-- | fs/read_write.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/fs/read_write.c b/fs/read_write.c index 31c6efa43183..d29d2a361d2c 100644 --- a/fs/read_write.c +++ b/fs/read_write.c | |||
@@ -396,7 +396,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) | |||
396 | 396 | ||
397 | if (!(file->f_mode & FMODE_READ)) | 397 | if (!(file->f_mode & FMODE_READ)) |
398 | return -EBADF; | 398 | return -EBADF; |
399 | if (!file->f_op->read && !file->f_op->aio_read) | 399 | if (!(file->f_mode & FMODE_CAN_READ)) |
400 | return -EINVAL; | 400 | return -EINVAL; |
401 | if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) | 401 | if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) |
402 | return -EFAULT; | 402 | return -EFAULT; |
@@ -445,7 +445,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t | |||
445 | const char __user *p; | 445 | const char __user *p; |
446 | ssize_t ret; | 446 | ssize_t ret; |
447 | 447 | ||
448 | if (!file->f_op->write && !file->f_op->aio_write) | 448 | if (!(file->f_mode & FMODE_CAN_WRITE)) |
449 | return -EINVAL; | 449 | return -EINVAL; |
450 | 450 | ||
451 | old_fs = get_fs(); | 451 | old_fs = get_fs(); |
@@ -472,7 +472,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_ | |||
472 | 472 | ||
473 | if (!(file->f_mode & FMODE_WRITE)) | 473 | if (!(file->f_mode & FMODE_WRITE)) |
474 | return -EBADF; | 474 | return -EBADF; |
475 | if (!file->f_op->write && !file->f_op->aio_write) | 475 | if (!(file->f_mode & FMODE_CAN_WRITE)) |
476 | return -EINVAL; | 476 | return -EINVAL; |
477 | if (unlikely(!access_ok(VERIFY_READ, buf, count))) | 477 | if (unlikely(!access_ok(VERIFY_READ, buf, count))) |
478 | return -EFAULT; | 478 | return -EFAULT; |
@@ -785,7 +785,7 @@ ssize_t vfs_readv(struct file *file, const struct iovec __user *vec, | |||
785 | { | 785 | { |
786 | if (!(file->f_mode & FMODE_READ)) | 786 | if (!(file->f_mode & FMODE_READ)) |
787 | return -EBADF; | 787 | return -EBADF; |
788 | if (!file->f_op->aio_read && !file->f_op->read) | 788 | if (!(file->f_mode & FMODE_CAN_READ)) |
789 | return -EINVAL; | 789 | return -EINVAL; |
790 | 790 | ||
791 | return do_readv_writev(READ, file, vec, vlen, pos); | 791 | return do_readv_writev(READ, file, vec, vlen, pos); |
@@ -798,7 +798,7 @@ ssize_t vfs_writev(struct file *file, const struct iovec __user *vec, | |||
798 | { | 798 | { |
799 | if (!(file->f_mode & FMODE_WRITE)) | 799 | if (!(file->f_mode & FMODE_WRITE)) |
800 | return -EBADF; | 800 | return -EBADF; |
801 | if (!file->f_op->aio_write && !file->f_op->write) | 801 | if (!(file->f_mode & FMODE_CAN_WRITE)) |
802 | return -EINVAL; | 802 | return -EINVAL; |
803 | 803 | ||
804 | return do_readv_writev(WRITE, file, vec, vlen, pos); | 804 | return do_readv_writev(WRITE, file, vec, vlen, pos); |
@@ -964,7 +964,7 @@ static size_t compat_readv(struct file *file, | |||
964 | goto out; | 964 | goto out; |
965 | 965 | ||
966 | ret = -EINVAL; | 966 | ret = -EINVAL; |
967 | if (!file->f_op->aio_read && !file->f_op->read) | 967 | if (!(file->f_mode & FMODE_CAN_READ)) |
968 | goto out; | 968 | goto out; |
969 | 969 | ||
970 | ret = compat_do_readv_writev(READ, file, vec, vlen, pos); | 970 | ret = compat_do_readv_writev(READ, file, vec, vlen, pos); |
@@ -1041,7 +1041,7 @@ static size_t compat_writev(struct file *file, | |||
1041 | goto out; | 1041 | goto out; |
1042 | 1042 | ||
1043 | ret = -EINVAL; | 1043 | ret = -EINVAL; |
1044 | if (!file->f_op->aio_write && !file->f_op->write) | 1044 | if (!(file->f_mode & FMODE_CAN_WRITE)) |
1045 | goto out; | 1045 | goto out; |
1046 | 1046 | ||
1047 | ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos); | 1047 | ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos); |