public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC 01/15] FS: libfs, implement simple_write_to_buffer
@ 2010-03-23 16:17 Jiri Slaby
  2010-03-23 16:17 ` [RFC 02/15] PM / Hibernate: snapshot cleanup Jiri Slaby
                   ` (29 more replies)
  0 siblings, 30 replies; 88+ messages in thread
From: Jiri Slaby @ 2010-03-23 16:17 UTC (permalink / raw)
  To: jirislaby
  Cc: Nigel Cunningham, linux-kernel, Alexander Viro, linux-fsdevel,
	linux-pm, Jiri Slaby

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 9e50bcf..fda73b3 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -546,6 +546,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
@@ -863,6 +897,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 a4636b6..0f751b6 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2370,6 +2370,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.2

^ permalink raw reply related	[flat|nested] 88+ messages in thread

end of thread, other threads:[~2010-04-22  3:43 UTC | newest]

Thread overview: 88+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-23 16:17 [RFC 01/15] FS: libfs, implement simple_write_to_buffer Jiri Slaby
2010-03-23 16:17 ` [RFC 02/15] PM / Hibernate: snapshot cleanup Jiri Slaby
2010-03-23 16:17 ` [RFC 03/15] PM / Hibernate: separate block_io Jiri Slaby
2010-03-23 16:17 ` [RFC 04/15] PM / Hibernate: move the first_sector out of swsusp_write Jiri Slaby
2010-03-23 16:17 ` [RFC 05/15] PM / Hibernate: group swap ops Jiri Slaby
2010-03-23 16:17 ` [RFC 06/15] PM / Hibernate: swap, remove swap_map_handle usages Jiri Slaby
2010-03-23 16:17 ` [RFC 07/15] PM / Hibernate: add sws_modules_ops Jiri Slaby
2010-03-23 16:17 ` [RFC 08/15] PM / Hibernate: add user module_ops Jiri Slaby
2010-03-25 22:07   ` Rafael J. Wysocki
     [not found]   ` <201003252307.15232.rjw@sisk.pl>
2010-03-26  9:43     ` Jiri Slaby
2010-03-23 16:17 ` [RFC 09/15] PM / Hibernate: user, implement user_ops writer Jiri Slaby
2010-03-23 16:17 ` [RFC 10/15] PM / Hibernate: user, implement user_ops reader Jiri Slaby
2010-03-23 16:17 ` [RFC 11/15] PM / Hibernate: add chunk i/o support Jiri Slaby
2010-03-23 16:17 ` [RFC 12/15] PM / Hibernate: split snapshot_read_next Jiri Slaby
2010-03-23 16:17 ` [RFC 13/15] PM / Hibernate: split snapshot_write_next Jiri Slaby
2010-03-23 16:17 ` [RFC 14/15] PM / Hibernate: dealign swsusp_info Jiri Slaby
2010-03-23 16:17 ` [RFC 15/15] PM / Hibernate: move non-swap code to snapshot.c Jiri Slaby
2010-03-23 21:51 ` [RFC 01/15] FS: libfs, implement simple_write_to_buffer Rafael J. Wysocki
2010-03-23 22:09 ` Nigel Cunningham
     [not found] ` <1269361063-3341-2-git-send-email-jslaby@suse.cz>
2010-03-24 20:29   ` [RFC 02/15] PM / Hibernate: snapshot cleanup Pavel Machek
2010-03-24 22:35   ` Rafael J. Wysocki
2010-03-25  5:29   ` Pavel Machek
     [not found] ` <1269361063-3341-3-git-send-email-jslaby@suse.cz>
2010-03-24 20:30   ` [RFC 03/15] PM / Hibernate: separate block_io Pavel Machek
     [not found]   ` <20100324203021.GE5798@elf.ucw.cz>
2010-03-24 21:22     ` Jiri Slaby
     [not found]     ` <4BAA829F.7060207@gmail.com>
2010-03-24 22:58       ` Nigel Cunningham
     [not found]       ` <4BAA98FC.9040302@crca.org.au>
2010-03-25  2:35         ` Nigel Cunningham
2010-03-25 14:29         ` Pavel Machek
     [not found]         ` <4BAACC0A.2040009@crca.org.au>
2010-03-25 20:12           ` Rafael J. Wysocki
     [not found]           ` <201003252112.25204.rjw@sisk.pl>
2010-03-25 20:13             ` Nigel Cunningham
     [not found]             ` <4BABC3D1.1050104@crca.org.au>
2010-03-25 20:33               ` Rafael J. Wysocki
     [not found]               ` <201003252133.50206.rjw@sisk.pl>
2010-03-25 20:36                 ` Nigel Cunningham
2010-03-29 13:30             ` Pavel Machek
     [not found] ` <1269361063-3341-4-git-send-email-jslaby@suse.cz>
2010-03-24 20:31   ` [RFC 04/15] PM / Hibernate: move the first_sector out of swsusp_write Pavel Machek
     [not found]   ` <20100324203125.GF5798@elf.ucw.cz>
2010-03-25 21:26     ` Rafael J. Wysocki
     [not found] ` <1269361063-3341-6-git-send-email-jslaby@suse.cz>
2010-03-24 20:33   ` [RFC 06/15] PM / Hibernate: swap, remove swap_map_handle usages Pavel Machek
     [not found]   ` <20100324203329.GG5798@elf.ucw.cz>
2010-03-24 21:29     ` Jiri Slaby
     [not found]     ` <4BAA842A.6060906@gmail.com>
2010-03-25 21:35       ` Rafael J. Wysocki
     [not found] ` <1269361063-3341-7-git-send-email-jslaby@suse.cz>
