JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
man pages section 9: DDI and DKI Properties and Data Structures     Oracle Solaris 11.1 Information Library
search filter icon
search icon

Document Information

Preface

Introduction

Data Structures for Drivers

aio_req(9S)

audio_engine_ops(9S)

blksize(9P)

buf(9S)

cb_ops(9S)

copyreq(9S)

copyresp(9S)

datab(9S)

dblk(9S)

ddi_device_acc_attr(9S)

ddi_dma_attr(9S)

ddi_dma_cookie(9S)

ddi_dmae_req(9S)

ddi_dma_lim(9S)

ddi_dma_lim_sparc(9S)

ddi_dma_lim_x86(9S)

ddi_dma_req(9S)

ddi_fm_error(9S)

ddi-forceattach(9P)

ddi_idevice_cookie(9S)

ddi-no-autodetach(9P)

ddi-no-modunload(9P)

device-blksize(9P)

device-nblocks(9P)

device-pblksize(9P)

devmap_callback_ctl(9S)

dev_ops(9S)

fmodsw(9S)

free_rtn(9S)

gld_mac_info(9S)

gld_stats(9S)

hook_nic_event(9S)

hook_pkt_event(9S)

hook_t(9S)

inquiry-device-type(9P)

inquiry-product-id(9P)

inquiry-revision-id(9P)

inquiry-serial-no(9P)

inquiry-vendor-id(9P)

iocblk(9S)

iovec(9S)

kstat(9S)

kstat_intr(9S)

kstat_io(9S)

kstat_named(9S)

linkblk(9S)

lso_basic_tcp_ipv4(9S)

mac_callbacks(9S)

mac_capab_lso(9S)

mac_capab_rings(9S)

mac_group_info(9S)

mac_register(9S)

mac_ring_info(9S)

mblk(9S)

modldrv(9S)

modlinkage(9S)

modlmisc(9S)

modlstrmod(9S)

module_info(9S)

msgb(9S)

Nblock(9P)

net_inject_t(9S)

net_instance_t(9S)

no-involuntary-power-cycles(9P)

pblksize(9P)

pm(9P)

pm-components(9P)

qband(9S)

qinit(9S)

queclass(9S)

queue(9S)

removable-media(9P)

scsi_address(9S)

scsi_arq_status(9S)

scsi_asc_key_strings(9S)

scsi_device(9S)

scsi_extended_sense(9S)

scsi_hba_tran(9S)

scsi_inquiry(9S)

scsi_pkt(9S)

scsi_status(9S)

size(9P)

sof_ops(9S)

streamtab(9S)

stroptions(9S)

tuple(9S)

uio(9S)

usb_bulk_request(9S)

usb_callback_flags(9S)

usb_cfg_descr(9S)

usb_client_dev_data(9S)

usb_completion_reason(9S)

usb_ctrl_request(9S)

usb_dev_descr(9S)

usb_dev_qlf_descr(9S)

usb_ep_descr(9S)

usb_if_descr(9S)

usb_intr_request(9S)

usb_isoc_request(9S)

usb_other_speed_cfg_descr(9S)

usb_request_attributes(9S)

usb_string_descr(9S)

buf

- block I/O data transfer structure

Synopsis

#include <sys/ddi.h>
#include <sys/sunddi.h>

Interface Level

Architecture independent level 1 (DDI/DKI)

Description

The buf structure is the basic data structure for block I/O transfers. Each block I/O 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 strategy(9E) routine. Do not depend on the size of the buf structure when writing a driver.

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.

Buffer headers are also used by the system for unbuffered or physical I/O for block drivers. In this case, the buffer describes a portion of user data space that is locked into memory.

Block drivers often chain block requests so that overall throughput for the device is maximized. The av_forw and the av_back members of the buf structure can serve as link pointers for chaining block requests.

Structure Members

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 */

The members of the buffer header available to test or set by a driver are as follows:

b_flags stores the buffer status and indicates to the driver whether to read or write to the device. The driver must never clear the b_flags member. If this is done, unpredictable results can occur including loss of disk sanity and the possible failure of other kernel processes.

All b_flags bit values not otherwise specified above are reserved by the kernel and may not be used.

Valid flags are as follows:

B_BUSY

Indicates the buffer is in use. The driver must not change this flag unless it allocated the buffer with getrbuf(9F) and no I/O operation is in progress.

B_DONE

Indicates the data transfer has completed. This flag is read-only.

B_ERROR

Indicates an I/O transfer error. It is set in conjunction with the b_error field. bioerror(9F) should be used in preference to setting the B_ERROR bit.

B_READ

Indicates that data is to be read from the peripheral device into main memory.

B_WRITE

Indicates that the data is to be transferred from main memory to the peripheral device. B_WRITE is a pseudo flag and cannot be directly tested; it is only detected as the NOT form of B_READ.

av_forw and av_back can be used by the driver to link the buffer into driver work lists.

b_bcount specifies the number of bytes to be transferred in both a paged and a non-paged I/O request.

b_un.b_addr must only be referenced after calling bp_mapin(9F). After bp_mapin(), b_un.b_addr is the virtual address of the buffer data associated with the I/O request. To efficiently check buffer data alignment, without calling bp_mapin(), a driver should use bioaligned(9F).

b_blkno 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 b_blkno or b_lblkno, but not both.

b_lblkno 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 b_lblkno or b_blkno, but not both.

b_resid should be set to the number of bytes not transferred because of an error.

b_bufsize contains the size of the allocated buffer.

b_iodone identifies a specific biodone routine to be called by the driver when the I/O is complete.

b_error can hold an error code that should be passed as a return code from the driver. b_error is set in conjunction with the B_ERROR bit set in the b_flags member. bioerror(9F) should be used in preference to setting the b_error field.

b_private is for the private use of the device driver.

b_edev contains the major and minor device numbers of the device accessed.

See Also

strategy(9E), aphysio(9F), bioaligned(9F), bioclone(9F), biodone(9F), bioerror(9F), bioinit(9F), bp_mapin(9F), clrbuf(9F), getrbuf(9F), physio(9F), iovec(9S), uio(9S)

Writing Device Drivers

Warnings

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 buf structure risk corrupting data in the kernel or on the device.