2 .\" Copyright (c) 2002 Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
6 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH BUF 9S "Sep 19, 2002"
9 buf \- block I/O data transfer structure
14 #include <sys/sunddi.h>
20 Architecture independent level 1 (DDI/DKI)
24 The \fBbuf\fR structure is the basic data structure for block \fBI/O\fR
25 transfers. Each block \fBI/O\fR transfer has an associated buffer header. The
26 header contains all the buffer control and status information. For drivers, the
27 buffer header pointer is the sole argument to a block driver \fBstrategy\fR(9E)
28 routine. Do not depend on the size of the \fBbuf\fR structure when writing a
32 A buffer header can be linked in multiple lists simultaneously. Because of
33 this, most of the members in the buffer header cannot be changed by the driver,
34 even when the buffer header is in one of the driver's work lists.
37 Buffer headers are also used by the system for unbuffered or physical \fBI/O\fR
38 for block drivers. In this case, the buffer describes a portion of user data
39 space that is locked into memory.
42 Block drivers often chain block requests so that overall throughput for the
43 device is maximized. The \fBav_forw\fR and the \fBav_back\fR members of the
44 \fBbuf\fR structure can serve as link pointers for chaining block requests.
49 int b_flags; /* Buffer status */
50 struct buf *av_forw; /* Driver work list link */
51 struct buf *av_back; /* Driver work list link */
52 size_t b_bcount; /* # of bytes to transfer */
54 caddr_t b_addr; /* Buffer's virtual address */
56 daddr_t b_blkno; /* Block number on device */
57 diskaddr_t b_lblkno; /* Expanded block number on dev. */
58 size_t b_resid; /* # of bytes not xferred */
59 size_t b_bufsize; /* size of alloc. buffer */
60 int (*b_iodone)(struct buf *); /* function called */
62 int b_error; /* expanded error field */
63 void *b_private; /* "opaque" driver private area */
64 dev_t b_edev; /* expanded dev field */
71 The members of the buffer header available to test or set by a driver are as
75 \fBb_flags\fR stores the buffer status and indicates to the driver whether to
76 read or write to the device. The driver must never clear the \fBb_flags\fR
77 member. If this is done, unpredictable results can occur including loss of disk
78 sanity and the possible failure of other kernel processes.
81 All \fBb_flags\fR bit values not otherwise specified above are reserved by the
82 kernel and may not be used.
85 Valid flags are as follows:
92 Indicates the buffer is in use. The driver must not change this flag unless it
93 allocated the buffer with \fBgetrbuf\fR(9F) and no \fBI/O\fR operation is in
103 Indicates the data transfer has completed. This flag is read-only.
112 Indicates an \fBI/O\fR transfer error. It is set in conjunction with the
113 \fBb_error\fR field. \fBbioerror\fR(9F) should be used in preference to setting
114 the \fBB_ERROR\fR bit.
120 \fB\fBB_PAGEIO\fR \fR
123 Indicates the buffer is being used in a paged \fBI/O\fR request. See the
124 description of the \fBb_un.b_addr\fR field for more information. This flag is
134 indicates the buffer header is being used for physical (direct) \fBI/O\fR to a
135 user data area. See the description of the \fBb_un.b_addr\fR field for more
136 information. This flag is read-only.
145 Indicates that data is to be read from the peripheral device into main memory.
154 Indicates that the data is to be transferred from main memory to the peripheral
155 device. \fBB_WRITE\fR is a pseudo flag and cannot be directly tested; it is
156 only detected as the NOT form of \fBB_READ\fR.
161 \fBav_forw\fR and \fBav_back\fR can be used by the driver to link the buffer
162 into driver work lists.
165 \fBb_bcount\fR specifies the number of bytes to be transferred in both a paged
166 and a non-paged \fBI/O\fR request.
169 \fBb_un.b_addr\fR is the virtual address of the \fBI/O\fR request, unless
170 \fBB_PAGEIO\fR is set. The address is a kernel virtual address, unless
171 \fBB_PHYS\fR is set, in which case it is a user virtual address. If
172 \fBB_PAGEIO\fR is set, \fBb_un.b_addr\fR contains kernel private data. Note
173 that either one of \fBB_PHYS\fR and \fBB_PAGEIO\fR, or neither, can be set, but
177 \fBb_blkno\fR identifies which logical block on the device (the device is
178 defined by the device number) is to be accessed. The driver might have to
179 convert this logical block number to a physical location such as a cylinder,
180 track, and sector of a disk. This is a 32-bit value. The driver should use
181 \fBb_blkno\fR or \fBb_lblkno\fR, but not both.
184 \fBb_lblkno\fR identifies which logical block on the device (the device is
185 defined by the device number) is to be accessed. The driver might have to
186 convert this logical block number to a physical location such as a cylinder,
187 track, and sector of a disk. This is a 64-bit value. The driver should use
188 \fBb_lblkno\fR or \fBb_blkno\fR, but not both.
191 \fBb_resid\fR should be set to the number of bytes not transferred because of
195 \fBb_bufsize\fR contains the size of the allocated buffer.
198 \fBb_iodone\fR identifies a specific \fBbiodone\fR routine to be called by the
199 driver when the \fBI/O\fR is complete.
202 \fBb_error\fR can hold an error code that should be passed as a return code
203 from the driver. \fBb_error\fR is set in conjunction with the \fBB_ERROR\fR bit
204 set in the \fBb_flags\fR member. \fBbioerror\fR(9F) should be used in
205 preference to setting the \fBb_error\fR field.
208 \fBb_private\fR is for the private use of the device driver.
211 \fBb_edev\fR contains the major and minor device numbers of the device
216 \fBstrategy\fR(9E), \fBaphysio\fR(9F), \fBbioclone\fR(9F), \fBbiodone\fR(9F),
217 \fBbioerror\fR(9F), \fBbioinit\fR(9F), \fBclrbuf\fR(9F), \fBgetrbuf\fR(9F),
218 \fBphysio\fR(9F), \fBiovec\fR(9S), \fBuio\fR(9S)
221 \fIWriting Device Drivers\fR
225 Buffers are a shared resource within the kernel. Drivers should read or write
226 only the members listed in this section. Drivers that attempt to use
227 undocumented members of the \fBbuf\fR structure risk corrupting data in the
228 kernel or on the device.