1 /* 2 * CDDL HEADER START 3 * 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. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or https://opensource.org/licenses/CDDL-1.0. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 27 /* All Rights Reserved */ 28 29 /* 30 * University Copyright- Copyright (c) 1982, 1986, 1988 31 * The Regents of the University of California 32 * All Rights Reserved 33 * 34 * University Acknowledgment- Portions of this document are derived from 35 * software developed by the University of California, Berkeley, and its 36 * contributors. 37 */ 38 39 /* 40 * $FreeBSD$ 41 */ 42 43 #include <sys/param.h> 44 #include <sys/uio_impl.h> 45 #include <sys/vnode.h> 46 #include <sys/zfs_znode.h> 47 48 int 49 zfs_uiomove(void *cp, size_t n, zfs_uio_rw_t dir, zfs_uio_t *uio) 50 { 51 ASSERT3U(zfs_uio_rw(uio), ==, dir); 52 return (uiomove(cp, (int)n, GET_UIO_STRUCT(uio))); 53 } 54 55 /* 56 * same as zfs_uiomove() but doesn't modify uio structure. 57 * return in cbytes how many bytes were copied. 58 */ 59 int 60 zfs_uiocopy(void *p, size_t n, zfs_uio_rw_t rw, zfs_uio_t *uio, size_t *cbytes) 61 { 62 struct iovec small_iovec[1]; 63 struct uio small_uio_clone; 64 struct uio *uio_clone; 65 int error; 66 67 ASSERT3U(zfs_uio_rw(uio), ==, rw); 68 if (zfs_uio_iovcnt(uio) == 1) { 69 small_uio_clone = *(GET_UIO_STRUCT(uio)); 70 small_iovec[0] = *(GET_UIO_STRUCT(uio)->uio_iov); 71 small_uio_clone.uio_iov = small_iovec; 72 uio_clone = &small_uio_clone; 73 } else { 74 uio_clone = cloneuio(GET_UIO_STRUCT(uio)); 75 } 76 77 error = vn_io_fault_uiomove(p, n, uio_clone); 78 *cbytes = zfs_uio_resid(uio) - uio_clone->uio_resid; 79 if (uio_clone != &small_uio_clone) 80 free(uio_clone, M_IOV); 81 return (error); 82 } 83 84 /* 85 * Drop the next n chars out of *uiop. 86 */ 87 void 88 zfs_uioskip(zfs_uio_t *uio, size_t n) 89 { 90 zfs_uio_seg_t segflg; 91 92 /* For the full compatibility with illumos. */ 93 if (n > zfs_uio_resid(uio)) 94 return; 95 96 segflg = zfs_uio_segflg(uio); 97 zfs_uio_segflg(uio) = UIO_NOCOPY; 98 zfs_uiomove(NULL, n, zfs_uio_rw(uio), uio); 99 zfs_uio_segflg(uio) = segflg; 100 } 101 102 int 103 zfs_uio_fault_move(void *p, size_t n, zfs_uio_rw_t dir, zfs_uio_t *uio) 104 { 105 ASSERT3U(zfs_uio_rw(uio), ==, dir); 106 return (vn_io_fault_uiomove(p, n, GET_UIO_STRUCT(uio))); 107 } 108