diff options
Diffstat (limited to 'fs/libfs.c')
-rw-r--r-- | fs/libfs.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/fs/libfs.c b/fs/libfs.c index b004dfadd891..baeb71ee1cde 100644 --- a/fs/libfs.c +++ b/fs/libfs.c | |||
@@ -512,6 +512,20 @@ void simple_release_fs(struct vfsmount **mount, int *count) | |||
512 | mntput(mnt); | 512 | mntput(mnt); |
513 | } | 513 | } |
514 | 514 | ||
515 | /** | ||
516 | * simple_read_from_buffer - copy data from the buffer to user space | ||
517 | * @to: the user space buffer to read to | ||
518 | * @count: the maximum number of bytes to read | ||
519 | * @ppos: the current position in the buffer | ||
520 | * @from: the buffer to read from | ||
521 | * @available: the size of the buffer | ||
522 | * | ||
523 | * The simple_read_from_buffer() function reads up to @count bytes from the | ||
524 | * buffer @from at offset @ppos into the user space address starting at @to. | ||
525 | * | ||
526 | * On success, the number of bytes read is returned and the offset @ppos is | ||
527 | * advanced by this number, or negative value is returned on error. | ||
528 | **/ | ||
515 | ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos, | 529 | ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos, |
516 | const void *from, size_t available) | 530 | const void *from, size_t available) |
517 | { | 531 | { |
@@ -528,6 +542,37 @@ ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos, | |||
528 | return count; | 542 | return count; |
529 | } | 543 | } |
530 | 544 | ||
545 | /** | ||
546 | * memory_read_from_buffer - copy data from the buffer | ||
547 | * @to: the kernel space buffer to read to | ||
548 | * @count: the maximum number of bytes to read | ||
549 | * @ppos: the current position in the buffer | ||
550 | * @from: the buffer to read from | ||
551 | * @available: the size of the buffer | ||
552 | * | ||
553 | * The memory_read_from_buffer() function reads up to @count bytes from the | ||
554 | * buffer @from at offset @ppos into the kernel space address starting at @to. | ||
555 | * | ||
556 | * On success, the number of bytes read is returned and the offset @ppos is | ||
557 | * advanced by this number, or negative value is returned on error. | ||
558 | **/ | ||
559 | ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos, | ||
560 | const void *from, size_t available) | ||
561 | { | ||
562 | loff_t pos = *ppos; | ||
563 | |||
564 | if (pos < 0) | ||
565 | return -EINVAL; | ||
566 | if (pos >= available) | ||
567 | return 0; | ||
568 | if (count > available - pos) | ||
569 | count = available - pos; | ||
570 | memcpy(to, from + pos, count); | ||
571 | *ppos = pos + count; | ||
572 | |||
573 | return count; | ||
574 | } | ||
575 | |||
531 | /* | 576 | /* |
532 | * Transaction based IO. | 577 | * Transaction based IO. |
533 | * The file expects a single write which triggers the transaction, and then | 578 | * The file expects a single write which triggers the transaction, and then |
@@ -800,6 +845,7 @@ EXPORT_SYMBOL(simple_statfs); | |||
800 | EXPORT_SYMBOL(simple_sync_file); | 845 | EXPORT_SYMBOL(simple_sync_file); |
801 | EXPORT_SYMBOL(simple_unlink); | 846 | EXPORT_SYMBOL(simple_unlink); |
802 | EXPORT_SYMBOL(simple_read_from_buffer); | 847 | EXPORT_SYMBOL(simple_read_from_buffer); |
848 | EXPORT_SYMBOL(memory_read_from_buffer); | ||
803 | EXPORT_SYMBOL(simple_transaction_get); | 849 | EXPORT_SYMBOL(simple_transaction_get); |
804 | EXPORT_SYMBOL(simple_transaction_read); | 850 | EXPORT_SYMBOL(simple_transaction_read); |
805 | EXPORT_SYMBOL(simple_transaction_release); | 851 | EXPORT_SYMBOL(simple_transaction_release); |