'\" te .\" Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. .\" Copyright 1989 AT&T .TH buf 9S "21 Dec 2010" "SunOS 5.11" "Data Structures for Drivers" .SH NAME buf \- block I/O data transfer structure .SH SYNOPSIS .LP .nf #include #include .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 .mk .na \fB\fBB_BUSY\fR\fR .ad .RS 11n .rt 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 .mk .na \fB\fBB_DONE\fR\fR .ad .RS 11n .rt Indicates the data transfer has completed. This flag is read-only. .RE .sp .ne 2 .mk .na \fB\fBB_ERROR\fR\fR .ad .RS 11n .rt 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 .mk .na \fB\fBB_READ\fR\fR .ad .RS 11n .rt Indicates that data is to be read from the peripheral device into main memory. .RE .sp .ne 2 .mk .na \fB\fBB_WRITE\fR\fR .ad .RS 11n .rt 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 must only be referenced after calling \fBbp_mapin\fR(9F). After \fBbp_mapin()\fR, \fBb_un.b_addr\fR is the virtual address of the buffer data associated with the I/O request. To efficiently check buffer data alignment, without calling \fBbp_mapin()\fR, a driver should use \fBbioaligned\fR(9F). .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), \fBbioaligned\fR(9F), \fBbioclone\fR(9F), \fBbiodone\fR(9F), \fBbioerror\fR(9F), \fBbioinit\fR(9F), \fBbp_mapin\fR(9F), \fBclrbuf\fR(9F), \fBgetrbuf\fR(9F), \fBphysio\fR(9F), \fBiovec\fR(9S), \fBuio\fR(9S) .sp .LP \fIWriting Device Drivers for Oracle Solaris 11.2\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.