* [PATCH 1/5] FS: libfs, implement simple_write_to_buffer
@ 2010-04-27 8:15 Jiri Slaby
2010-04-27 21:58 ` Rafael J. Wysocki
2010-04-28 22:10 ` Rafael J. Wysocki
0 siblings, 2 replies; 5+ messages in thread
From: Jiri Slaby @ 2010-04-27 8:15 UTC (permalink / raw)
To: rjw
Cc: Nigel Cunningham, jirislaby, linux-kernel, Alexander Viro,
linux-fsdevel, linux-pm
It will be used in suspend code and serves as an easy wrap around
copy_from_user. Similar to simple_read_from_buffer, it takes care
of transfers with proper lengths depending on available and count
parameters and advances ppos appropriately.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Nigel Cunningham <ncunningham@crca.org.au>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
---
fs/libfs.c | 35 +++++++++++++++++++++++++++++++++++
include/linux/fs.h | 2 ++
2 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/fs/libfs.c b/fs/libfs.c
index ea9a6cc..cfab42a 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -547,6 +547,40 @@ ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos,
}
/**
+ * simple_write_to_buffer - copy data from user space to the buffer
+ * @to: the buffer to write to
+ * @available: the size of the buffer
+ * @ppos: the current position in the buffer
+ * @from: the user space buffer to read from
+ * @count: the maximum number of bytes to read
+ *
+ * The simple_write_to_buffer() function reads up to @count bytes from the user
+ * space address starting at @from into the buffer @to at offset @ppos.
+ *
+ * On success, the number of bytes written is returned and the offset @ppos is
+ * advanced by this number, or negative value is returned on error.
+ **/
+ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
+ const void __user *from, size_t count)
+{
+ loff_t pos = *ppos;
+ size_t ret;
+
+ if (pos < 0)
+ return -EINVAL;
+ if (pos >= available || !count)
+ return 0;
+ if (count > available - pos)
+ count = available - pos;
+ ret = copy_from_user(to + pos, from, count);
+ if (ret == count)
+ return -EFAULT;
+ count -= ret;
+ *ppos = pos + count;
+ return count;
+}
+
+/**
* memory_read_from_buffer - copy data from the buffer
* @to: the kernel space buffer to read to
* @count: the maximum number of bytes to read
@@ -864,6 +898,7 @@ EXPORT_SYMBOL(simple_statfs);
EXPORT_SYMBOL(simple_sync_file);
EXPORT_SYMBOL(simple_unlink);
EXPORT_SYMBOL(simple_read_from_buffer);
+EXPORT_SYMBOL(simple_write_to_buffer);
EXPORT_SYMBOL(memory_read_from_buffer);
EXPORT_SYMBOL(simple_transaction_set);
EXPORT_SYMBOL(simple_transaction_get);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 66f3caa..e594a8d 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2372,6 +2372,8 @@ extern void simple_release_fs(struct vfsmount **mount, int *count);
extern ssize_t simple_read_from_buffer(void __user *to, size_t count,
loff_t *ppos, const void *from, size_t available);
+extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
+ const void __user *from, size_t count);
extern int simple_fsync(struct file *, struct dentry *, int);
--
1.7.0.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/5] FS: libfs, implement simple_write_to_buffer
2010-04-27 8:15 [PATCH 1/5] FS: libfs, implement simple_write_to_buffer Jiri Slaby
@ 2010-04-27 21:58 ` Rafael J. Wysocki
2010-04-28 22:16 ` Rafael J. Wysocki
2010-04-28 22:10 ` Rafael J. Wysocki
1 sibling, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2010-04-27 21:58 UTC (permalink / raw)
To: Jiri Slaby
Cc: pavel, linux-pm, linux-kernel, jirislaby, Nigel Cunningham,
Alexander Viro, linux-fsdevel
On Tuesday 27 April 2010, Jiri Slaby wrote:
> It will be used in suspend code and serves as an easy wrap around
> copy_from_user. Similar to simple_read_from_buffer, it takes care
> of transfers with proper lengths depending on available and count
> parameters and advances ppos appropriately.
>
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Nigel Cunningham <ncunningham@crca.org.au>
> Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: linux-fsdevel@vger.kernel.org
Thanks for the patches, I'll review them as soon as I can.
Rafael
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/5] FS: libfs, implement simple_write_to_buffer
2010-04-27 8:15 [PATCH 1/5] FS: libfs, implement simple_write_to_buffer Jiri Slaby
2010-04-27 21:58 ` Rafael J. Wysocki
@ 2010-04-28 22:10 ` Rafael J. Wysocki
1 sibling, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2010-04-28 22:10 UTC (permalink / raw)
To: Jiri Slaby
Cc: pavel, linux-pm, linux-kernel, jirislaby, Nigel Cunningham,
Alexander Viro, linux-fsdevel
On Tuesday 27 April 2010, Jiri Slaby wrote:
> It will be used in suspend code and serves as an easy wrap around
> copy_from_user. Similar to simple_read_from_buffer, it takes care
> of transfers with proper lengths depending on available and count
> parameters and advances ppos appropriately.
Will anyone object if I take this one into the suspend-2.6 tree?
Rafael
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Nigel Cunningham <ncunningham@crca.org.au>
> Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: linux-fsdevel@vger.kernel.org
> ---
> fs/libfs.c | 35 +++++++++++++++++++++++++++++++++++
> include/linux/fs.h | 2 ++
> 2 files changed, 37 insertions(+), 0 deletions(-)
>
> diff --git a/fs/libfs.c b/fs/libfs.c
> index ea9a6cc..cfab42a 100644
> --- a/fs/libfs.c
> +++ b/fs/libfs.c
> @@ -547,6 +547,40 @@ ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos,
> }
>
> /**
> + * simple_write_to_buffer - copy data from user space to the buffer
> + * @to: the buffer to write to
> + * @available: the size of the buffer
> + * @ppos: the current position in the buffer
> + * @from: the user space buffer to read from
> + * @count: the maximum number of bytes to read
> + *
> + * The simple_write_to_buffer() function reads up to @count bytes from the user
> + * space address starting at @from into the buffer @to at offset @ppos.
> + *
> + * On success, the number of bytes written is returned and the offset @ppos is
> + * advanced by this number, or negative value is returned on error.
> + **/
> +ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
> + const void __user *from, size_t count)
> +{
> + loff_t pos = *ppos;
> + size_t ret;
> +
> + if (pos < 0)
> + return -EINVAL;
> + if (pos >= available || !count)
> + return 0;
> + if (count > available - pos)
> + count = available - pos;
> + ret = copy_from_user(to + pos, from, count);
> + if (ret == count)
> + return -EFAULT;
> + count -= ret;
> + *ppos = pos + count;
> + return count;
> +}
> +
> +/**
> * memory_read_from_buffer - copy data from the buffer
> * @to: the kernel space buffer to read to
> * @count: the maximum number of bytes to read
> @@ -864,6 +898,7 @@ EXPORT_SYMBOL(simple_statfs);
> EXPORT_SYMBOL(simple_sync_file);
> EXPORT_SYMBOL(simple_unlink);
> EXPORT_SYMBOL(simple_read_from_buffer);
> +EXPORT_SYMBOL(simple_write_to_buffer);
> EXPORT_SYMBOL(memory_read_from_buffer);
> EXPORT_SYMBOL(simple_transaction_set);
> EXPORT_SYMBOL(simple_transaction_get);
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 66f3caa..e594a8d 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2372,6 +2372,8 @@ extern void simple_release_fs(struct vfsmount **mount, int *count);
>
> extern ssize_t simple_read_from_buffer(void __user *to, size_t count,
> loff_t *ppos, const void *from, size_t available);
> +extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
> + const void __user *from, size_t count);
>
> extern int simple_fsync(struct file *, struct dentry *, int);
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/5] FS: libfs, implement simple_write_to_buffer
2010-04-27 21:58 ` Rafael J. Wysocki
@ 2010-04-28 22:16 ` Rafael J. Wysocki
2010-05-01 22:00 ` Rafael J. Wysocki
0 siblings, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2010-04-28 22:16 UTC (permalink / raw)
To: Jiri Slaby
Cc: pavel, linux-pm, linux-kernel, jirislaby, Nigel Cunningham,
Alexander Viro, linux-fsdevel
On Tuesday 27 April 2010, Rafael J. Wysocki wrote:
> On Tuesday 27 April 2010, Jiri Slaby wrote:
> > It will be used in suspend code and serves as an easy wrap around
> > copy_from_user. Similar to simple_read_from_buffer, it takes care
> > of transfers with proper lengths depending on available and count
> > parameters and advances ppos appropriately.
> >
> > Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> > Cc: Nigel Cunningham <ncunningham@crca.org.au>
> > Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
> > Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> > Cc: linux-fsdevel@vger.kernel.org
>
> Thanks for the patches, I'll review them as soon as I can.
They look good. If there are no objections from the other people, I'll add
them to suspend-2.6/linux-next in the next few days.
Rafael
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/5] FS: libfs, implement simple_write_to_buffer
2010-04-28 22:16 ` Rafael J. Wysocki
@ 2010-05-01 22:00 ` Rafael J. Wysocki
0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2010-05-01 22:00 UTC (permalink / raw)
To: Jiri Slaby
Cc: pavel, linux-pm, linux-kernel, jirislaby, Nigel Cunningham,
Alexander Viro, linux-fsdevel
On Thursday 29 April 2010, Rafael J. Wysocki wrote:
> On Tuesday 27 April 2010, Rafael J. Wysocki wrote:
> > On Tuesday 27 April 2010, Jiri Slaby wrote:
> > > It will be used in suspend code and serves as an easy wrap around
> > > copy_from_user. Similar to simple_read_from_buffer, it takes care
> > > of transfers with proper lengths depending on available and count
> > > parameters and advances ppos appropriately.
> > >
> > > Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> > > Cc: Nigel Cunningham <ncunningham@crca.org.au>
> > > Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
> > > Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> > > Cc: linux-fsdevel@vger.kernel.org
> >
> > Thanks for the patches, I'll review them as soon as I can.
>
> They look good. If there are no objections from the other people, I'll add
> them to suspend-2.6/linux-next in the next few days.
All patches in this series applied to suspend-2.6/linux-next.
I fixed up the Pavel's address in the copyright notice in kernel/power/block_io.c.
Thanks,
Rafael
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-05-01 22:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-27 8:15 [PATCH 1/5] FS: libfs, implement simple_write_to_buffer Jiri Slaby
2010-04-27 21:58 ` Rafael J. Wysocki
2010-04-28 22:16 ` Rafael J. Wysocki
2010-05-01 22:00 ` Rafael J. Wysocki
2010-04-28 22:10 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).