12062 Convert buf(9S) to mandoc

   1 '\" te
   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"
   8 .SH NAME
   9 buf \- block I/O data transfer structure
  10 .SH SYNOPSIS
  11 .LP
  12 .nf
  13 #include <sys/ddi.h>
  14 #include <sys/sunddi.h>
  15 .fi
  16 
  17 .SH INTERFACE LEVEL
  18 .sp
  19 .LP








  20 Architecture independent level 1 (DDI/DKI)
  21 .SH DESCRIPTION
  22 .sp
  23 .LP
  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
  29 driver.
  30 .sp
  31 .LP
  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.
  35 .sp
  36 .LP
  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.
  40 .sp
  41 .LP
  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.
  45 .SH STRUCTURE MEMBERS
  46 .sp
  47 .in +2
  48 .nf




  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 */
  53 union {
  54      caddr_t  b_addr;            /* Buffer's virtual address */
  55 } b_un;
  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 */
  61                                                 /* by biodone */
  62 int           b_error;           /* expanded error field */
  63 void          *b_private;        /* "opaque" driver private area */
  64 dev_t         b_edev;            /* expanded dev field */
  65 \fI\fR
  66 .fi
  67 .in -2
  68 
  69 .sp
  70 .LP
  71 The members of the buffer header available to test or set by a driver are as
  72 follows:
  73 .sp
  74 .LP
  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.
  79 .sp
  80 .LP
  81 All \fBb_flags\fR bit values not otherwise specified above are reserved by the

  82 kernel and may not be used.
  83 .sp
  84 .LP
  85 Valid flags are as follows:
  86 .sp
  87 .ne 2
  88 .na
  89 \fB\fBB_BUSY\fR \fR
  90 .ad
  91 .RS 13n
  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
  94 progress.
  95 .RE
  96 
  97 .sp
  98 .ne 2
  99 .na
 100 \fB\fBB_DONE\fR \fR
 101 .ad
 102 .RS 13n
 103 Indicates the data transfer has completed. This flag is read-only.
 104 .RE
 105 
 106 .sp
 107 .ne 2
 108 .na
 109 \fB\fBB_ERROR\fR \fR
 110 .ad
 111 .RS 13n
 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.
 115 .RE
 116 
 117 .sp
 118 .ne 2
 119 .na
 120 \fB\fBB_PAGEIO\fR \fR
 121 .ad
 122 .RS 13n
 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
 125 read-only.
 126 .RE
 127 
 128 .sp
 129 .ne 2
 130 .na
 131 \fB\fBB_PHYS\fR \fR
 132 .ad
 133 .RS 13n
 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.
 137 .RE
 138 
 139 .sp
 140 .ne 2
 141 .na
 142 \fB\fBB_READ\fR \fR
 143 .ad
 144 .RS 13n
 145 Indicates that data is to be read from the peripheral device into main memory.
 146 .RE
 147 
 148 .sp
 149 .ne 2
 150 .na
 151 \fB\fBB_WRITE\fR \fR
 152 .ad
 153 .RS 13n
 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.
 157 .RE
 158 
 159 .sp
 160 .LP
 161 \fBav_forw\fR and \fBav_back\fR can be used by the driver to link the buffer
 162 into driver work lists.
 163 .sp
 164 .LP
 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.
 167 .sp
 168 .LP
 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

















 174 not both.
 175 .sp
 176 .LP
 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.
 182 .sp
 183 .LP
 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.
 189 .sp
 190 .LP
 191 \fBb_resid\fR should be set to the number of bytes not transferred because of
 192 an error.
 193 .sp
 194 .LP
 195 \fBb_bufsize\fR contains the size of the allocated buffer.
 196 .sp
 197 .LP
 198 \fBb_iodone\fR identifies a specific \fBbiodone\fR routine to be called by the
 199 driver when the \fBI/O\fR is complete.
 200 .sp
 201 .LP
 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.
 206 .sp
 207 .LP
 208 \fBb_private\fR is for the private use of the device driver.
 209 .sp
 210 .LP
 211 \fBb_edev\fR contains the major and minor device numbers of the device

















 212 accessed.
 213 .SH SEE ALSO
 214 .sp
 215 .LP
 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)
 219 .sp
 220 .LP
 221 \fIWriting Device Drivers\fR
 222 .SH WARNINGS
 223 .sp
 224 .LP
 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.





--- EOF ---