Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

buf(9s) [osf1 man page]

buf(9s) 																   buf(9s)

NAME
buf - General: Describes arbitrary I/O SYNOPSIS
---------------------------------- Member Name Data Type ---------------------------------- b_flags int b_forw struct buf * b_back struct buf * av_forw struct buf * av_back struct buf * b_bcount int b_error short b_dev dev_t b_un.b_addr caddr_t b_lblkno daddr_t b_blkno daddr_t b_resid int b_iodone void (*b_iodone) () b_proc struct proc * ---------------------------------- MEMBERS
Specifies binary status flags. These flags indicate how a request is to be handled and the current status of the request. The following flags are applicable to kernel modules that are device drivers: B_READ, B_DONE, B_ERROR, B_BUSY, and B_PHYS. See the DESCRIPTION section for more information on these flags. Specifies a hash chain. Only the entity (driver, buffer cache) that owns the buf structure can use or reference this member. A driver receiving a buf structure from the buffer cache through the strategy routine must not use this member. Specifies a hash chain. Only the entity (driver, buffer cache) that owns the buf structure can use or reference this member. A driver receiving a buf structure from the buffer cache through the strategy routine must not use this member. Specifies the position on the free list if the b_flags member is not set to B_BUSY. Specifies the position on the free list if the b_flags member is not set to B_BUSY. Specifies the size of the requested transfer (in bytes). Specifies that an error occurred on this data transfer. This member is set to an error code if the b_flags member bit was set. Specifies the special device to which the transfer is directed. Specifies the address at which to pull or push the data. Specifies the logical block number. Specifies the block number on the partition of a disk or on the file system. Specifies (in bytes) the data not transferred because of some error. Specifies the routine called by iodone. The device driver calls iodone at the completion of an I/O operation. Specifies a pointer to the proc structure that represents the process performing the I/O. DESCRIPTION
The buf data structure describes arbitrary I/O, but is usually associated with block I/O and physio. A systemwide pool of buf data struc- tures exists for block I/O; however, many kernel modules that are device drivers also include locally defined buf data structures. Kernel modules can use the following flags with the b_flags member: This flag is set if the operation is read and cleared if the operation is write. This flag is cleared when a request is passed to a driver strategy routine. The writer must call iodone to mark a buffer as com- pleted. This flag specifies that an error occurred on this data transfer. Kernel modules set this flag if an error occurs. This flag indicates that the buffer is in use. This flag indicates that the associated data is in user address space. NOTES
The operating system does not define a B_CALL flag. The iodone routine checks the b_iodone member to determine if you specified a comple- tion routine. If so, iodone clears b_iodone and then calls the specified completion routine. If you want to reuse this buf data structure, you must reset the b_iodone member to a completion routine. In fact, it is good programming practice to reset all of the referenced members of a buf data structure that you plan to reuse. FILES
buf(9s)

Check Out this Related Man Page

biodone(9F)						   Kernel Functions for Drivers 					       biodone(9F)

NAME
biodone - release buffer after buffer I/O transfer and notify blocked threads SYNOPSIS
#include <sys/types.h> #include <sys/buf.h> void biodone(struct buf *bp); INTERFACE LEVEL
Architecture independent level 1 (DDI/DKI). PARAMETERS
bp Pointer to a buf(9S) structure. DESCRIPTION
biodone() notifies blocked processes waiting for the I/O to complete, sets the B_DONE flag in the b_flags field of the buf(9S) structure, and releases the buffer if the I/O is asynchronous. biodone() is called by either the driver interrupt or strategy(9E) routines when a buf- fer I/O request is complete. biodone() provides the capability to call a completion routine if bp describes a kernel buffer. The address of the routine is specified in the b_iodone field of the buf(9S) structure. If such a routine is specified, biodone() calls it and returns without performing any other actions. Otherwise, it performs the steps above. CONTEXT
biodone() can be called from user or interrupt context. EXAMPLES
Generally, the first validation test performed by any block device strategy(9E) routine is a check for an end-of-file (EOF) condition. The strategy(9E) routine is responsible for determining an EOF condition when the device is accessed directly. If a read(2) request is made for one block beyond the limits of the device (line 10), it will report an EOF condition. Otherwise, if the request is outside the limits of the device, the routine will report an error condition. In either case, report the I/O operation as complete (line 27). 1 #define RAMDNBLK 1000 /* Number of blocks in RAM disk */ 2 #define RAMDBSIZ 512 /* Number of bytes per block */ 3 char ramdblks[RAMDNBLK][RAMDBSIZ]; /* Array containing RAM disk */ 4 5 static int 6 ramdstrategy(struct buf *bp) 7 { 8 daddr_t blkno = bp->b_blkno; /* get block number */ 9 10 if ((blkno < 0) || (blkno >= RAMDNBLK)) { 11 /* 12 * If requested block is outside RAM disk 13 * limits, test for EOF which could result 14 * from a direct (physio) request. 15 */ 16 if ((blkno == RAMDNBLK) && (bp->b_flags & B_READ)) { 17 /* 18 * If read is for block beyond RAM disk 19 * limits, mark EOF condition. 20 */ 21 bp->b_resid = bp->b_bcount; /* compute return value */ 22 23 } else { /* I/O attempt is beyond */ 24 bp->b_error = ENXIO; /* limits of RAM disk */ 25 bp->b_flags |= B_ERROR; /* return error */ 26 } 27 biodone(bp); /* mark I/O complete (B_DONE) */ 28 /* 29 * Wake any processes awaiting this I/O 30 * or release buffer for asynchronous 31 * (B_ASYNC) request. 32 */ 33 return(0); 34 } ... SEE ALSO
read(2), strategy(9E), biowait(9F), ddi_add_intr(9F), delay(9F), timeout(9F), untimeout(9F), buf(9S) Writing Device Drivers WARNINGS
After calling biodone(), bp is no longer available to be referred to by the driver. If the driver makes any reference to bp after calling biodone(), a panic may result. NOTES
Drivers that use the b_iodone field of the buf(9S) structure to specify a substitute completion routine should save the value of b_iodone before changing it, and then restore the old value before calling biodone() to release the buffer. SunOS 5.10 23 Apr 1996 biodone(9F)
Man Page