xref: /illumos-gate/usr/src/man/man9s/buf.9s (revision 427723622c44f91d933c66b35e3de35f4ccd4669)
1c10c16deSRichard Lowe.\" Copyright (c) 2002 Sun Microsystems, Inc. All Rights Reserved.
2c10c16deSRichard Lowe.\" Copyright 1989 AT&T
3*42772362SJason King.\" The contents of this file are subject to the terms of the
4*42772362SJason King.\" Common Development and Distribution License (the "License").
5*42772362SJason King.\" You may not use this file except in compliance with the License.
6*42772362SJason King.\"
7*42772362SJason King.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8*42772362SJason King.\" or http://www.opensolaris.org/os/licensing.
9*42772362SJason King.\" See the License for the specific language governing permissions
10*42772362SJason King.\" and limitations under the License.
11*42772362SJason King.\"
12*42772362SJason King.\" When distributing Covered Code, include this CDDL HEADER in each
13*42772362SJason King.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14*42772362SJason King.\" If applicable, add the following below this CDDL HEADER, with the
15*42772362SJason King.\" fields enclosed by brackets "[]" replaced with your own identifying
16*42772362SJason King.\" information: Portions Copyright [yyyy] [name of copyright owner]
17*42772362SJason King.Dd July 9, 2018
18*42772362SJason King.Dt BUF 9S
19*42772362SJason King.Os
20*42772362SJason King.Sh NAME
21*42772362SJason King.Nm buf
22*42772362SJason King.Nd block I/O data transfer structure
23*42772362SJason King.Sh SYNOPSIS
24*42772362SJason King.In sys/ddi.h
25*42772362SJason King.In sys/sunddi.h
26*42772362SJason King.Sh INTERFACE LEVEL
27c10c16deSRichard LoweArchitecture independent level 1 (DDI/DKI)
28*42772362SJason King.Sh DESCRIPTION
29*42772362SJason KingThe
30*42772362SJason King.Vt buf
31*42772362SJason Kingstructure is the basic data structure for block
32*42772362SJason King.Sy I/O
33*42772362SJason Kingtransfers.
34*42772362SJason KingEach block
35*42772362SJason King.Sy I/O
36*42772362SJason Kingtransfer has an associated buffer header.
37*42772362SJason KingThe header contains all the buffer control and status information.
38*42772362SJason KingFor drivers, the buffer header pointer is the sole argument to a block driver
39*42772362SJason King.Xr strategy 9E
40*42772362SJason Kingroutine.
41*42772362SJason KingDo not depend on the size of the
42*42772362SJason King.Vt buf
43*42772362SJason Kingstructure when writing a driver.
44*42772362SJason King.Pp
45*42772362SJason KingA buffer header can be linked in multiple lists simultaneously.
46*42772362SJason KingBecause of
47c10c16deSRichard Lowethis, most of the members in the buffer header cannot be changed by the driver,
48c10c16deSRichard Loweeven when the buffer header is in one of the driver's work lists.
49*42772362SJason King.Pp
50*42772362SJason KingBuffer headers are also used by the system for unbuffered or physical
51*42772362SJason King.Sy I/O
52*42772362SJason Kingfor block drivers.
53*42772362SJason KingIn this case, the buffer describes a portion of user data
54c10c16deSRichard Lowespace that is locked into memory.
55*42772362SJason King.Pp
56c10c16deSRichard LoweBlock drivers often chain block requests so that overall throughput for the
57*42772362SJason Kingdevice is maximized.
58*42772362SJason KingThe
59*42772362SJason King.Fa av_forw
60*42772362SJason Kingand the
61*42772362SJason King.Fa av_back
62*42772362SJason Kingmembers of the
63*42772362SJason King.Vt buf
64*42772362SJason Kingstructure can serve as link pointers for chaining block requests.
65*42772362SJason King.Sh STRUCTURE MEMBERS
66*42772362SJason King.Bd -literal -offset 2n
67c10c16deSRichard Loweint           b_flags;           /* Buffer status */
68c10c16deSRichard Lowestruct buf    *av_forw;          /* Driver work list link */
69c10c16deSRichard Lowestruct buf    *av_back;          /* Driver work list link */
70c10c16deSRichard Lowesize_t        b_bcount;          /* # of bytes to transfer */
71c10c16deSRichard Loweunion {
72c10c16deSRichard Lowe    caddr_t  b_addr;            /* Buffer's virtual address */
73c10c16deSRichard Lowe} b_un;
74c10c16deSRichard Lowedaddr_t       b_blkno;           /* Block number on device */
75c10c16deSRichard Lowediskaddr_t    b_lblkno;          /* Expanded block number on dev.  */
76c10c16deSRichard Lowesize_t        b_resid;           /* # of bytes not xferred */
77c10c16deSRichard Lowesize_t        b_bufsize;         /* size of alloc. buffer */
78c10c16deSRichard Loweint           (*b_iodone)(struct buf *); /* function called */
79c10c16deSRichard Lowe                                         /* by biodone */
80c10c16deSRichard Loweint           b_error;           /* expanded error field */
81c10c16deSRichard Lowevoid          *b_private;        /* "opaque" driver private area */
82c10c16deSRichard Lowedev_t         b_edev;            /* expanded dev field */
83*42772362SJason King.Ed
84*42772362SJason King.Pp
85c10c16deSRichard LoweThe members of the buffer header available to test or set by a driver are as
86c10c16deSRichard Lowefollows:
87*42772362SJason King.Pp
88*42772362SJason King.Fa b_flags
89*42772362SJason Kingstores the buffer status and indicates to the driver whether to
90*42772362SJason Kingread or write to the device.
91*42772362SJason KingThe driver must never clear the
92*42772362SJason King.Fa b_flags
93*42772362SJason Kingmember.
94*42772362SJason KingIf this is done, unpredictable results can occur including loss of disk
95c10c16deSRichard Lowesanity and the possible failure of other kernel processes.
96*42772362SJason King.Pp
97*42772362SJason KingAll
98*42772362SJason King.Fa b_flags
99*42772362SJason Kingbit values not otherwise specified above are reserved by the
100c10c16deSRichard Lowekernel and may not be used.
101*42772362SJason King.Pp
102c10c16deSRichard LoweValid flags are as follows:
103*42772362SJason King.Bl -tag -width "B_PAGEIO"
104*42772362SJason King.It Dv B_BUSY
105*42772362SJason KingIndicates the buffer is in use.
106*42772362SJason KingThe driver must not change this flag unless it allocated the buffer with
107*42772362SJason King.Xr getrbuf 9F
108*42772362SJason Kingand no
109*42772362SJason King.Sy I/O
110*42772362SJason Kingoperation is in progress.
111*42772362SJason King.It Dv B_DONE
112*42772362SJason KingIndicates the data transfer has completed.
113*42772362SJason KingThis flag is read-only.
114*42772362SJason King.It Dv B_ERROR
115*42772362SJason KingIndicates an
116*42772362SJason King.Sy I/O
117*42772362SJason Kingtransfer error.
118*42772362SJason KingIt is set in conjunction with the
119*42772362SJason King.Fa b_error
120*42772362SJason Kingfield.
121*42772362SJason King.Xr bioerror 9F
122*42772362SJason Kingshould be used in preference to setting the
123*42772362SJason King.Dv B_ERROR
124*42772362SJason Kingbit.
125*42772362SJason King.It Dv B_PAGEIO
126*42772362SJason KingIndicates the buffer is being used in a paged
127*42772362SJason King.Sy I/O
128*42772362SJason Kingrequest.
129*42772362SJason KingSee the description of the
130*42772362SJason King.Fa b_un.b_addr
131*42772362SJason Kingfield for more information.
132*42772362SJason KingThis flag is read-only.
133*42772362SJason King.It Dv B_PHYS
134*42772362SJason Kingindicates the buffer header is being used for physical (direct)
135*42772362SJason King.Sy I/O
136*42772362SJason Kingto a user data area.
137*42772362SJason KingSee the description of the
138*42772362SJason King.Fa b_un.b_addr
139*42772362SJason Kingfield for more information.
140*42772362SJason KingThis flag is read-only.
141*42772362SJason King.It Dv B_READ
142c10c16deSRichard LoweIndicates that data is to be read from the peripheral device into main memory.
143*42772362SJason King.It Dv B_WRITE
144c10c16deSRichard LoweIndicates that the data is to be transferred from main memory to the peripheral
145*42772362SJason Kingdevice.
146*42772362SJason King.Dv B_WRITE
147*42772362SJason Kingis a pseudo flag and cannot be directly tested; it is
148*42772362SJason Kingonly detected as the NOT form of
149*42772362SJason King.Dv B_READ .
150*42772362SJason King.El
151*42772362SJason King.Pp
152*42772362SJason King.Fa av_forw
153*42772362SJason Kingand
154*42772362SJason King.Fa av_back
155*42772362SJason Kingcan be used by the driver to link the buffer into driver work lists.
156*42772362SJason King.Pp
157*42772362SJason King.Fa b_bcount
158*42772362SJason Kingspecifies the number of bytes to be transferred in both a paged and a non-paged
159*42772362SJason King.Sy I/O
160*42772362SJason Kingrequest.
161*42772362SJason King.Pp
162*42772362SJason King.Fa b_un.b_addr
163*42772362SJason Kingis the virtual address of the
164*42772362SJason King.Sy I/O
165*42772362SJason Kingrequest, unless
166*42772362SJason King.Dv B_PAGEIO
167*42772362SJason Kingis set.
168*42772362SJason KingThe address is a kernel virtual address, unless
169*42772362SJason King.Dv B_PHYS
170*42772362SJason Kingis set, in which case it is a user virtual address.
171*42772362SJason KingIf
172*42772362SJason King.Dv B_PAGEIO
173*42772362SJason Kingis set,
174*42772362SJason King.Fa b_un.b_addr
175*42772362SJason Kingcontains kernel private data.
176*42772362SJason KingNote that either one of
177*42772362SJason King.Dv B_PHYS
178*42772362SJason Kingand
179*42772362SJason King.Dv B_PAGEIO ,
180*42772362SJason Kingor neither, can be set, but
181c10c16deSRichard Lowenot both.
182*42772362SJason King.Pp
183*42772362SJason King.Fa b_blkno
184*42772362SJason Kingidentifies which logical block on the device (the device is
185*42772362SJason Kingdefined by the device number) is to be accessed.
186*42772362SJason KingThe driver might have to
187c10c16deSRichard Loweconvert this logical block number to a physical location such as a cylinder,
188*42772362SJason Kingtrack, and sector of a disk.
189*42772362SJason KingThis is a 32-bit value.
190*42772362SJason KingThe driver should use
191*42772362SJason King.Fa b_blkno
192*42772362SJason Kingor
193*42772362SJason King.Fa b_lblkno ,
194*42772362SJason Kingbut not both.
195*42772362SJason King.Pp
196*42772362SJason King.Fa b_lblkno
197*42772362SJason Kingidentifies which logical block on the device (the device is
198*42772362SJason Kingdefined by the device number) is to be accessed.
199*42772362SJason KingThe driver might have to
200c10c16deSRichard Loweconvert this logical block number to a physical location such as a cylinder,
201*42772362SJason Kingtrack, and sector of a disk.
202*42772362SJason KingThis is a 64-bit value.
203*42772362SJason KingThe driver should use
204*42772362SJason King.Fa b_lblkno
205*42772362SJason Kingor
206*42772362SJason King.Fa b_blkno ,
207*42772362SJason Kingbut not both.
208*42772362SJason King.Pp
209*42772362SJason King.Fa b_resid
210*42772362SJason Kingshould be set to the number of bytes not transferred because of an error.
211*42772362SJason King.Pp
212*42772362SJason King.Fa b_bufsize
213*42772362SJason Kingcontains the size of the allocated buffer.
214*42772362SJason King.Pp
215*42772362SJason King.Fa b_iodone
216*42772362SJason Kingidentifies a specific
217*42772362SJason King.Xr biodone 9F
218*42772362SJason Kingroutine to be called by the driver when the
219*42772362SJason King.Sy I/O
220*42772362SJason Kingis complete.
221*42772362SJason King.Pp
222*42772362SJason King.Fa b_error
223*42772362SJason Kingcan hold an error code that should be passed as a return code
224*42772362SJason Kingfrom the driver.
225*42772362SJason King.Fa b_error
226*42772362SJason Kingis set in conjunction with the
227*42772362SJason King.Dv B_ERROR
228*42772362SJason Kingbit
229*42772362SJason Kingset in the
230*42772362SJason King.Fa b_flags
231*42772362SJason Kingmember.
232*42772362SJason King.Xr bioerror 9F
233*42772362SJason Kingshould be used in
234*42772362SJason Kingpreference to setting the
235*42772362SJason King.Fa b_error
236*42772362SJason Kingfield.
237*42772362SJason King.Pp
238*42772362SJason King.Fa b_private
239*42772362SJason Kingis for the private use of the device driver.
240*42772362SJason King.Pp
241*42772362SJason King.Fa b_edev
242*42772362SJason Kingcontains the major and minor device numbers of the device
243c10c16deSRichard Loweaccessed.
244*42772362SJason King.Sh SEE ALSO
245*42772362SJason King.Xr strategy 9E ,
246*42772362SJason King.Xr aphysio 9F ,
247*42772362SJason King.Xr bioclone 9F ,
248*42772362SJason King.Xr biodone 9F ,
249*42772362SJason King.Xr bioerror 9F ,
250*42772362SJason King.Xr bioinit 9F ,
251*42772362SJason King.Xr clrbuf 9F ,
252*42772362SJason King.Xr getrbuf 9F ,
253*42772362SJason King.Xr physio 9F ,
254*42772362SJason King.Xr iovec 9S ,
255*42772362SJason King.Xr uio 9S
256*42772362SJason King.Rs
257*42772362SJason King.%T Writing Device Drivers
258*42772362SJason King.Re
259*42772362SJason King.Sh WARNINGS
260*42772362SJason KingBuffers are a shared resource within the kernel.
261*42772362SJason KingDrivers should read or write only the members listed in this section.
262*42772362SJason KingDrivers that attempt to use undocumented members of the
263*42772362SJason King.Fa buf
264*42772362SJason Kingstructure risk corrupting data in the kernel or on the device.
265