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.
34 .Nd device driver IO routines
41 struct iovec *uio_iov;
45 enum uio_seg uio_segflg;
47 struct proc *uio_procp;
51 .Fn uiomove "caddr_t buf" "int howmuch" "struct uio *uiop"
55 is used to handle transfer of data between buffers and IO vectors
56 that might possibly also cross the user/kernel space boundary.
64 system call that is being passed to a character-device driver, the
69 entry will be called with a pointer to a
71 being passed. The transfer request is encoded in this structure.
72 The driver itself should use
74 to get at the data in this structure.
76 The fields in the uio structure are:
77 .Bl -tag -width "uio_iovcntXXXX" -compact
79 The array of IO vectors to be processed. In the case of scatter/gather
80 IO, this will be more than one vector.
82 The number of IO vectors present.
84 The offset into the device.
86 The number of bytes to process.
88 One of the following flags:
89 .Bl -tag -width "UIO_USERISPACEX" -compact
91 The IO vector points into a process's address space.
93 The IO vector points into the kernel address space.
95 The IO vector points into the instruction area of a process's address
98 Don't copy, already in object.
101 The direction of the desired transfer, either
108 for the associated process; used if
110 indicates that the transfer is to be made from/to a process's address
114 The idea is that the driver maintains a private buffer for its data,
115 and processes the request in chunks of maximal the size of this
116 buffer. Note that the buffer handling below is very simplified and
117 won't work (the buffer pointer is not being advanced in case of a
118 partial read), it's just here to demonstrate the uio handling.
120 /* MIN() can be found there: */
121 #include <sys/param.h>
124 static char buffer[BUFSIZE];
126 static int data_available; /* amount of data that can be read */
129 fooread(dev_t dev, struct uio *uio, int flag)
133 while (uio->uio_resid > 0) {
134 if (data_available > 0) {
135 amnt = MIN(uio->uio_resid, data_available);
136 if ((rv = uiomove((caddr_t)buffer, amnt, uio))
139 data_available -= amnt;
141 tsleep(...); /* wait for a better time */
146 /* do error cleanup here */
159 in case the transfer was to/from a process's address space.
169 The uio mechanism appeared in some early version of
172 This man page was written by