Commit 274a4886 authored by Al Viro's avatar Al Viro

ncpfs: switch to ->read_iter/->write_iter

Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 6e242a1c
...@@ -98,30 +98,24 @@ int ncp_make_open(struct inode *inode, int right) ...@@ -98,30 +98,24 @@ int ncp_make_open(struct inode *inode, int right)
} }
static ssize_t static ssize_t
ncp_file_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) ncp_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
{ {
struct file *file = iocb->ki_filp;
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
size_t already_read = 0; size_t already_read = 0;
off_t pos; off_t pos = iocb->ki_pos;
size_t bufsize; size_t bufsize;
int error; int error;
void* freepage; void *freepage;
size_t freelen; size_t freelen;
ncp_dbg(1, "enter %pD2\n", file); ncp_dbg(1, "enter %pD2\n", file);
pos = *ppos; if (!iov_iter_count(to))
if ((ssize_t) count < 0) {
return -EINVAL;
}
if (!count)
return 0; return 0;
if (pos > inode->i_sb->s_maxbytes) if (pos > inode->i_sb->s_maxbytes)
return 0; return 0;
if (pos + count > inode->i_sb->s_maxbytes) { iov_iter_truncate(to, inode->i_sb->s_maxbytes - pos);
count = inode->i_sb->s_maxbytes - pos;
}
error = ncp_make_open(inode, O_RDONLY); error = ncp_make_open(inode, O_RDONLY);
if (error) { if (error) {
...@@ -138,31 +132,29 @@ ncp_file_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) ...@@ -138,31 +132,29 @@ ncp_file_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
goto outrel; goto outrel;
error = 0; error = 0;
/* First read in as much as possible for each bufsize. */ /* First read in as much as possible for each bufsize. */
while (already_read < count) { while (iov_iter_count(to)) {
int read_this_time; int read_this_time;
size_t to_read = min_t(unsigned int, size_t to_read = min_t(size_t,
bufsize - (pos % bufsize), bufsize - (pos % bufsize),
count - already_read); iov_iter_count(to));
error = ncp_read_bounce(NCP_SERVER(inode), error = ncp_read_bounce(NCP_SERVER(inode),
NCP_FINFO(inode)->file_handle, NCP_FINFO(inode)->file_handle,
pos, to_read, buf, &read_this_time, pos, to_read, to, &read_this_time,
freepage, freelen); freepage, freelen);
if (error) { if (error) {
error = -EIO; /* NW errno -> Linux errno */ error = -EIO; /* NW errno -> Linux errno */
break; break;
} }
pos += read_this_time; pos += read_this_time;
buf += read_this_time;
already_read += read_this_time; already_read += read_this_time;
if (read_this_time != to_read) { if (read_this_time != to_read)
break; break;
}
} }
vfree(freepage); vfree(freepage);
*ppos = pos; iocb->ki_pos = pos;
file_accessed(file); file_accessed(file);
...@@ -173,42 +165,26 @@ ncp_file_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) ...@@ -173,42 +165,26 @@ ncp_file_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
} }
static ssize_t static ssize_t
ncp_file_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) ncp_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
{ {
struct file *file = iocb->ki_filp;
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
size_t already_written = 0; size_t already_written = 0;
off_t pos; loff_t pos = iocb->ki_pos;
size_t count = iov_iter_count(from);
size_t bufsize; size_t bufsize;
int errno; int errno;
void* bouncebuffer; void *bouncebuffer;
ncp_dbg(1, "enter %pD2\n", file); ncp_dbg(1, "enter %pD2\n", file);
if ((ssize_t) count < 0) errno = generic_write_checks(file, &pos, &count, 0);
return -EINVAL; if (errno)
pos = *ppos; return errno;
if (file->f_flags & O_APPEND) { iov_iter_truncate(from, count);
pos = i_size_read(inode);
}
if (pos + count > MAX_NON_LFS && !(file->f_flags&O_LARGEFILE)) {
if (pos >= MAX_NON_LFS) {
return -EFBIG;
}
if (count > MAX_NON_LFS - (u32)pos) {
count = MAX_NON_LFS - (u32)pos;
}
}
if (pos >= inode->i_sb->s_maxbytes) {
if (count || pos > inode->i_sb->s_maxbytes) {
return -EFBIG;
}
}
if (pos + count > inode->i_sb->s_maxbytes) {
count = inode->i_sb->s_maxbytes - pos;
}
if (!count) if (!count)
return 0; return 0;
errno = ncp_make_open(inode, O_WRONLY); errno = ncp_make_open(inode, O_WRONLY);
if (errno) { if (errno) {
ncp_dbg(1, "open failed, error=%d\n", errno); ncp_dbg(1, "open failed, error=%d\n", errno);
...@@ -216,8 +192,6 @@ ncp_file_write(struct file *file, const char __user *buf, size_t count, loff_t * ...@@ -216,8 +192,6 @@ ncp_file_write(struct file *file, const char __user *buf, size_t count, loff_t *
} }
bufsize = NCP_SERVER(inode)->buffer_size; bufsize = NCP_SERVER(inode)->buffer_size;
already_written = 0;
errno = file_update_time(file); errno = file_update_time(file);
if (errno) if (errno)
goto outrel; goto outrel;
...@@ -227,13 +201,13 @@ ncp_file_write(struct file *file, const char __user *buf, size_t count, loff_t * ...@@ -227,13 +201,13 @@ ncp_file_write(struct file *file, const char __user *buf, size_t count, loff_t *
errno = -EIO; /* -ENOMEM */ errno = -EIO; /* -ENOMEM */
goto outrel; goto outrel;
} }
while (already_written < count) { while (iov_iter_count(from)) {
int written_this_time; int written_this_time;
size_t to_write = min_t(unsigned int, size_t to_write = min_t(size_t,
bufsize - (pos % bufsize), bufsize - ((off_t)pos % bufsize),
count - already_written); iov_iter_count(from));
if (copy_from_user(bouncebuffer, buf, to_write)) { if (copy_from_iter(bouncebuffer, to_write, from) != to_write) {
errno = -EFAULT; errno = -EFAULT;
break; break;
} }
...@@ -244,16 +218,14 @@ ncp_file_write(struct file *file, const char __user *buf, size_t count, loff_t * ...@@ -244,16 +218,14 @@ ncp_file_write(struct file *file, const char __user *buf, size_t count, loff_t *
break; break;
} }
pos += written_this_time; pos += written_this_time;
buf += written_this_time;
already_written += written_this_time; already_written += written_this_time;
if (written_this_time != to_write) { if (written_this_time != to_write)
break; break;
}
} }
vfree(bouncebuffer); vfree(bouncebuffer);
*ppos = pos; iocb->ki_pos = pos;
if (pos > i_size_read(inode)) { if (pos > i_size_read(inode)) {
mutex_lock(&inode->i_mutex); mutex_lock(&inode->i_mutex);
...@@ -277,8 +249,10 @@ static int ncp_release(struct inode *inode, struct file *file) { ...@@ -277,8 +249,10 @@ static int ncp_release(struct inode *inode, struct file *file) {
const struct file_operations ncp_file_operations = const struct file_operations ncp_file_operations =
{ {
.llseek = generic_file_llseek, .llseek = generic_file_llseek,
.read = ncp_file_read, .read = new_sync_read,
.write = ncp_file_write, .write = new_sync_write,
.read_iter = ncp_file_read_iter,
.write_iter = ncp_file_write_iter,
.unlocked_ioctl = ncp_ioctl, .unlocked_ioctl = ncp_ioctl,
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
.compat_ioctl = ncp_compat_ioctl, .compat_ioctl = ncp_compat_ioctl,
......
...@@ -1001,8 +1001,8 @@ ncp_read_kernel(struct ncp_server *server, const char *file_id, ...@@ -1001,8 +1001,8 @@ ncp_read_kernel(struct ncp_server *server, const char *file_id,
*/ */
int int
ncp_read_bounce(struct ncp_server *server, const char *file_id, ncp_read_bounce(struct ncp_server *server, const char *file_id,
__u32 offset, __u16 to_read, char __user *target, int *bytes_read, __u32 offset, __u16 to_read, struct iov_iter *to,
void* bounce, __u32 bufsize) int *bytes_read, void *bounce, __u32 bufsize)
{ {
int result; int result;
...@@ -1025,7 +1025,7 @@ ncp_read_bounce(struct ncp_server *server, const char *file_id, ...@@ -1025,7 +1025,7 @@ ncp_read_bounce(struct ncp_server *server, const char *file_id,
(offset & 1); (offset & 1);
*bytes_read = len; *bytes_read = len;
result = 0; result = 0;
if (copy_to_user(target, source, len)) if (copy_to_iter(source, len, to) != len)
result = -EFAULT; result = -EFAULT;
} }
} }
......
...@@ -53,7 +53,7 @@ static inline int ncp_read_bounce_size(__u32 size) { ...@@ -53,7 +53,7 @@ static inline int ncp_read_bounce_size(__u32 size) {
return sizeof(struct ncp_reply_header) + 2 + 2 + size + 8; return sizeof(struct ncp_reply_header) + 2 + 2 + size + 8;
}; };
int ncp_read_bounce(struct ncp_server *, const char *, __u32, __u16, int ncp_read_bounce(struct ncp_server *, const char *, __u32, __u16,
char __user *, int *, void* bounce, __u32 bouncelen); struct iov_iter *, int *, void *bounce, __u32 bouncelen);
int ncp_read_kernel(struct ncp_server *, const char *, __u32, __u16, int ncp_read_kernel(struct ncp_server *, const char *, __u32, __u16,
char *, int *); char *, int *);
int ncp_write_kernel(struct ncp_server *, const char *, __u32, __u16, int ncp_write_kernel(struct ncp_server *, const char *, __u32, __u16,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment