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 static void 49 zfs_freeuio(struct uio *uio) 50 { 51 #if __FreeBSD_version > 1500013 52 freeuio(uio); 53 #else 54 free(uio, M_IOV); 55 #endif 56 } 57 58 int 59 zfs_uiomove(void *cp, size_t n, zfs_uio_rw_t dir, zfs_uio_t *uio) 60 { 61 ASSERT3U(zfs_uio_rw(uio), ==, dir); 62 return (uiomove(cp, (int)n, GET_UIO_STRUCT(uio))); 63 } 64 65 /* 66 * same as zfs_uiomove() but doesn't modify uio structure. 67 * return in cbytes how many bytes were copied. 68 */ 69 int 70 zfs_uiocopy(void *p, size_t n, zfs_uio_rw_t rw, zfs_uio_t *uio, size_t *cbytes) 71 { 72 struct iovec small_iovec[1]; 73 struct uio small_uio_clone; 74 struct uio *uio_clone; 75 int error; 76 77 ASSERT3U(zfs_uio_rw(uio), ==, rw); 78 if (zfs_uio_iovcnt(uio) == 1) { 79 small_uio_clone = *(GET_UIO_STRUCT(uio)); 80 small_iovec[0] = *(GET_UIO_STRUCT(uio)->uio_iov); 81 small_uio_clone.uio_iov = small_iovec; 82 uio_clone = &small_uio_clone; 83 } else { 84 uio_clone = cloneuio(GET_UIO_STRUCT(uio)); 85 } 86 87 error = vn_io_fault_uiomove(p, n, uio_clone); 88 *cbytes = zfs_uio_resid(uio) - uio_clone->uio_resid; 89 if (uio_clone != &small_uio_clone) 90 zfs_freeuio(uio_clone); 91 return (error); 92 } 93 94 /* 95 * Drop the next n chars out of *uiop. 96 */ 97 void 98 zfs_uioskip(zfs_uio_t *uio, size_t n) 99 { 100 zfs_uio_seg_t segflg; 101 102 /* For the full compatibility with illumos. */ 103 if (n > zfs_uio_resid(uio)) 104 return; 105 106 segflg = zfs_uio_segflg(uio); 107 zfs_uio_segflg(uio) = UIO_NOCOPY; 108 zfs_uiomove(NULL, n, zfs_uio_rw(uio), uio); 109 zfs_uio_segflg(uio) = segflg; 110 } 111 112 int 113 zfs_uio_fault_move(void *p, size_t n, zfs_uio_rw_t dir, zfs_uio_t *uio) 114 { 115 ASSERT3U(zfs_uio_rw(uio), ==, dir); 116 return (vn_io_fault_uiomove(p, n, GET_UIO_STRUCT(uio))); 117 } 118