xref: /netbsd-src/share/man/man9/uiomove.9 (revision 819a01cff334f9eaf1e295d38ebf36943614d10a)
1.\"	$NetBSD: uiomove.9,v 1.21 2023/05/22 14:07:24 riastradh 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 May 9, 2023
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.Ft int
38.Fn uiopeek "void *buf" "size_t n" "struct uio *uio"
39.Ft void
40.Fn uioskip "void *buf" "size_t n" "struct uio *uio"
41.Sh DESCRIPTION
42The
43.Fn uiomove
44function copies up to
45.Fa n
46bytes between the kernel-space address pointed
47to by
48.Fa buf
49and the addresses described by
50.Fa uio ,
51which may be in user-space or kernel-space.
52.Pp
53The
54.Fa uio
55argument is a pointer to a
56.Va struct uio
57as defined by
58.In sys/uio.h :
59.Bd -literal -offset indent
60struct uio {
61	struct	iovec *uio_iov;
62	int	uio_iovcnt;
63	off_t	uio_offset;
64	size_t	uio_resid;
65	enum	uio_rw uio_rw;
66	struct	vmspace *uio_vmspace;
67};
68.Ed
69.Pp
70A
71.Va struct uio
72typically describes data in motion.
73Several of the fields described below reflect that expectation.
74.Bl -tag -width "uio_vmspace "
75.It Va uio_iov
76Pointer to array of
77.Tn I/O
78vectors to be processed.
79The
80.Va struct iovec
81is defined to be:
82.Bd -literal -offset indent
83struct iovec {
84	void	*iov_base;
85	size_t	 iov_len;
86};
87.Ed
88.Pp
89The members in the
90.Va struct iovec
91should only be initialized.
92These are:
93.Bl -tag -width "*iov_base " -offset indent
94.It Va iov_base
95The address for a range of memory to or from which data is transferred.
96.It Va iov_len
97The number of bytes of data to be transferred to
98or from the range of memory starting at
99.Va iov_base .
100.El
101.It Va uio_iovcnt
102The number of
103.Tn I/O
104vectors in the
105.Va uio_iov
106array.
107.It Va uio_offset
108An offset into the corresponding object.
109.It Va uio_resid
110The amount of space described by the structure; notionally, the amount
111of data remaining to be transferred.
112.It Va uio_rw
113A flag indicating whether data should be read into the space
114(UIO_READ) or written from the space (UIO_WRITE).
115.It Va uio_vmspace
116A pointer to the address space which is being transferred to or from.
117.El
118.Pp
119The value of
120.Va uio->uio_rw
121controls whether
122.Fn uiomove
123copies data from
124.Fa buf
125to
126.Fa uio
127or vice versa.
128.Pp
129The lesser of
130.Fa n
131or
132.Va uio->uio_resid
133bytes are copied.
134.Pp
135.Fn uiomove
136changes fields of the structure pointed to by
137.Fa uio ,
138such that
139.Va uio->uio_resid
140is decremented by the amount of data moved,
141.Va uio->uio_offset
142is incremented by the same amount, and the array of iovecs is adjusted
143to point that much farther into the region described.
144This allows multiple calls to
145.Fn uiomove
146to easily be used to fill or drain the region of data.
147.Pp
148The
149.Fn uiopeek
150function copies up to
151.Fa n
152bytes of data without updating
153.Fa uio ;
154the
155.Fn uioskip
156function updates
157.Fa uio
158without copying any data, and is guaranteed never to sleep or fault
159even if the buffers are in userspace and memory access via
160.Fn uiomove
161or
162.Fn uiopeek
163would trigger paging.
164A successful
165.Fn uiomove buf n uio
166call is equivalent to a successful
167.Fn uiopeek buf n uio
168followed by
169.Fn uioskip n uio .
170.Sh RETURN VALUES
171Upon successful completion,
172.Fn uiomove
173and
174.Fn uiopeek
175return 0.
176If a bad address is encountered,
177.Er EFAULT
178is returned.
179.Sh SEE ALSO
180.Xr copy 9 ,
181.Xr ufetch 9 ,
182.Xr ustore 9
183