xref: /netbsd/share/man/man9/uiomove.9 (revision 6550d01e)
1.\"	$NetBSD: uiomove.9,v 1.17 2010/04/26 07:51:36 jruoho 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.Pp
71.Bl -tag -width "uio_vmspace "
72.It Va uio_iov
73Pointer to array of
74.Tn I/O
75vectors to be processed.
76The
77.Va struct iovec
78is defined to be:
79.Bd -literal -offset indent
80struct iovec {
81	void	*iov_base;
82	size_t	 iov_len;
83};
84.Ed
85.Pp
86The members in the
87.Va struct iovec
88should only be initialized.
89These are:
90.Bl -tag -width "*iov_base " -offset indent
91.It Va iov_base
92The address for a range of memory to or from which data is transferred.
93.It Va iov_len
94The number of bytes of data to be transferred to
95or from the range of memory starting at
96.Va iov_base .
97.El
98.It Va uio_iovcnt
99The number of
100.Tn I/O
101vectors in the
102.Va uio_iov
103array.
104.It Va uio_offset
105An offset into the corresponding object.
106.It Va uio_resid
107The amount of space described by the structure; notionally, the amount
108of data remaining to be transferred.
109.It Va uio_rw
110A flag indicating whether data should be read into the space
111(UIO_READ) or written from the space (UIO_WRITE).
112.It Va uio_vmspace
113A pointer to the address space which is being transferred to or from.
114.El
115.Pp
116The value of
117.Va uio-\*[Gt]uio_rw
118controls whether
119.Fn uiomove
120copies data from
121.Fa buf
122to
123.Fa uio
124or vice versa.
125.Pp
126The lesser of
127.Fa n
128or
129.Va uio-\*[Gt]uio_resid
130bytes are copied.
131.Pp
132.Fn uiomove
133changes fields of the structure pointed to by
134.Fa uio ,
135such that
136.Va uio-\*[Gt]uio_resid
137is decremented by the amount of data moved,
138.Va uio-\*[Gt]uio_offset
139is incremented by the same amount, and the array of iovecs is adjusted
140to point that much farther into the region described.
141This allows multiple calls to
142.Fn uiomove
143to easily be used to fill or drain the region of data.
144.Sh RETURN VALUES
145Upon successful completion,
146.Fn uiomove
147returns 0.
148If a bad address is encountered,
149.Er EFAULT
150is returned.
151.Sh SEE ALSO
152.Xr copy 9 ,
153.Xr fetch 9 ,
154.Xr store 9
155