11553Srgrimes/*
21553Srgrimes * CDDL HEADER START
31553Srgrimes *
41553Srgrimes * The contents of this file are subject to the terms of the
51553Srgrimes * Common Development and Distribution License (the "License").
61553Srgrimes * You may not use this file except in compliance with the License.
71553Srgrimes *
81553Srgrimes * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91553Srgrimes * or http://www.opensolaris.org/os/licensing.
101553Srgrimes * See the License for the specific language governing permissions
111553Srgrimes * and limitations under the License.
121553Srgrimes *
131553Srgrimes * When distributing Covered Code, include this CDDL HEADER in each
141553Srgrimes * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151553Srgrimes * If applicable, add the following below this CDDL HEADER, with the
161553Srgrimes * fields enclosed by brackets "[]" replaced with your own identifying
171553Srgrimes * information: Portions Copyright [yyyy] [name of copyright owner]
181553Srgrimes *
191553Srgrimes * CDDL HEADER END
201553Srgrimes */
211553Srgrimes/*
221553Srgrimes * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
231553Srgrimes * Use is subject to license terms.
241553Srgrimes */
251553Srgrimes
261553Srgrimes/*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
271553Srgrimes/*        All Rights Reserved   */
281553Srgrimes
291553Srgrimes/*
301553Srgrimes * University Copyright- Copyright (c) 1982, 1986, 1988
3130642Scharnier * The Regents of the University of California
321553Srgrimes * All Rights Reserved
331553Srgrimes *
341553Srgrimes * University Acknowledgment- Portions of this document are derived from
351553Srgrimes * software developed by the University of California, Berkeley, and its
361553Srgrimes * contributors.
3730642Scharnier */
381553Srgrimes
3930642Scharnier/*
4030642Scharnier */
4150479Speter
421553Srgrimes#include <sys/types.h>
431553Srgrimes#include <sys/uio.h>
441553Srgrimes#include <sys/vnode.h>
451553Srgrimes
4630642Scharnier/*
471553Srgrimes * same as uiomove() but doesn't modify uio structure.
4830642Scharnier * return in cbytes how many bytes were copied.
491553Srgrimes */
50116078Simpint
511553Srgrimesuiocopy(void *p, size_t n, enum uio_rw rw, struct uio *uio, size_t *cbytes)
5230642Scharnier{
531553Srgrimes	struct iovec small_iovec[1];
541553Srgrimes	struct uio small_uio_clone;
551553Srgrimes	struct uio *uio_clone;
561553Srgrimes	int error;
571553Srgrimes
58120995Stjr	ASSERT3U(uio->uio_rw, ==, rw);
59120995Stjr	if (uio->uio_iovcnt == 1) {
601553Srgrimes		small_uio_clone = *uio;
611553Srgrimes		small_iovec[0] = *uio->uio_iov;
62173412Skevlo		small_uio_clone.uio_iov = small_iovec;
631553Srgrimes		uio_clone = &small_uio_clone;
641553Srgrimes	} else {
65246209Scharnier		uio_clone = cloneuio(uio);
661553Srgrimes	}
671553Srgrimes
681553Srgrimes	error = vn_io_fault_uiomove(p, n, uio_clone);
691553Srgrimes	*cbytes = uio->uio_resid - uio_clone->uio_resid;
701553Srgrimes	if (uio_clone != &small_uio_clone)
711553Srgrimes		freeuio(uio_clone);
721553Srgrimes	return (error);
731553Srgrimes}
7430642Scharnier
7530642Scharnier/*
76220970Ssimon * Drop the next n chars out of *uiop.
77220970Ssimon */
781553Srgrimesvoid
791553Srgrimesuioskip(uio_t *uio, size_t n)
801553Srgrimes{
811553Srgrimes	enum uio_seg segflg;
821553Srgrimes
831553Srgrimes	/* For the full compatibility with illumos. */
841553Srgrimes	if (n > uio->uio_resid)
851553Srgrimes		return;
861553Srgrimes
871553Srgrimes	segflg = uio->uio_segflg;
881553Srgrimes	uio->uio_segflg = UIO_NOCOPY;
891553Srgrimes	uiomove(NULL, n, uio->uio_rw, uio);
901553Srgrimes	uio->uio_segflg = segflg;
911553Srgrimes}
921553Srgrimes