buf Structure

Purpose

Describes buffering data transfers between a program and the peripheral device

Introduction to Kernel Buffers

For block devices, kernel buffers are used to buffer data transfers between a program and the peripheral device. These buffers are allocated in blocks of 4096 bytes. At any given time, each memory block is a member of one of two linked lists that the device driver and the kernel maintain:

List Description
Available buffer queue (avlist) A list of all buffers available for use. These buffers do not contain data waiting to be transferred to or from a device.
Busy buffer queue (blist) A list of all buffers that contain data waiting to be transferred to or from a device.

Each buffer has an associated buffer header called the buf structure pointing to it. Each buffer header has several parts:

The device driver maintains the av_forw and av_back pointers (for the available blocks), while the kernel maintains the b_forw and b_back pointers (for the busy blocks).

buf Structure Variables for Block I/O

The buf structure, which is defined in the /usr/include/sys/buf.h file, includes the following fields:

Item Description
b_flags Flag bits. The value of this field is constructed by logically ORing 0 or more of the following values:
B_WRITE
This operation is a write operation.
B_READ
This operation is a read data operation, rather than write.
B_DONE
I/O on the buffer has been done, so the buffer information is more current than other versions.
B_ERROR
A transfer error has occurred and the transaction has aborted.
B_BUSY
The block is not on the free list.
B_INFLIGHT
This I/O request has been sent to the physical device driver for processing.
B_AGE
The data is not likely to be reused soon, so prefer this buffer for reuse. This flag suggests that the buffer goes at the head of the free list rather than at the end.
B_ASYNC
Asynchronous I/O is being performed on this block. When I/O is done, release the block.
B_DELWRI
The contents of this buffer still need to be written out before the buffer can be reused, even though this block may be on the free list. This is used by the write subroutine when the system expects another write to the same block to occur soon.
B_NOHIDE
Indicates that the data page should not be hidden during direct memory access (DMA) transfer.
B_SETMOD
Allows an enhanced I/O file system to cause a page to be considered modified.
B_STALE
The data conflicts with the data on disk because of an I/O error.
B_ XREADONLY
Indicates a read-only page in the external pager buffer list.
B_MORE_DONE
When set, indicates to the receiver of this buf structure that more structures are queued in the IODONE level. This permits device drivers to handle all completed requests before processing any new requests.
B_SPLIT
When set, indicates that the transfer can begin anywhere within the data buffer.
b_forw The forward busy block pointer.
b_back The backward busy block pointer.
av_forw The forward pointer for a driver request queue.
av_back The backward pointer for a driver request queue.
b_iodone Anyone calling the strategy routine must set this field to point to their I/O done routine. This routine is called on the INTIODONE interrupt level when I/O is complete.
b_dev The major and minor device number.
b_bcount The byte count for the data transfer.
b_un.b_addr The memory address of the data buffer.
b_blkno The block number on the device.
b_resid Amount of data not transferred after error.
b_event Anchor for event list.
b_xmemd Cross-memory descriptor.