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 http://www.opensolaris.org/os/licensing. 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 */ 41 42 #include <sys/types.h> 43 #include <sys/uio.h> 44 #include <sys/vnode.h> 45 46 /* 47 * same as uiomove() but doesn't modify uio structure. 48 * return in cbytes how many bytes were copied. 49 */ 50 int 51 uiocopy(void *p, size_t n, enum uio_rw rw, struct uio *uio, size_t *cbytes) 52 { 53 struct iovec small_iovec[1]; 54 struct uio small_uio_clone; 55 struct uio *uio_clone; 56 int error; 57 58 ASSERT3U(uio->uio_rw, ==, rw); 59 if (uio->uio_iovcnt == 1) { 60 small_uio_clone = *uio; 61 small_iovec[0] = *uio->uio_iov; 62 small_uio_clone.uio_iov = small_iovec; 63 uio_clone = &small_uio_clone; 64 } else { 65 uio_clone = cloneuio(uio); 66 } 67 68 error = vn_io_fault_uiomove(p, n, uio_clone); 69 *cbytes = uio->uio_resid - uio_clone->uio_resid; 70 if (uio_clone != &small_uio_clone) 71 free(uio_clone, M_IOV); 72 return (error); 73 } 74 75 /* 76 * Drop the next n chars out of *uiop. 77 */ 78 void 79 uioskip(uio_t *uio, size_t n) 80 { 81 enum uio_seg segflg; 82 83 /* For the full compatibility with illumos. */ 84 if (n > uio->uio_resid) 85 return; 86 87 segflg = uio->uio_segflg; 88 uio->uio_segflg = UIO_NOCOPY; 89 uiomove(NULL, n, uio->uio_rw, uio); 90 uio->uio_segflg = segflg; 91 } 92