xref: /freebsd/share/man/man9/physio.9 (revision ce834215a70ff69e7e222827437116eee2f9ac6f)
1.\"	$NetBSD: physio.9,v 1.2 1996/11/11 00:05:12 lukem Exp $
2.\"
3.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Paul Kranenburg.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
29.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd June 15, 1996
38.Dt PHYSIO 9
39.Os FreeBSD
40.Sh NAME
41.Nm physio
42.Nd initiate I/O on raw devices
43.Sh SYNOPSIS
44.Fd #include <sys/param.h>
45.Fd #include <sys/buf.h>
46.Ft int
47.Fo physio
48.Fa "void (*strategy)(struct buf *)"
49.Fa "struct buf *bp"
50.Fa "dev_t dev"
51.Fa "int flags"
52.Fa "u_int (*minphys)(struct buf *)"
53.Fa "struct uio *uio"
54.Fc
55.Sh DESCRIPTION
56The
57.Fn physio
58is a helper function typically called from character device read and write
59routines to start I/O on a user process buffer. It calls back on the
60provided
61.Fa strategy
62routine one or more times to complete the transfer described by
63.Fa uio .
64The maximum amount of data to transfer with each call to
65.Fa strategy
66is determined by the
67.Fa minphys
68routine. Since
69.Fa uio
70normally describes user space addresses,
71.Fn physio
72needs to lock the process into memory.  This is done by setting the
73.Dv P_PHYSIO
74flag on the process.
75.Fn physio
76always awaits the completion of the entire requested transfer before
77returning, unless an error condition is detected earlier. In all cases,
78the buffer passed in
79.Fa bp
80is locked (marked as
81.Dq busy )
82for the duration of the entire transfer.
83.Pp
84A break-down of the arguments follows:
85.Bl -tag -width indent
86.It Fa strategy
87The device strategy routine to call for each chunk of data to initiate
88device I/O.
89.It Fa bp
90The buffer to use with the strategy routine. The buffer flags will have
91.Dv B_BUSY ,
92and
93.Dv B_PHYS
94set when passed to the strategy routine. If
95.Dv NULL ,
96a buffer is allocated from a system pool.
97.It Fa dev
98The device number identifying the device to interact with.
99.It Fa flags
100Direction of transfer; the only valid settings are
101.Dv B_READ
102or
103.Dv B_WRITE .
104.It Fa minphys
105A device specific routine called to determine the maximum transfer size
106that the device's strategy routine can handle.
107.It Fa uio
108The description of the entire transfer as requested by the user process.
109Currently, the results of passing a
110.Fa uio
111structure with the
112.Sq uio_segflg
113set to anything other than
114.Dv UIO_USERSPACE ,
115are undefined.
116.El
117.Pp
118.Sh RETURN VALUES
119If successful
120.Fn physio
121returns 0.
122.Er EFAULT
123is returned if the address range described by
124.Fa uio
125is not accessible by the requesting process.
126.Fn physio
127will return any error resulting from calls to the device strategy routine,
128by examining the
129.Dv B_ERROR
130buffer flag and the
131.Va b_error
132field. Note that the actual transfer size may be less than requested by
133.Fa uio
134if the device signals an
135.Dq end of file
136condition.
137.Sh SEE ALSO
138.Xr read 2 ,
139.Xr write 2
140