2 .\" Copyright (c) 1997 Joerg Wunsch
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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.
15 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 .Nd device driver I/O routines
42 struct iovec *uio_iov; /* scatter/gather list */
43 int uio_iovcnt; /* length of scatter/gather list */
44 off_t uio_offset; /* offset in target object */
45 ssize_t uio_resid; /* remaining bytes to copy */
46 enum uio_seg uio_segflg; /* address space */
47 enum uio_rw uio_rw; /* operation */
48 struct thread *uio_td; /* owner */
52 .Fn uiomove "void *buf" "int howmuch" "struct uio *uiop"
54 .Fn uiomove_frombuf "void *buf" "int howmuch" "struct uio *uiop"
56 .Fn uiomove_nofault "void *buf" "int howmuch" "struct uio *uiop"
63 are used to transfer data between buffers and I/O vectors that might
64 possibly cross the user/kernel space boundary.
72 system call that is being passed to a character-device driver, the
77 entry will be called with a pointer to a
80 The transfer request is encoded in this structure.
81 The driver itself should use
85 to get at the data in this structure.
90 .Bl -tag -width ".Va uio_iovcnt"
92 The array of I/O vectors to be processed.
93 In the case of scatter/gather
94 I/O, this will be more than one vector.
96 The number of I/O vectors present.
98 The offset into the device.
100 The remaining number of bytes to process, updated after transfer.
102 One of the following flags:
103 .Bl -tag -width ".Dv UIO_USERSPACE"
105 The I/O vector points into a process's address space.
107 The I/O vector points into the kernel address space.
109 Do not copy, already in object.
112 The direction of the desired transfer, either
119 for the associated thread; used if
121 indicates that the transfer is to be made from/to a process's address
127 requires that the buffer and I/O vectors be accessible without
128 incurring a page fault.
129 The source and destination addresses must be physically mapped for
130 read and write access, respectively, and neither the source nor
131 destination addresses may be pageable.
134 can be called from contexts where acquiring virtual memory system
135 locks or sleeping are prohibited.
139 function is a convenience wrapper around
141 for drivers that serve data which is wholly contained within an
142 existing buffer in memory.
147 values against the size of the existing buffer, handling short
148 transfers when the request partially overlaps the buffer.
151 is greater than or equal to the buffer size, the result is success
152 with no bytes transferred, effectively signaling EOF.
156 .Fn uiomove_frombuf ,
159 will return 0; on error they will return an appropriate error code.
161 The idea is that the driver maintains a private buffer for its data,
162 and processes the request in chunks of maximal the size of this
164 Note that the buffer handling below is very simplified and
165 will not work (the buffer pointer is not being advanced in case of a
166 partial read), it is just here to demonstrate the
170 /* MIN() can be found there: */
171 #include <sys/param.h>
174 static char buffer[BUFSIZE];
176 static int data_available; /* amount of data that can be read */
179 fooread(struct cdev *dev, struct uio *uio, int flag)
184 while (uio->uio_resid > 0) {
185 if (data_available > 0) {
186 amnt = MIN(uio->uio_resid, data_available);
187 rv = uiomove(buffer, amnt, uio);
190 data_available -= amnt;
192 tsleep(...); /* wait for a better time */
195 /* do error cleanup here */
204 will fail and return the following error code if:
217 will fail and return the following error code if:
233 mechanism appeared in some early version of
236 This manual page was written by