]>
git.proxmox.com Git - mirror_zfs.git/blob - module/zcommon/zfs_uio.c
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
40 * The uio support from OpenSolaris has been added as a short term
41 * work around. The hope is to adopt native Linux type and drop the
42 * use of uio's entirely. Under Linux they only add overhead and
43 * when possible we want to use native APIs for the ZPL layer.
47 #include <sys/types.h>
48 #include <sys/uio_impl.h>
51 * Move "n" bytes at byte address "p"; "rw" indicates the direction
52 * of the move, and the I/O parameters are provided in "uio", which is
53 * update to reflect the data which was moved. Returns 0 on success or
54 * a non-zero errno on failure.
57 uiomove(void *p
, size_t n
, enum uio_rw rw
, struct uio
*uio
)
62 while (n
&& uio
->uio_resid
) {
64 cnt
= MIN(iov
->iov_len
, n
);
70 switch (uio
->uio_segflg
) {
73 /* p = kernel data pointer
74 * iov->iov_base = user data pointer */
77 if (copy_to_user(iov
->iov_base
, p
, cnt
))
79 /* error = xcopyout_nta(p, iov->iov_base, cnt,
80 * (uio->uio_extflg & UIO_COPY_CACHED)); */
82 /* error = xcopyin_nta(iov->iov_base, p, cnt,
83 * (uio->uio_extflg & UIO_COPY_CACHED)); */
84 if (copy_from_user(p
, iov
->iov_base
, cnt
))
90 bcopy(p
, iov
->iov_base
, cnt
);
92 bcopy(iov
->iov_base
, p
, cnt
);
97 uio
->uio_resid
-= cnt
;
98 uio
->uio_loffset
+= cnt
;
104 EXPORT_SYMBOL(uiomove
);
106 #define fuword8(uptr, vptr) get_user((*vptr), (uptr))
109 * Fault in the pages of the first n bytes specified by the uio structure.
110 * 1 byte in each page is touched and the uio struct is unmodified. Any
111 * error will terminate the process as this is only a best attempt to get
112 * the pages resident.
115 uio_prefaultpages(ssize_t n
, struct uio
*uio
)
124 iovcnt
= uio
->uio_iovcnt
;
126 while ((n
> 0) && (iovcnt
> 0)) {
127 cnt
= MIN(iov
->iov_len
, n
);
129 /* empty iov entry */
136 * touch each page in this segment.
140 switch (uio
->uio_segflg
) {
143 if (fuword8((uint8_t *) p
, &tmp
))
150 incr
= MIN(cnt
, PAGESIZE
);
155 * touch the last byte in case it straddles a page.
158 switch (uio
->uio_segflg
) {
161 if (fuword8((uint8_t *) p
, &tmp
))
172 EXPORT_SYMBOL(uio_prefaultpages
);
175 * same as uiomove() but doesn't modify uio structure.
176 * return in cbytes how many bytes were copied.
179 uiocopy(void *p
, size_t n
, enum uio_rw rw
, struct uio
*uio
, size_t *cbytes
)
185 iovcnt
= uio
->uio_iovcnt
;
188 for (iov
= uio
->uio_iov
; n
&& iovcnt
; iov
++, iovcnt
--) {
189 cnt
= MIN(iov
->iov_len
, n
);
193 switch (uio
->uio_segflg
) {
197 /* p = kernel data pointer
198 * iov->iov_base = user data pointer */
200 if (rw
== UIO_READ
) {
201 /* * UIO_READ = copy data from kernel to user * */
202 if (copy_to_user(iov
->iov_base
, p
, cnt
))
204 /* error = xcopyout_nta(p, iov->iov_base, cnt,
205 * (uio->uio_extflg & UIO_COPY_CACHED)); */
207 /* * UIO_WRITE = copy data from user to kernel * */
208 /* error = xcopyin_nta(iov->iov_base, p, cnt,
209 * (uio->uio_extflg & UIO_COPY_CACHED)); */
210 if (copy_from_user(p
, iov
->iov_base
, cnt
))
217 bcopy(p
, iov
->iov_base
, cnt
);
219 bcopy(iov
->iov_base
, p
, cnt
);
222 p
= (caddr_t
)p
+ cnt
;
228 EXPORT_SYMBOL(uiocopy
);
231 * Drop the next n chars out of *uiop.
234 uioskip(uio_t
*uiop
, size_t n
)
236 if (n
> uiop
->uio_resid
)
239 iovec_t
*iovp
= uiop
->uio_iov
;
240 size_t niovb
= MIN(iovp
->iov_len
, n
);
247 iovp
->iov_base
+= niovb
;
248 uiop
->uio_loffset
+= niovb
;
249 iovp
->iov_len
-= niovb
;
250 uiop
->uio_resid
-= niovb
;
254 EXPORT_SYMBOL(uioskip
);