Skip to content

Commit

Permalink
preadv/pwritev: create compat_writev()
Browse files Browse the repository at this point in the history
Factor out some code from compat_sys_writev() which can be shared with the
upcoming compat_sys_pwritev().

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: <linux-api@vger.kernel.org>
Cc: <linux-arch@vger.kernel.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Gerd Hoffmann authored and Linus Torvalds committed Apr 3, 2009
1 parent dac1213 commit 6949a63
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions fs/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,28 +1232,39 @@ compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec,
return ret;
}

asmlinkage ssize_t
compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec, unsigned long vlen)
static size_t compat_writev(struct file *file,
const struct compat_iovec __user *vec,
unsigned long vlen, loff_t *pos)
{
struct file *file;
ssize_t ret = -EBADF;

file = fget(fd);
if (!file)
return -EBADF;
if (!(file->f_mode & FMODE_WRITE))
goto out;

ret = -EINVAL;
if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
goto out;

ret = compat_do_readv_writev(WRITE, file, vec, vlen, &file->f_pos);
ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos);

out:
if (ret > 0)
add_wchar(current, ret);
inc_syscw(current);
return ret;
}

asmlinkage ssize_t
compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec,
unsigned long vlen)
{
struct file *file;
ssize_t ret;

file = fget(fd);
if (!file)
return -EBADF;
ret = compat_writev(file, vec, vlen, &file->f_pos);
fput(file);
return ret;
}
Expand Down

0 comments on commit 6949a63

Please sign in to comment.