]>
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
) {
74 * p = kernel data pointer
75 * iov->iov_base = user data pointer
78 if (copy_to_user(iov
->iov_base
, p
, cnt
))
81 if (copy_from_user(p
, iov
->iov_base
, cnt
))
87 bcopy(p
, iov
->iov_base
, cnt
);
89 bcopy(iov
->iov_base
, p
, cnt
);
94 uio
->uio_resid
-= cnt
;
95 uio
->uio_loffset
+= cnt
;
101 EXPORT_SYMBOL(uiomove
);
103 #define fuword8(uptr, vptr) get_user((*vptr), (uptr))
106 * Fault in the pages of the first n bytes specified by the uio structure.
107 * 1 byte in each page is touched and the uio struct is unmodified. Any
108 * error will terminate the process as this is only a best attempt to get
109 * the pages resident.
112 uio_prefaultpages(ssize_t n
, struct uio
*uio
)
121 iovcnt
= uio
->uio_iovcnt
;
123 while ((n
> 0) && (iovcnt
> 0)) {
124 cnt
= MIN(iov
->iov_len
, n
);
126 /* empty iov entry */
133 * touch each page in this segment.
137 switch (uio
->uio_segflg
) {
140 if (fuword8((uint8_t *) p
, &tmp
))
147 incr
= MIN(cnt
, PAGESIZE
);
152 * touch the last byte in case it straddles a page.
155 switch (uio
->uio_segflg
) {
158 if (fuword8((uint8_t *) p
, &tmp
))
169 EXPORT_SYMBOL(uio_prefaultpages
);
172 * same as uiomove() but doesn't modify uio structure.
173 * return in cbytes how many bytes were copied.
176 uiocopy(void *p
, size_t n
, enum uio_rw rw
, struct uio
*uio
, size_t *cbytes
)
182 iovcnt
= uio
->uio_iovcnt
;
185 for (iov
= uio
->uio_iov
; n
&& iovcnt
; iov
++, iovcnt
--) {
186 cnt
= MIN(iov
->iov_len
, n
);
190 switch (uio
->uio_segflg
) {
195 * p = kernel data pointer
196 * iov->iov_base = user data pointer
198 if (rw
== UIO_READ
) {
199 /* UIO_READ = copy data from kernel to user */
200 if (copy_to_user(iov
->iov_base
, p
, cnt
))
203 /* UIO_WRITE = copy data from user to kernel */
204 if (copy_from_user(p
, iov
->iov_base
, cnt
))
211 bcopy(p
, iov
->iov_base
, cnt
);
213 bcopy(iov
->iov_base
, p
, cnt
);
216 p
= (caddr_t
)p
+ cnt
;
222 EXPORT_SYMBOL(uiocopy
);
225 * Drop the next n chars out of *uiop.
228 uioskip(uio_t
*uiop
, size_t n
)
230 if (n
> uiop
->uio_resid
)
233 iovec_t
*iovp
= uiop
->uio_iov
;
234 size_t niovb
= MIN(iovp
->iov_len
, n
);
241 iovp
->iov_base
+= niovb
;
242 uiop
->uio_loffset
+= niovb
;
243 iovp
->iov_len
-= niovb
;
244 uiop
->uio_resid
-= niovb
;
248 EXPORT_SYMBOL(uioskip
);