diff options
author | Jiri Slaby <jslaby@suse.cz> | 2010-05-01 17:51:22 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2010-05-10 17:08:17 -0400 |
commit | 6a727b43be8b005609e893a80af980808012cfdb (patch) | |
tree | 7e30e015a9da93f049fbe6a27b591313d592b8b6 /fs | |
parent | bc6a0cbd576c66995d782331456f68ae63a50af4 (diff) |
FS / libfs: Implement simple_write_to_buffer
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>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/libfs.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/fs/libfs.c b/fs/libfs.c index ea9a6cc9b35c..232bea425b09 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, | |||
547 | } | 547 | } |
548 | 548 | ||
549 | /** | 549 | /** |
550 | * simple_write_to_buffer - copy data from user space to the buffer | ||
551 | * @to: the buffer to write to | ||
552 | * @available: the size of the buffer | ||
553 | * @ppos: the current position in the buffer | ||
554 | * @from: the user space buffer to read from | ||
555 | * @count: the maximum number of bytes to read | ||
556 | * | ||
557 | * The simple_write_to_buffer() function reads up to @count bytes from the user | ||
558 | * space address starting at @from into the buffer @to at offset @ppos. | ||
559 | * | ||
560 | * On success, the number of bytes written is returned and the offset @ppos is | ||
561 | * advanced by this number, or negative value is returned on error. | ||
562 | **/ | ||
563 | ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, | ||
564 | const void __user *from, size_t count) | ||
565 | { | ||
566 | loff_t pos = *ppos; | ||
567 | size_t res; | ||
568 | |||
569 | if (pos < 0) | ||
570 | return -EINVAL; | ||
571 | if (pos >= available || !count) | ||
572 | return 0; | ||
573 | if (count > available - pos) | ||
574 | count = available - pos; | ||
575 | res = copy_from_user(to + pos, from, count); | ||
576 | if (res == count) | ||
577 | return -EFAULT; | ||
578 | count -= res; | ||
579 | *ppos = pos + count; | ||
580 | return count; | ||
581 | } | ||
582 | |||
583 | /** | ||
550 | * memory_read_from_buffer - copy data from the buffer | 584 | * memory_read_from_buffer - copy data from the buffer |
551 | * @to: the kernel space buffer to read to | 585 | * @to: the kernel space buffer to read to |
552 | * @count: the maximum number of bytes to read | 586 | * @count: the maximum number of bytes to read |
@@ -864,6 +898,7 @@ EXPORT_SYMBOL(simple_statfs); | |||
864 | EXPORT_SYMBOL(simple_sync_file); | 898 | EXPORT_SYMBOL(simple_sync_file); |
865 | EXPORT_SYMBOL(simple_unlink); | 899 | EXPORT_SYMBOL(simple_unlink); |
866 | EXPORT_SYMBOL(simple_read_from_buffer); | 900 | EXPORT_SYMBOL(simple_read_from_buffer); |
901 | EXPORT_SYMBOL(simple_write_to_buffer); | ||
867 | EXPORT_SYMBOL(memory_read_from_buffer); | 902 | EXPORT_SYMBOL(memory_read_from_buffer); |
868 | EXPORT_SYMBOL(simple_transaction_set); | 903 | EXPORT_SYMBOL(simple_transaction_set); |
869 | EXPORT_SYMBOL(simple_transaction_get); | 904 | EXPORT_SYMBOL(simple_transaction_get); |