BSD 4_4_Lite2 release
[unix-history] / usr / src / share / doc / psd / 05.sysman / 2.1.t
index ef25887..d76b753 100644 (file)
@@ -1,4 +1,4 @@
-.\" Copyright (c) 1983, 1993
+.\" Copyright (c) 1983, 1993, 1994
 .\"    The Regents of the University of California.  All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
 .\"    The Regents of the University of California.  All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"    @(#)2.1.t       8.1 (Berkeley) 6/8/93
+.\"    @(#)2.1.t       8.4 (Berkeley) 5/26/94
 .\"
 .\"
-.sh "Generic operations
-.PP
+.Sh 2 "Generic operations
 .PP
 Many system abstractions support the
 .PP
 Many system abstractions support the
-operations \fIread\fP, \fIwrite\fP and \fIioctl\fP.  We describe
-the basics of these common primitives here.
+.Fn read ,
+.Fn write ,
+and
+.Fn ioctl
+operations.
+We describe the basics of these common primitives here.
 Similarly, the mechanisms whereby normally synchronous operations
 may occur in a non-blocking or asynchronous fashion are
 common to all system-defined abstractions and are described here.
 Similarly, the mechanisms whereby normally synchronous operations
 may occur in a non-blocking or asynchronous fashion are
 common to all system-defined abstractions and are described here.
-.NH 3
-Read and write
+.Sh 3 "Read and write
 .PP
 .PP
-The \fIread\fP and \fIwrite\fP system calls can be applied
-to communications channels, files, terminals and devices.
+The
+.Fn read
+and
+.Fn write
+system calls can be applied to communications channels,
+files, terminals and devices.
 They have the form:
 .DS
 They have the form:
 .DS
+.Fd read 3 "read input
 cc = read(fd, buf, nbytes);
 cc = read(fd, buf, nbytes);
-result int cc; int fd; result caddr_t buf; int nbytes;
-
+result ssize_t cc; int fd; result void *buf; size_t nbytes;
+.DE
+.DS
+.Fd write 3 "write output
 cc = write(fd, buf, nbytes);
 cc = write(fd, buf, nbytes);
-result int cc; int fd; caddr_t buf; int nbytes;
+result ssize_t cc; int fd; void *buf; size_t nbytes;
 .DE
 .DE
-The \fIread\fP call transfers as much data as possible from the
+The
+.Fn read
+call transfers as much data as possible from the
 object defined by \fIfd\fP to the buffer at address \fIbuf\fP of
 size \fInbytes\fP.  The number of bytes transferred is
 returned in \fIcc\fP, which is \-1 if a return occurred before
 any data was transferred because of an error or use of non-blocking
 operations.
 object defined by \fIfd\fP to the buffer at address \fIbuf\fP of
 size \fInbytes\fP.  The number of bytes transferred is
 returned in \fIcc\fP, which is \-1 if a return occurred before
 any data was transferred because of an error or use of non-blocking
 operations.
+A return value of 0 is used to indicate an end-of-file condition.
 .PP
 .PP
-The \fIwrite\fP call transfers data from the buffer to the
+The
+.Fn write
+call transfers data from the buffer to the
 object defined by \fIfd\fP.  Depending on the type of \fIfd\fP,
 object defined by \fIfd\fP.  Depending on the type of \fIfd\fP,
-it is possible that the \fIwrite\fP call will accept some portion
-of the provided bytes; the user should resubmit the other bytes
-in a later request in this case.
+it is possible that the
+.Fn write
+call will accept only a portion of the provided bytes;
+the user should resubmit the other bytes in a later request.
 Error returns because of interrupted or otherwise incomplete operations
 Error returns because of interrupted or otherwise incomplete operations
-are possible.
+are possible, in which case no data will have been transferred.
 .PP
 .PP
-Scattering of data on input or gathering of data for output
+Scattering of data on input, or gathering of data for output
 is also possible using an array of input/output vector descriptors.
 The type for the descriptors is defined in \fI<sys/uio.h>\fP as:
 .DS
 is also possible using an array of input/output vector descriptors.
 The type for the descriptors is defined in \fI<sys/uio.h>\fP as:
 .DS
-._f
+.TS
+l s s s
+l l l l.
 struct iovec {
 struct iovec {
-       caddr_t iov_msg;        /* base of a component */
-       int     iov_len;        /* length of a component */
+       char    *iov_base;      /* base of a component */
+       size_t  iov_len;        /* length of a component */
 };
 };
+.TE
 .DE
 .DE
-The calls using an array of descriptors are:
+.LP
+The \fIiov_base\fP field should be treated as if its type were
+``void *'' as POSIX and other versions of the structure may use
+that type.
+Thus, pointer arithmetic should not use this value without a cast.
+.LP
+The calls using an array of \fIiovec\fP structures are:
 .DS
 .DS
+.Fd readv 3 "read gathered input
 cc = readv(fd, iov, iovlen);
 cc = readv(fd, iov, iovlen);
-result int cc; int fd; struct iovec *iov; int iovlen;
-
+result ssize_t cc; int fd; struct iovec *iov; int iovlen;
+.DE
+.DS
+.Fd writev 3 "write scattered output
 cc = writev(fd, iov, iovlen);
 cc = writev(fd, iov, iovlen);
-result int cc; int fd; struct iovec *iov; int iovlen;
+result ssize_t cc; int fd; struct iovec *iov; int iovlen;
 .DE
 Here \fIiovlen\fP is the count of elements in the \fIiov\fP array.
 .DE
 Here \fIiovlen\fP is the count of elements in the \fIiov\fP array.
-.NH 3
-Input/output control
-.PP
-Control operations on an object are performed by the \fIioctl\fP
+.Sh 3 "Input/output control
+.LP
+Control operations on an object are performed by the
+.Fn ioctl
 operation:
 .DS
 operation:
 .DS
+.Fd ioctl 3 "control device
 ioctl(fd, request, buffer);
 ioctl(fd, request, buffer);
-int fd, request; caddr_t buffer;
+int fd; u_long request; caddr_t buffer;
 .DE
 This operation causes the specified \fIrequest\fP to be performed
 on the object \fIfd\fP.  The \fIrequest\fP parameter specifies
 whether the argument buffer is to be read, written, read and written,
 .DE
 This operation causes the specified \fIrequest\fP to be performed
 on the object \fIfd\fP.  The \fIrequest\fP parameter specifies
 whether the argument buffer is to be read, written, read and written,
-or is not needed, and also the size of the buffer, as well as the
+or is not used, and also the size of the buffer, as well as the
 request.
 Different descriptor types and subtypes within descriptor types
 request.
 Different descriptor types and subtypes within descriptor types
-may use distinct \fIioctl\fP requests.  For example,
+may use distinct
+.Fn ioctl
+requests. For example,
 operations on terminals control flushing of input and output
 queues and setting of terminal parameters; operations on
 disks cause formatting operations to occur; operations on tapes
 control tape positioning.
 operations on terminals control flushing of input and output
 queues and setting of terminal parameters; operations on
 disks cause formatting operations to occur; operations on tapes
 control tape positioning.
-.PP
-The names for basic control operations are defined in \fI<sys/ioctl.h>\fP.
-.NH 3
-Non-blocking and asynchronous operations
+The names for basic control operations are defined by \fI<sys/ioctl.h>\fP,
+or more specifically by files it includes.
+.Sh 3 "Non-blocking and asynchronous operations
 .PP
 A process that wishes to do non-blocking operations on one of
 its descriptors sets the descriptor in non-blocking mode as
 .PP
 A process that wishes to do non-blocking operations on one of
 its descriptors sets the descriptor in non-blocking mode as
-described in section 1.5.4.  Thereafter the \fIread\fP call will
-return a specific EWOULDBLOCK error indication if there is no data to be
-\fIread\fP.  The process may
-\fIselect\fP the associated descriptor to determine when a read is
-possible.
+described in section
+.Xr 1.5.4 .
+Thereafter the
+.Fn read
+call will return a specific EWOULDBLOCK error indication
+if there is no data to be
+.Fn read .
+The process may
+.Fn select
+the associated descriptor to determine when a read is possible.
 .PP
 Output attempted when a descriptor can accept less than is requested
 will either accept some of the provided data, returning a shorter than normal
 length, or return an error indicating that the operation would block.
 .PP
 Output attempted when a descriptor can accept less than is requested
 will either accept some of the provided data, returning a shorter than normal
 length, or return an error indicating that the operation would block.
-More output can be performed as soon as a \fIselect\fP call indicates
-the object is writeable.
+More output can be performed as soon as a
+.Fn select
+call indicates
+the object is writable.
 .PP
 Operations other than data input or output
 may be performed on a descriptor in a non-blocking fashion.
 These operations will return with a characteristic error indicating
 that they are in progress
 if they cannot complete immediately.  The descriptor
 .PP
 Operations other than data input or output
 may be performed on a descriptor in a non-blocking fashion.
 These operations will return with a characteristic error indicating
 that they are in progress
 if they cannot complete immediately.  The descriptor
-may then be \fIselect\fPed for \fIwrite\fP to find out
-when the operation has been completed.  When \fIselect\fP indicates
-the descriptor is writeable, the operation has completed.
+may then be
+.Fn select 'ed
+for
+.Fn write
+to find out when the operation has been completed.
+When
+.Fn select
+indicates the descriptor is writable, the operation has completed.
 Depending on the nature of the descriptor and the operation,
 additional activity may be started or the new state may be tested.
 Depending on the nature of the descriptor and the operation,
 additional activity may be started or the new state may be tested.