Describes buffering data transfers between a program and the peripheral device
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).
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_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. |