xref: /netbsd-src/share/man/man9/uiomove.9 (revision 181254a7b1bdde6873432bffef2d2decc4b5c22f)
1.\"	$NetBSD: uiomove.9,v 1.20 2019/09/01 19:08:35 wiz Exp $
2.\"
3.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25.\" POSSIBILITY OF SUCH DAMAGE.
26.\"
27.Dd April 26, 2010
28.Dt UIOMOVE 9
29.Os
30.Sh NAME
31.Nm uiomove
32.Nd move data described by a struct uio
33.Sh SYNOPSIS
34.In sys/systm.h
35.Ft int
36.Fn uiomove "void *buf" "size_t n" "struct uio *uio"
37.Sh DESCRIPTION
38The
39.Fn uiomove
40function copies up to
41.Fa n
42bytes between the kernel-space address pointed
43to by
44.Fa buf
45and the addresses described by
46.Fa uio ,
47which may be in user-space or kernel-space.
48.Pp
49The
50.Fa uio
51argument is a pointer to a
52.Va struct uio
53as defined by
54.In sys/uio.h :
55.Bd -literal -offset indent
56struct uio {
57	struct	iovec *uio_iov;
58	int	uio_iovcnt;
59	off_t	uio_offset;
60	size_t	uio_resid;
61	enum	uio_rw uio_rw;
62	struct	vmspace *uio_vmspace;
63};
64.Ed
65.Pp
66A
67.Va struct uio
68typically describes data in motion.
69Several of the fields described below reflect that expectation.
70.Bl -tag -width "uio_vmspace "
71.It Va uio_iov
72Pointer to array of
73.Tn I/O
74vectors to be processed.
75The
76.Va struct iovec
77is defined to be:
78.Bd -literal -offset indent
79struct iovec {
80	void	*iov_base;
81	size_t	 iov_len;
82};
83.Ed
84.Pp
85The members in the
86.Va struct iovec
87should only be initialized.
88These are:
89.Bl -tag -width "*iov_base " -offset indent
90.It Va iov_base
91The address for a range of memory to or from which data is transferred.
92.It Va iov_len
93The number of bytes of data to be transferred to
94or from the range of memory starting at
95.Va iov_base .
96.El
97.It Va uio_iovcnt
98The number of
99.Tn I/O
100vectors in the
101.Va uio_iov
102array.
103.It Va uio_offset
104An offset into the corresponding object.
105.It Va uio_resid
106The amount of space described by the structure; notionally, the amount
107of data remaining to be transferred.
108.It Va uio_rw
109A flag indicating whether data should be read into the space
110(UIO_READ) or written from the space (UIO_WRITE).
111.It Va uio_vmspace
112A pointer to the address space which is being transferred to or from.
113.El
114.Pp
115The value of
116.Va uio->uio_rw
117controls whether
118.Fn uiomove
119copies data from
120.Fa buf
121to
122.Fa uio
123or vice versa.
124.Pp
125The lesser of
126.Fa n
127or
128.Va uio->uio_resid
129bytes are copied.
130.Pp
131.Fn uiomove
132changes fields of the structure pointed to by
133.Fa uio ,
134such that
135.Va uio->uio_resid
136is decremented by the amount of data moved,
137.Va uio->uio_offset
138is incremented by the same amount, and the array of iovecs is adjusted
139to point that much farther into the region described.
140This allows multiple calls to
141.Fn uiomove
142to easily be used to fill or drain the region of data.
143.Sh RETURN VALUES
144Upon successful completion,
145.Fn uiomove
146returns 0.
147If a bad address is encountered,
148.Er EFAULT
149is returned.
150.Sh SEE ALSO
151.Xr copy 9 ,
152.Xr ufetch 9 ,
153.Xr ustore 9
154