]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/doc/psd/05.sysman/2.1.t
Merge llvm-project release/17.x llvmorg-17.0.0-rc4-10-g0176e8729ea4
[FreeBSD/FreeBSD.git] / share / doc / psd / 05.sysman / 2.1.t
1 .\" Copyright (c) 1983, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .sh "Generic operations
29 .PP
30 .PP
31 Many system abstractions support the
32 operations \fIread\fP, \fIwrite\fP and \fIioctl\fP.  We describe
33 the basics of these common primitives here.
34 Similarly, the mechanisms whereby normally synchronous operations
35 may occur in a non-blocking or asynchronous fashion are
36 common to all system-defined abstractions and are described here.
37 .NH 3
38 Read and write
39 .PP
40 The \fIread\fP and \fIwrite\fP system calls can be applied
41 to communications channels, files, terminals and devices.
42 They have the form:
43 .DS
44 cc = read(fd, buf, nbytes);
45 result int cc; int fd; result caddr_t buf; int nbytes;
46
47 cc = write(fd, buf, nbytes);
48 result int cc; int fd; caddr_t buf; int nbytes;
49 .DE
50 The \fIread\fP call transfers as much data as possible from the
51 object defined by \fIfd\fP to the buffer at address \fIbuf\fP of
52 size \fInbytes\fP.  The number of bytes transferred is
53 returned in \fIcc\fP, which is \-1 if a return occurred before
54 any data was transferred because of an error or use of non-blocking
55 operations.
56 .PP
57 The \fIwrite\fP call transfers data from the buffer to the
58 object defined by \fIfd\fP.  Depending on the type of \fIfd\fP,
59 it is possible that the \fIwrite\fP call will accept some portion
60 of the provided bytes; the user should resubmit the other bytes
61 in a later request in this case.
62 Error returns because of interrupted or otherwise incomplete operations
63 are possible.
64 .PP
65 Scattering of data on input or gathering of data for output
66 is also possible using an array of input/output vector descriptors.
67 The type for the descriptors is defined in \fI<sys/uio.h>\fP as:
68 .DS
69 ._f
70 struct iovec {
71         caddr_t iov_msg;        /* base of a component */
72         int     iov_len;        /* length of a component */
73 };
74 .DE
75 The calls using an array of descriptors are:
76 .DS
77 cc = readv(fd, iov, iovlen);
78 result int cc; int fd; struct iovec *iov; int iovlen;
79
80 cc = writev(fd, iov, iovlen);
81 result int cc; int fd; struct iovec *iov; int iovlen;
82 .DE
83 Here \fIiovlen\fP is the count of elements in the \fIiov\fP array.
84 .NH 3
85 Input/output control
86 .PP
87 Control operations on an object are performed by the \fIioctl\fP
88 operation:
89 .DS
90 ioctl(fd, request, buffer);
91 int fd, request; caddr_t buffer;
92 .DE
93 This operation causes the specified \fIrequest\fP to be performed
94 on the object \fIfd\fP.  The \fIrequest\fP parameter specifies
95 whether the argument buffer is to be read, written, read and written,
96 or is not needed, and also the size of the buffer, as well as the
97 request.
98 Different descriptor types and subtypes within descriptor types
99 may use distinct \fIioctl\fP requests.  For example,
100 operations on terminals control flushing of input and output
101 queues and setting of terminal parameters; operations on
102 disks cause formatting operations to occur; operations on tapes
103 control tape positioning.
104 .PP
105 The names for basic control operations are defined in \fI<sys/ioctl.h>\fP.
106 .NH 3
107 Non-blocking and asynchronous operations
108 .PP
109 A process that wishes to do non-blocking operations on one of
110 its descriptors sets the descriptor in non-blocking mode as
111 described in section 1.5.4.  Thereafter the \fIread\fP call will
112 return a specific EWOULDBLOCK error indication if there is no data to be
113 \fIread\fP.  The process may
114 \fIselect\fP the associated descriptor to determine when a read is
115 possible.
116 .PP
117 Output attempted when a descriptor can accept less than is requested
118 will either accept some of the provided data, returning a shorter than normal
119 length, or return an error indicating that the operation would block.
120 More output can be performed as soon as a \fIselect\fP call indicates
121 the object is writeable.
122 .PP
123 Operations other than data input or output
124 may be performed on a descriptor in a non-blocking fashion.
125 These operations will return with a characteristic error indicating
126 that they are in progress
127 if they cannot complete immediately.  The descriptor
128 may then be \fIselect\fPed for \fIwrite\fP to find out
129 when the operation has been completed.  When \fIselect\fP indicates
130 the descriptor is writeable, the operation has completed.
131 Depending on the nature of the descriptor and the operation,
132 additional activity may be started or the new state may be tested.