]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/uio.9
This commit was generated by cvs2svn to compensate for changes in r138298,
[FreeBSD/FreeBSD.git] / share / man / man9 / uio.9
1 .\"
2 .\" Copyright (c) 1997 Joerg Wunsch
3 .\"
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 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.
25 .\"
26 .\" $FreeBSD$
27 .\"
28 .Dd February 2, 1997
29 .Os
30 .Dt UIO 9
31 .Sh NAME
32 .Nm uio ,
33 .Nm uiomove
34 .Nd device driver I/O routines
35 .Sh SYNOPSIS
36 .In sys/types.h
37 .In sys/uio.h
38 .Pp
39 .Bd -literal
40 struct uio {
41         struct  iovec *uio_iov;
42         int     uio_iovcnt;
43         off_t   uio_offset;
44         int     uio_resid;
45         enum    uio_seg uio_segflg;
46         enum    uio_rw uio_rw;
47         struct  thread *uio_td;
48 };
49 .Ed
50 .Ft int
51 .Fn uiomove "void *buf" "int howmuch" "struct uio *uiop"
52 .Sh DESCRIPTION
53 The function
54 .Fn uiomove
55 is used to handle transfer of data between buffers and I/O vectors
56 that might possibly also cross the user/kernel space boundary.
57 .Pp
58 As a result of any
59 .Xr read 2 ,
60 .Xr write 2 ,
61 .Xr readv 2 ,
62 or
63 .Xr writev 2
64 system call that is being passed to a character-device driver, the
65 appropriate driver
66 .Va d_read
67 or
68 .Va d_write
69 entry will be called with a pointer to a
70 .Vt "struct uio"
71 being passed.
72 The transfer request is encoded in this structure.
73 The driver itself should use
74 .Fn uiomove
75 to get at the data in this structure.
76 .Pp
77 The fields in the
78 .Vt uio
79 structure are:
80 .Bl -tag -width ".Va uio_iovcnt"
81 .It Va uio_iov
82 The array of I/O vectors to be processed.
83 In the case of scatter/gather
84 I/O, this will be more than one vector.
85 .It Va uio_iovcnt
86 The number of I/O vectors present.
87 .It Va uio_offset
88 The offset into the device.
89 .It Va uio_resid
90 The number of bytes to process.
91 .It Va uio_segflg
92 One of the following flags:
93 .Bl -tag -width ".Dv UIO_USERSPACE"
94 .It Dv UIO_USERSPACE
95 The I/O vector points into a process's address space.
96 .It Dv UIO_SYSSPACE
97 The I/O vector points into the kernel address space.
98 .It Dv UIO_NOCOPY
99 Don't copy, already in object.
100 .El
101 .It Va uio_rw
102 The direction of the desired transfer, either
103 .Dv UIO_READ ,
104 or
105 .Dv UIO_WRITE .
106 .It Va uio_td
107 The pointer to a
108 .Vt "struct thread"
109 for the associated thread; used if
110 .Va uio_segflg
111 indicates that the transfer is to be made from/to a process's address
112 space.
113 .El
114 .Sh EXAMPLES
115 The idea is that the driver maintains a private buffer for its data,
116 and processes the request in chunks of maximal the size of this
117 buffer.
118 Note that the buffer handling below is very simplified and
119 won't work (the buffer pointer is not being advanced in case of a
120 partial read), it's just here to demonstrate the
121 .Nm
122 handling.
123 .Bd -literal
124 /* MIN() can be found there: */
125 #include <sys/param.h>
126
127 #define BUFSIZE 512
128 static char buffer[BUFSIZE];
129
130 static int data_available;      /* amount of data that can be read */
131
132 static int
133 fooread(dev_t dev, struct uio *uio, int flag)
134 {
135         int rv, amnt;
136
137         rv = 0;
138         while (uio->uio_resid > 0) {
139                 if (data_available > 0) {
140                         amnt = MIN(uio->uio_resid, data_available);
141                         rv = uiomove(buffer, amnt, uio);
142                         if (rv != 0)
143                                 break;
144                         data_available -= amnt;
145                 } else
146                         tsleep(...);    /* wait for a better time */
147         }
148         if (rv != 0) {
149                 /* do error cleanup here */
150         }
151         return (rv);
152 }
153 .Ed
154 .Sh RETURN VALUES
155 .Fn uiomove
156 can return
157 .Er EFAULT
158 from the invoked
159 .Xr copyin 9
160 or
161 .Xr copyout 9
162 in case the transfer was to/from a process's address space.
163 .Sh SEE ALSO
164 .Xr read 2 ,
165 .Xr readv 2 ,
166 .Xr write 2 ,
167 .Xr writev 2 ,
168 .Xr copyin 9 ,
169 .Xr copyout 9 ,
170 .Xr sleep 9
171 .Sh HISTORY
172 The
173 .Nm
174 mechanism appeared in some early version of
175 .Ux .
176 .Sh AUTHORS
177 This man page was written by
178 .An J\(:org Wunsch .