12.07.2015 Views

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

DISK (9) <strong>NetBSD</strong> <strong>Kernel</strong> Developer’s <strong>Manual</strong> DISK (9)voidfoostart(sc)struct foo_softc ∗sc;{[ . . . ]}/∗ Get buffer from drive’s transfer queue. ∗/[ . . . ]/∗ Build command to send to drive. ∗/[ . . . ]/∗ Tell the disk framework we’re going busy. ∗/disk_busy(&sc->sc_dk);/∗ Send command to the drive. ∗/[ . . . ]When disk_busy() is called, a timestamp is taken if the disk’s busy counter moves from 0 to 1, indicatingthe disk has gone from an idle to non-idle state. Note that disk_busy() must be called at splbio(). Atthe end of a transaction, the disk_unbusy() routine should be called. This routine performs some consistencychecks, such as ensuring that the calls to disk_busy() and disk_unbusy() are balanced. Thisroutine also performs the actual metrics calculation. Atimestamp is taken, and the difference from the timestamptaken in disk_busy() is added to the disk’s total running time. The disk’s timestamp is thenupdated in case there is more than one pending transfer on the disk. Abyte count is also added to the disk’srunning total, and if greater than zero, the number of transfers the disk has performed is incremented. Thethird argument read specifies the direction of I/O; if non-zero it means reading from the disk, otherwise itmeans writing to the disk.voidfoodone(xfer)struct foo_xfer ∗xfer;{struct foo_softc = (struct foo_softc ∗)xfer->xf_softc;struct buf ∗bp = xfer->xf_buf;long nbytes;[ . . . ]/∗∗ Get number of bytes transfered. If there is no buf∗ associated with the xfer, we are being called at the∗ end of a non-I/O command.∗/if (bp == NULL)nbytes = 0;elsenbytes = bp->b_bcount - bp->b_resid;[ . . . ]/∗ Notify the disk framework that we’ve completed the transfer. ∗/disk_unbusy(&sc->sc_dk, nbytes,<strong>NetBSD</strong> 3.0 May 3, 2008 4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!