1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
'\" te
.\" Copyright (c) 2002 Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 1989 AT&T
.\" 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.
.\" 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.
.\" 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]
.TH BUF 9S "Sep 19, 2002"
.SH NAME
buf \- block I/O data transfer structure
.SH SYNOPSIS
.LP
.nf
#include <sys/ddi.h>
#include <sys/sunddi.h>
.fi
.SH INTERFACE LEVEL
.sp
.LP
Architecture independent level 1 (DDI/DKI)
.SH DESCRIPTION
.sp
.LP
The \fBbuf\fR structure is the basic data structure for block \fBI/O\fR
transfers. Each block \fBI/O\fR transfer has an associated buffer header. The
header contains all the buffer control and status information. For drivers, the
buffer header pointer is the sole argument to a block driver \fBstrategy\fR(9E)
routine. Do not depend on the size of the \fBbuf\fR structure when writing a
driver.
.sp
.LP
A buffer header can be linked in multiple lists simultaneously. Because of
this, most of the members in the buffer header cannot be changed by the driver,
even when the buffer header is in one of the driver's work lists.
.sp
.LP
Buffer headers are also used by the system for unbuffered or physical \fBI/O\fR
for block drivers. In this case, the buffer describes a portion of user data
space that is locked into memory.
.sp
.LP
Block drivers often chain block requests so that overall throughput for the
device is maximized. The \fBav_forw\fR and the \fBav_back\fR members of the
\fBbuf\fR structure can serve as link pointers for chaining block requests.
.SH STRUCTURE MEMBERS
.sp
.in +2
.nf
int b_flags; /* Buffer status */
struct buf *av_forw; /* Driver work list link */
struct buf *av_back; /* Driver work list link */
size_t b_bcount; /* # of bytes to transfer */
union {
caddr_t b_addr; /* Buffer's virtual address */
} b_un;
daddr_t b_blkno; /* Block number on device */
diskaddr_t b_lblkno; /* Expanded block number on dev. */
size_t b_resid; /* # of bytes not xferred */
size_t b_bufsize; /* size of alloc. buffer */
int (*b_iodone)(struct buf *); /* function called */
/* by biodone */
int b_error; /* expanded error field */
void *b_private; /* "opaque" driver private area */
dev_t b_edev; /* expanded dev field */
\fI\fR
.fi
.in -2
.sp
.LP
The members of the buffer header available to test or set by a driver are as
follows:
.sp
.LP
\fBb_flags\fR stores the buffer status and indicates to the driver whether to
read or write to the device. The driver must never clear the \fBb_flags\fR
member. If this is done, unpredictable results can occur including loss of disk
sanity and the possible failure of other kernel processes.
.sp
.LP
All \fBb_flags\fR bit values not otherwise specified above are reserved by the
kernel and may not be used.
.sp
.LP
Valid flags are as follows:
.sp
.ne 2
.na
\fB\fBB_BUSY\fR \fR
.ad
.RS 13n
Indicates the buffer is in use. The driver must not change this flag unless it
allocated the buffer with \fBgetrbuf\fR(9F) and no \fBI/O\fR operation is in
progress.
.RE
.sp
.ne 2
.na
\fB\fBB_DONE\fR \fR
.ad
.RS 13n
Indicates the data transfer has completed. This flag is read-only.
.RE
.sp
.ne 2
.na
\fB\fBB_ERROR\fR \fR
.ad
.RS 13n
Indicates an \fBI/O\fR transfer error. It is set in conjunction with the
\fBb_error\fR field. \fBbioerror\fR(9F) should be used in preference to setting
the \fBB_ERROR\fR bit.
.RE
.sp
.ne 2
.na
\fB\fBB_PAGEIO\fR \fR
.ad
.RS 13n
Indicates the buffer is being used in a paged \fBI/O\fR request. See the
description of the \fBb_un.b_addr\fR field for more information. This flag is
read-only.
.RE
.sp
.ne 2
.na
\fB\fBB_PHYS\fR \fR
.ad
.RS 13n
indicates the buffer header is being used for physical (direct) \fBI/O\fR to a
user data area. See the description of the \fBb_un.b_addr\fR field for more
information. This flag is read-only.
.RE
.sp
.ne 2
.na
\fB\fBB_READ\fR \fR
.ad
.RS 13n
Indicates that data is to be read from the peripheral device into main memory.
.RE
.sp
.ne 2
.na
\fB\fBB_WRITE\fR \fR
.ad
.RS 13n
Indicates that the data is to be transferred from main memory to the peripheral
device. \fBB_WRITE\fR is a pseudo flag and cannot be directly tested; it is
only detected as the NOT form of \fBB_READ\fR.
.RE
.sp
.LP
\fBav_forw\fR and \fBav_back\fR can be used by the driver to link the buffer
into driver work lists.
.sp
.LP
\fBb_bcount\fR specifies the number of bytes to be transferred in both a paged
and a non-paged \fBI/O\fR request.
.sp
.LP
\fBb_un.b_addr\fR is the virtual address of the \fBI/O\fR request, unless
\fBB_PAGEIO\fR is set. The address is a kernel virtual address, unless
\fBB_PHYS\fR is set, in which case it is a user virtual address. If
\fBB_PAGEIO\fR is set, \fBb_un.b_addr\fR contains kernel private data. Note
that either one of \fBB_PHYS\fR and \fBB_PAGEIO\fR, or neither, can be set, but
not both.
.sp
.LP
\fBb_blkno\fR identifies which logical block on the device (the device is
defined by the device number) is to be accessed. The driver might have to
convert this logical block number to a physical location such as a cylinder,
track, and sector of a disk. This is a 32-bit value. The driver should use
\fBb_blkno\fR or \fBb_lblkno\fR, but not both.
.sp
.LP
\fBb_lblkno\fR identifies which logical block on the device (the device is
defined by the device number) is to be accessed. The driver might have to
convert this logical block number to a physical location such as a cylinder,
track, and sector of a disk. This is a 64-bit value. The driver should use
\fBb_lblkno\fR or \fBb_blkno\fR, but not both.
.sp
.LP
\fBb_resid\fR should be set to the number of bytes not transferred because of
an error.
.sp
.LP
\fBb_bufsize\fR contains the size of the allocated buffer.
.sp
.LP
\fBb_iodone\fR identifies a specific \fBbiodone\fR routine to be called by the
driver when the \fBI/O\fR is complete.
.sp
.LP
\fBb_error\fR can hold an error code that should be passed as a return code
from the driver. \fBb_error\fR is set in conjunction with the \fBB_ERROR\fR bit
set in the \fBb_flags\fR member. \fBbioerror\fR(9F) should be used in
preference to setting the \fBb_error\fR field.
.sp
.LP
\fBb_private\fR is for the private use of the device driver.
.sp
.LP
\fBb_edev\fR contains the major and minor device numbers of the device
accessed.
.SH SEE ALSO
.sp
.LP
\fBstrategy\fR(9E), \fBaphysio\fR(9F), \fBbioclone\fR(9F), \fBbiodone\fR(9F),
\fBbioerror\fR(9F), \fBbioinit\fR(9F), \fBclrbuf\fR(9F), \fBgetrbuf\fR(9F),
\fBphysio\fR(9F), \fBiovec\fR(9S), \fBuio\fR(9S)
.sp
.LP
\fIWriting Device Drivers\fR
.SH WARNINGS
.sp
.LP
Buffers are a shared resource within the kernel. Drivers should read or write
only the members listed in this section. Drivers that attempt to use
undocumented members of the \fBbuf\fR structure risk corrupting data in the
kernel or on the device.
|