1biodone(9F)              Kernel Functions for Drivers              biodone(9F)
2
3
4

NAME

6       biodone  -  release buffer after buffer I/O transfer and notify blocked
7       threads
8

SYNOPSIS

10       #include <sys/types.h>
11       #include <sys/buf.h>
12
13
14
15       void biodone(struct buf *bp);
16
17

INTERFACE LEVEL

19       Architecture independent level 1 (DDI/DKI).
20

PARAMETERS

22       bp    Pointer to a buf(9S) structure.
23
24

DESCRIPTION

26       The biodone() function notifies blocked processes waiting for  the  I/O
27       to  complete,  sets the B_DONE flag in the b_flags field of the buf(9S)
28       structure,  and  releases  the  buffer  if  the  I/O  is  asynchronous.
29       biodone() is called by either the driver interrupt or strategy(9E) rou‐
30       tines when a buffer I/O request is complete.
31
32
33       The biodone() function provides the capability  to  call  a  completion
34       routine  if bp describes a kernel buffer. The address of the routine is
35       specified in the b_iodone field of the buf(9S)  structure.  If  such  a
36       routine is specified, biodone() calls it and returns without performing
37       any other actions. Otherwise, it performs the steps above.
38

CONTEXT

40       The biodone() function can be called from user,  interrupt,  or  kernel
41       context.
42

EXAMPLES

44       Generally,  the  first  validation  test  performed by any block device
45       strategy(9E) routine is a check for an end-of-file (EOF) condition. The
46       strategy(9E)  routine  is  responsible for determining an EOF condition
47       when the device is accessed directly. If a read(2) request is made  for
48       one  block beyond the limits of the device (line 10), it will report an
49       EOF condition.  Otherwise, if the request is outside the limits of  the
50       device,  the  routine  will report an error condition.  In either case,
51       report the I/O operation as complete (line 27).
52
53          1   #define RAMDNBLK    1000 /* Number of blocks in RAM disk */
54          2   #define RAMDBSIZ    512  /* Number of bytes per block */
55          3   char ramdblks[RAMDNBLK][RAMDBSIZ]; /* Array containing RAM disk */
56          4
57          5   static int
58          6   ramdstrategy(struct buf *bp)
59          7   {
60          8      daddr_t blkno = bp->b_blkno;    /* get block number */
61          9
62         10      if ((blkno < 0) || (blkno >= RAMDNBLK)) {
63         11            /*
64         12             * If requested block is outside RAM disk
65         13             * limits, test for EOF which could result
66         14             * from a direct (physio) request.
67         15             */
68         16            if ((blkno == RAMDNBLK) && (bp->b_flags & B_READ)) {
69         17             /*
70         18              * If read is for block beyond RAM disk
71         19              * limits, mark EOF condition.
72         20              */
73         21              bp->b_resid = bp->b_bcount;  /* compute return value */
74         22
75         23           } else {    /* I/O attempt is beyond */
76         24              bp->b_error = ENXIO;    /*    limits of RAM disk */
77         25              bp->b_flags |= B_ERROR; /* return error */
78         26           }
79         27           biodone(bp);     /* mark I/O complete (B_DONE) */
80         28             /*
81         29              * Wake any processes awaiting this I/O
82         30              * or release buffer for asynchronous
83         31              * (B_ASYNC) request.
84         32              */
85         33           return (0);
86         34      }
87                    ...
88
89

SEE ALSO

91       read(2), strategy(9E), biowait(9F), ddi_add_intr(9F), delay(9F),  time‐
92       out(9F), untimeout(9F), buf(9S)
93
94
95       Writing Device Drivers
96

WARNINGS

98       After calling biodone(), bp is no longer available to be referred to by
99       the driver. If the driver makes  any  reference  to  bp  after  calling
100       biodone(), a panic may result.
101

NOTES

103       Drivers that use the b_iodone field of the buf(9S) structure to specify
104       a substitute completion routine  should  save  the  value  of  b_iodone
105       before  changing  it,  and  then  restore  the old value before calling
106       biodone() to release the buffer.
107
108
109
110SunOS 5.11                        16 Jan 2006                      biodone(9F)
Impressum