4 * Copyright (C) 1994-1999 Linus Torvalds
10 #include <linux/types.h>
13 #include <linux/highmem.h>
14 #include <linux/uio.h>
15 #include <linux/uaccess.h>
18 __filemap_copy_from_user_iovec_inatomic(char *vaddr,
19 const struct iovec *iov,
24 * Copy as much as we can into the page and return the number of bytes which
25 * were sucessfully copied. If a fault is encountered then clear the page
26 * out to (offset+bytes) and return the number of bytes which were copied.
28 * NOTE: For this to work reliably we really want copy_from_user_inatomic_nocache
29 * to *NOT* zero any tail of the buffer that it failed to copy. If it does,
30 * and if the following non-atomic copy succeeds, then there is a small window
31 * where the target page contains neither the data before the write, nor the
32 * data after the write (it contains zero). A read at this time will see
33 * data that is inconsistent with any ordering of the read and the write.
34 * (This has been detected in practice).
37 filemap_copy_from_user(struct page *page, unsigned long offset,
38 const char __user *buf, unsigned bytes)
43 kaddr = kmap_atomic(page, KM_USER0);
44 left = __copy_from_user_inatomic_nocache(kaddr + offset, buf, bytes);
45 kunmap_atomic(kaddr, KM_USER0);
48 /* Do it the slow way */
50 left = __copy_from_user_nocache(kaddr + offset, buf, bytes);
57 * This has the same sideeffects and return value as filemap_copy_from_user().
58 * The difference is that on a fault we need to memset the remainder of the
59 * page (out to offset+bytes), to emulate filemap_copy_from_user()'s
60 * single-segment behaviour.
63 filemap_copy_from_user_iovec(struct page *page, unsigned long offset,
64 const struct iovec *iov, size_t base, size_t bytes)
69 kaddr = kmap_atomic(page, KM_USER0);
70 copied = __filemap_copy_from_user_iovec_inatomic(kaddr + offset, iov,
72 kunmap_atomic(kaddr, KM_USER0);
73 if (copied != bytes) {
75 copied = __filemap_copy_from_user_iovec_inatomic(kaddr + offset, iov,
78 memset(kaddr + offset + copied, 0, bytes - copied);
85 filemap_set_next_iovec(const struct iovec **iovp, size_t *basep, size_t bytes)
87 const struct iovec *iov = *iovp;
91 int copy = min(bytes, iov->iov_len - base);
95 if (iov->iov_len == base) {