2010-03-24 20:36   ` [RFC 07/15] PM / Hibernate: add sws_modules_ops Pavel Machek
     [not found]   ` <20100324203634.GH5798@elf.ucw.cz>
2010-03-24 21:31     ` Jiri Slaby
2010-03-25 22:02   ` Rafael J. Wysocki
     [not found] ` <1269361063-3341-9-git-send-email-jslaby@suse.cz>
2010-03-24 20:42   ` [RFC 09/15] PM / Hibernate: user, implement user_ops writer Pavel Machek
     [not found]   ` <20100324204259.GA6423@elf.ucw.cz>
2010-03-24 21:40     ` Jiri Slaby
     [not found]     ` <4BAA86E8.5090108@gmail.com>
2010-03-25 21:36       ` Pavel Machek
2010-03-25 22:14       ` Rafael J. Wysocki
     [not found]       ` <201003252314.33256.rjw@sisk.pl>
2010-03-26  9:34         ` Jiri Slaby
     [not found]         ` <4BAC7FC3.50405@gmail.com>
2010-03-26 22:04           ` Rafael J. Wysocki
2010-03-27  7:02           ` Pavel Machek
     [not found]           ` <201003262304.32118.rjw@sisk.pl>
2010-03-29 15:33             ` Jiri Slaby
     [not found]             ` <4BB0C840.7030802@gmail.com>
2010-03-29 22:09               ` Rafael J. Wysocki
2010-03-30  1:14                 ` Nigel Cunningham
2010-03-30 21:03                   ` Rafael J. Wysocki
2010-03-31  2:31                     ` Nigel Cunningham
2010-03-31 14:47                       ` Pavel Machek
2010-03-31 21:01                         ` Nigel Cunningham
2010-03-31 20:25                       ` Rafael J. Wysocki
2010-03-31 21:06                         ` Nigel Cunningham
2010-03-31 21:36                           ` Rafael J. Wysocki
2010-04-04 23:08                             ` Nigel Cunningham
2010-04-04 23:13                               ` Rafael J. Wysocki
2010-03-31 21:54                           ` Nigel Cunningham
2010-03-30  8:59                 ` Jiri Slaby
2010-03-30 20:50                   ` Rafael J. Wysocki
2010-03-31 14:41                     ` Jiri Slaby
2010-03-31 20:29                       ` Rafael J. Wysocki
2010-04-21 21:22                         ` Jiri Slaby
2010-04-22  3:43                           ` Rafael J. Wysocki
2010-03-24 22:13 ` [RFC 01/15] FS: libfs, implement simple_write_to_buffer Rafael J. Wysocki
     [not found] ` <1269361063-3341-10-git-send-email-jslaby@suse.cz>
2010-03-25  5:30   ` what the patches do Re: [RFC 10/15] PM / Hibernate: user, implement user_ops reader Pavel Machek
     [not found]   ` <20100325053003.GB12935@elf.ucw.cz>
2010-03-25  5:42     ` Nigel Cunningham
     [not found]     ` <4BAAF7DA.30506@crca.org.au>
2010-03-25  6:12       ` Nigel Cunningham
2010-03-25 20:14       ` Rafael J. Wysocki
     [not found]       ` <201003252114.36605.rjw@sisk.pl>
2010-03-25 20:21         ` Nigel Cunningham
     [not found]         ` <4BABC5B6.2070301@crca.org.au>
2010-03-25 20:29           ` Rafael J. Wysocki
     [not found]           ` <201003252129.10224.rjw@sisk.pl>
2010-03-25 20:35             ` Nigel Cunningham
     [not found]             ` <4BABC926.8060203@crca.org.au>
2010-03-25 21:13               ` Rafael J. Wysocki
2010-03-25 21:26             ` Pavel Machek
     [not found]             ` <20100325212656.GD22902@elf.ucw.cz>
2010-03-25 21:49               ` Nigel Cunningham
     [not found]               ` <4BABDA59.8070107@crca.org.au>
2010-04-02  6:36                 ` Pavel Machek
     [not found]                 ` <20100402063644.GA14941@atrey.karlin.mff.cuni.cz>
2010-04-02 17:03                   ` Rafael J. Wysocki
2010-03-25 22:21     ` Rafael J. Wysocki
     [not found] ` <1269361063-3341-5-git-send-email-jslaby@suse.cz>
2010-03-25 21:28   ` [RFC 05/15] PM / Hibernate: group swap ops Rafael J. Wysocki
     [not found] ` <1269361063-3341-11-git-send-email-jslaby@suse.cz>
2010-03-25 22:38   ` [RFC 11/15] PM / Hibernate: add chunk i/o support Rafael J. Wysocki
     [not found]   ` <201003252338.48513.rjw@sisk.pl>
2010-03-26  9:09     ` Jiri Slaby
     [not found]     ` <4BAC79B4.4040200@gmail.com>
2010-03-26 10:02       ` Nigel Cunningham
     [not found] ` <1269361063-3341-12-git-send-email-jslaby@suse.cz>
2010-03-25 22:44   ` [RFC 12/15] PM / Hibernate: split snapshot_read_next Rafael J. Wysocki
     [not found] ` <1269361063-3341-13-git-send-email-jslaby@suse.cz>
2010-03-25 22:46   ` [RFC 13/15] PM / Hibernate: split snapshot_write_next Rafael J. Wysocki
     [not found] ` <1269361063-3341-14-git-send-email-jslaby@suse.cz>
2010-03-25 22:46   ` [RFC 14/15] PM / Hibernate: dealign swsusp_info Rafael J. Wysocki
     [not found] ` <1269361063-3341-15-git-send-email-jslaby@suse.cz>
2010-03-25 22:50   ` [RFC 15/15] PM / Hibernate: move non-swap code to snapshot.c 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