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.
26 .\" $FreeBSD: src/share/man/man9/uio.9,v 1.5.2.4 2001/12/17 11:30:19 ru Exp $
34 .Nd device driver I/O routines
40 struct iovec *uio_iov;
44 enum uio_seg uio_segflg;
46 struct thread *uio_td;
50 .Fn uiomove "caddr_t buf" "size_t howmuch" "struct uio *uiop"
54 is used to handle transfer of data between buffers and I/O vectors
55 that might possibly also cross the user/kernel space boundary.
63 system call that is being passed to a character-device driver, the
68 entry will be called with a pointer to a
69 .Vt "struct dev_read_args"
71 .Vt "struct dev_write_args"
73 a member of which is a pointer to a
75 The transfer request is encoded in this structure.
76 The driver itself should use
78 to get at the data in this structure.
83 .Bl -tag -width ".Va uio_iovcnt"
85 The array of I/O vectors to be processed.
86 In the case of scatter/gather
87 I/O, this will be more than one vector.
89 The number of I/O vectors present.
91 The offset into the device.
93 The number of bytes to process.
95 One of the following flags:
96 .Bl -tag -width ".Dv UIO_USERSPACE"
98 The I/O vector points into a process's address space.
100 The I/O vector points into the kernel address space.
102 Don't copy, already in object.
105 The direction of the desired transfer, either
112 for the associated thread; used if
114 indicates that the transfer is to be made from/to a process's address
125 in case the transfer was to/from a process's address space.
127 The idea is that the driver maintains a private buffer for its data,
128 and processes the request in chunks of maximal the size of this
130 Note that the buffer handling below is very simplified and
131 won't work (the buffer pointer is not being advanced in case of a
132 partial read), it's just here to demonstrate the
136 /* MIN() can be found there: */
137 #include <sys/param.h>
140 static char buffer[BUFSIZE];
142 static int data_available; /* amount of data that can be read */
145 fooread(struct dev_read_args *ap)
147 cdev_t dev = ap->a_head.a_dev;
150 while (ap->a_uio->uio_resid > 0) {
151 if (data_available > 0) {
152 amnt = MIN(ap->a_uio->uio_resid, data_available);
153 if ((rv = uiomove((caddr_t)buffer, amnt, ap->a_uio))
156 data_available -= amnt;
158 tsleep(...); /* wait for a better time */
163 /* do error cleanup here */
179 mechanism appeared in some early version of
182 This man page was written by