/* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Nexenta Systems, Inc. All rights reserved. */ #include #include #include #include #include #include /* * Move "n" bytes at byte address "p"; "rw" indicates the direction * of the move, and the I/O parameters are provided in "uio", which is * update to reflect the data which was moved. Returns 0 on success or * a non-zero errno on failure. */ int uiomove(void *p, size_t n, enum uio_rw rw, struct uio *uio) { struct iovec *iov; ulong_t cnt; while (n && uio->uio_resid) { iov = uio->uio_iov; cnt = MIN(iov->iov_len, n); if (cnt == 0L) { uio->uio_iov++; uio->uio_iovcnt--; continue; } switch (uio->uio_segflg) { case UIO_USERSPACE: case UIO_USERISPACE: return (EINVAL); case UIO_SYSSPACE: if (rw == UIO_READ) bcopy(p, iov->iov_base, cnt); else bcopy(iov->iov_base, p, cnt); break; } iov->iov_base += cnt; iov->iov_len -= cnt; uio->uio_resid -= cnt; uio->uio_loffset += cnt; p = (caddr_t)p + cnt; n -= cnt; } return (0); }