svcadm(8)을 검색하려면 섹션에서 8 을 선택하고, 맨 페이지 이름에 svcadm을 입력하고 검색을 누른다.
buf(9s)
Kernel & Driver Data Structures buf(9S)
NAME
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 strat‐
egy(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; /* error number field */
int b_xerror; /* extended 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 below 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 and b_xerror fields. bioerror(9F) and biox‐
error(9F) should be used in preference to setting the
B_ERROR bit. geterror(9F) and getxerror(9F) should be used
in preference to checking the B_ERROR bit and obtaining the
b_error and b_xerror field values.
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 mem‐
ory 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 asso‐
ciated with the I/O request. To efficiently check buffer data align‐
ment, 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 number 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 field. bioerror(9F) should be used in preference to
directly setting the B_ERROR bit and b_error field. geterrorr(9F)
should be used in preference to directly checking the B_ERROR bit or
obtaining the b_error field value. The b_error values chosen should be
constrained by the intro(2) system calls error numbers associated with
the buf operation: see read(2), write(2) for details.
b_xerror can hold an extended error code. b_xerror is set in conjunc‐
tion with b_error field and the B_ERROR bit in the b_flags field. biox‐
error(9F) should be used in preference to directly setting the B_ERROR
bit and the b_error and b_xerror fields. getxerror(9F) should be used
in preference to directly obtaining the b_xerror field value.
Valid b_xerror values are as follows:
B_XERR_UNDEFINED I/O execution succeeded, or I/O execution failed
but no extended error information was estab‐
lished via bioxerror(9F).
B_XERR_RECOVERED I/O execution succeeded, but driver retry and
recovery operations were necessary to complete
the I/O successfully.
B_XERR_MERR_READ I/O execution failed due to an error associated
with reading the device medium.
B_XERR_MERR_WRITE I/O execution failed due to an error associated
with writing the device medium.
B_XERR_MERR I/O execution failed due to an error associated
with the device medium.
B_XERR_DERR I/O execution failed due to a device error unre‐
lated to device medium.
B_XERR_PERR_UDERR I/O execution failed due to unexpected protocol
data.
B_XERR_PERR_USERR I/O execution failed due to unexpected protocol
status.
B_XERR_PERR I/O execution failed due to unexpected protocol
error.
B_XERR_TRAN_TIMEOUT I/O execution failed due to a transport timeout.
B_XERR_TRAN_DEVGONE I/O execution failed due to a transport not cur‐
rently being able to address the device.
B_XERR_TRAN I/O execution failed due to some type of trans‐
port issue.
B_XERR_LSRSUSPEND I/O execution failed due to device was live sus‐
pended.
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), bioxerror(9F), bioinit(9F), bp_mapin(9F), clrbuf(9F),
geterror(9F), getxerror(9F), getrbuf(9F), physio(9F), iovec(9S),
uio(9S)
Writing Device Drivers in Oracle Solaris 11.4
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.
Oracle Solaris 11.4 26 Jan 2018 buf(9S)