Print this page
12062 Convert buf(9S) to mandoc

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