1*6ed37069Sjmc.\" $OpenBSD: uiomove.9,v 1.19 2016/03/15 06:49:21 jmc Exp $ 2a5b14370Smillert.\" $NetBSD: uiomove.9,v 1.6 2001/12/26 00:16:30 wiz Exp $ 3a5b14370Smillert.\" 4a5b14370Smillert.\" Copyright (c) 1996 The NetBSD Foundation, Inc. 5a5b14370Smillert.\" All rights reserved. 6a5b14370Smillert.\" 7a5b14370Smillert.\" Redistribution and use in source and binary forms, with or without 8a5b14370Smillert.\" modification, are permitted provided that the following conditions 9a5b14370Smillert.\" are met: 10a5b14370Smillert.\" 1. Redistributions of source code must retain the above copyright 11a5b14370Smillert.\" notice, this list of conditions and the following disclaimer. 12a5b14370Smillert.\" 2. Redistributions in binary form must reproduce the above copyright 13a5b14370Smillert.\" notice, this list of conditions and the following disclaimer in the 14a5b14370Smillert.\" documentation and/or other materials provided with the distribution. 15a5b14370Smillert.\" 16a5b14370Smillert.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17a5b14370Smillert.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18a5b14370Smillert.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19a5b14370Smillert.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20a5b14370Smillert.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21a5b14370Smillert.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22a5b14370Smillert.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23a5b14370Smillert.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24a5b14370Smillert.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25a5b14370Smillert.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26a5b14370Smillert.\" POSSIBILITY OF SUCH DAMAGE. 27a5b14370Smillert.\" 2828b5ebe0Sstefan.Dd $Mdocdate: March 15 2016 $ 29a5b14370Smillert.Dt UIOMOVE 9 30a5b14370Smillert.Os 31a5b14370Smillert.Sh NAME 3228b5ebe0Sstefan.Nm uiomove 33a5b14370Smillert.Nd move data described by a struct uio 34a5b14370Smillert.Sh SYNOPSIS 35dddd2645Sschwarze.In sys/systm.h 36a5b14370Smillert.Ft int 37081bf720Smiod.Fn uiomove "void *buf" "size_t n" "struct uio *uio" 38a5b14370Smillert.Sh DESCRIPTION 39a5b14370SmillertThe 40a5b14370Smillert.Nm 41a5b14370Smillertfunction copies up to 42a5b14370Smillert.Fa n 43a5b14370Smillertbytes between the kernel-space address pointed 44a5b14370Smillertto by 45a5b14370Smillert.Fa buf 46a5b14370Smillertand the addresses described by 47a5b14370Smillert.Fa uio , 48a5b14370Smillertwhich may be in user-space or kernel-space. 49a5b14370Smillert.Pp 50a5b14370SmillertThe 51a5b14370Smillert.Fa uio 52a5b14370Smillertargument is a pointer to a 53a5b14370Smillert.Fa struct uio 54a5b14370Smillertas defined by 55369bef3aSschwarze.In sys/uio.h : 56a5b14370Smillert.Bd -literal 57a5b14370Smillertstruct uio { 58a5b14370Smillert struct iovec *uio_iov; /* pointer to array of iovecs */ 59a5b14370Smillert int uio_iovcnt; /* number of iovecs in array */ 60a5b14370Smillert off_t uio_offset; /* offset into file this uio corresponds to */ 61a5b14370Smillert size_t uio_resid; /* residual i/o count */ 62a5b14370Smillert enum uio_seg uio_segflg; 63a5b14370Smillert enum uio_rw uio_rw; 6419c223fcSuwe struct proc *uio_procp;/* associated process or NULL */ 65a5b14370Smillert}; 66a5b14370Smillert.Ed 67a5b14370Smillert.Pp 68a5b14370SmillertA 69a5b14370Smillert.Fa struct uio 70a5b14370Smillerttypically describes data in motion. 71a5b14370SmillertSeveral of the fields described below reflect that expectation. 72a5b14370Smillert.Bl -tag -width uio_xxxxxx 73a5b14370Smillert.It uio_iov 74a5b14370SmillertPointer to array of 75a5b14370Smillert.Fa struct iovecs : 76a5b14370Smillert.Bd -literal 77a5b14370Smillertstruct iovec { 78a5b14370Smillert void *iov_base; /* Base address. */ 79a5b14370Smillert size_t iov_len; /* Length. */ 80a5b14370Smillert}; 81a5b14370Smillert.Ed 82a5b14370Smillert.It uio_iovcnt 83a5b14370SmillertThe number of iovecs in the array. 84a5b14370Smillert.It uio_offset 85a5b14370SmillertAn offset into the corresponding object. 86a5b14370Smillert.It uio_resid 87a5b14370SmillertThe amount of data remaining to be transferred. 88a5b14370Smillert.It uio_segflg 89a5b14370SmillertA flag indicating whether the space described is in user-space 90a5b14370Smillert(UIO_USERSPACE) or kernel-space (UIO_SYSSPACE). 91a5b14370Smillert.It uio_rw 92500c108aSjmcA flag indicating whether data should be read into the space 93a5b14370Smillert(UIO_READ) or written from the space (UIO_WRITE). 94a5b14370Smillert.It uio_procp 9519c223fcSuweA pointer to a process whose data area is described by the 9619c223fcSuwestructure, or which is having the I/O done on its behalf if 9719c223fcSuwethe area is in kernel-space. 9819c223fcSuwe.Nm uiomove 9919c223fcSuweitself does not use this field if the area is in kernel-space, 10019c223fcSuwebut other functions that take a 10119c223fcSuwe.Fa struct uio 10219c223fcSuwemay depend on this information. 103a5b14370Smillert.El 104a5b14370Smillert.Pp 105a5b14370SmillertThe value of 106a5b14370Smillert.Fa uio->uio_rw 107a5b14370Smillertcontrols whether 108a5b14370Smillert.Nm 109a5b14370Smillertcopies data from 110a5b14370Smillert.Fa buf 111a5b14370Smillertto 112a5b14370Smillert.Fa uio 113a5b14370Smillertor vice versa. 114a5b14370Smillert.Pp 115a5b14370SmillertThe lesser of 116a5b14370Smillert.Fa n 117a5b14370Smillertor 118695828c7Sjmc.Fa uio->uio_resid 119a5b14370Smillertbytes are copied. 120a5b14370Smillert.Pp 121a5b14370Smillert.Nm 122a5b14370Smillertchanges fields of the structure pointed to by 123a5b14370Smillert.Fa uio , 124a5b14370Smillertsuch that 125a5b14370Smillert.Fa uio->uio_resid 126a5b14370Smillertis decremented by the amount of data moved, 127a5b14370Smillert.Fa uio->uio_offset 128a5b14370Smillertis incremented by the same amount, and the array of iovecs is adjusted 129a5b14370Smillertto point that much farther into the region described. 130a5b14370SmillertThis allows multiple calls to 131a5b14370Smillert.Nm 132a5b14370Smillertto easily be used to fill or drain the region of data. 133a5b14370Smillert.Sh RETURN VALUES 134a5b14370Smillert.Nm 135*6ed37069Sjmcreturns 0 on success or EFAULT if a bad address is encountered. 136a5b14370Smillert.Sh SEE ALSO 137c0a75849Smiod.Xr copy 9 138