2 * iovec manipulation routines.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
11 * Andrew Lunn : Errors in iovec copying.
12 * Pedro Roque : Added memcpy_fromiovecend and
13 * csum_..._fromiovecend.
14 * Andi Kleen : fixed error handling for 2.1
15 * Alexey Kuznetsov: 2.1 optimisations
16 * Andi Kleen : Fix csum*fromiovecend for IPv6.
19 #include <linux/errno.h>
20 #include <linux/module.h>
21 #include <linux/kernel.h>
23 #include <linux/net.h>
24 #include <linux/in6.h>
25 #include <asm/uaccess.h>
26 #include <asm/byteorder.h>
27 #include <net/checksum.h>
31 * And now for the all-in-one: copy and checksum from a user iovec
32 * directly to a datagram
33 * Calls to csum_partial but the last must be in 32 bit chunks
35 * ip_build_xmit must ensure that when fragmenting only the last
36 * call to this function will be unaligned also.
38 int csum_partial_copy_fromiovecend(unsigned char *kdata, struct iovec *iov,
39 int offset, unsigned int len, __wsum *csump)
42 int partial_cnt = 0, err = 0;
44 /* Skip over the finished iovecs */
45 while (offset >= iov->iov_len) {
46 offset -= iov->iov_len;
51 u8 __user *base = iov->iov_base + offset;
52 int copy = min_t(unsigned int, len, iov->iov_len - offset);
56 /* There is a remnant from previous iov. */
58 int par_len = 4 - partial_cnt;
60 /* iov component is too short ... */
62 if (copy_from_user(kdata, base, copy))
71 *csump = csum_partial(kdata - partial_cnt,
75 if (copy_from_user(kdata, base, par_len))
77 csum = csum_partial(kdata - partial_cnt, 4, csum);
86 partial_cnt = copy % 4;
89 if (copy_from_user(kdata + copy, base + copy,
96 csum = csum_and_copy_from_user(base, kdata, copy,
101 len -= copy + partial_cnt;
102 kdata += copy + partial_cnt;
113 EXPORT_SYMBOL(csum_partial_copy_fromiovecend);
115 unsigned long iov_pages(const struct iovec *iov, int offset,
116 unsigned long nr_segs)
118 unsigned long seg, base;
119 int pages = 0, len, size;
121 while (nr_segs && (offset >= iov->iov_len)) {
122 offset -= iov->iov_len;
127 for (seg = 0; seg < nr_segs; seg++) {
128 base = (unsigned long)iov[seg].iov_base + offset;
129 len = iov[seg].iov_len - offset;
130 size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
137 EXPORT_SYMBOL(iov_pages);