- geterror(bp);
-}
-
-/*
- * Release the buffer, marking it so that if it is grabbed
- * for another purpose it will be written out before being
- * given up (e.g. when writing a partial block where it is
- * assumed that another write for the same block will soon follow).
- * This can't be done for magtape, since writes must be done
- * in the same order as requested.
- */
-bdwrite(bp)
-register struct buf *bp;
-{
- register struct buf *dp;
-
- if ((bp->b_flags&B_DELWRI) == 0)
- u.u_vm.vm_oublk++; /* noone paid yet */
- dp = bdevsw[major(bp->b_dev)].d_tab;
- if(dp->b_flags & B_TAPE)
- bawrite(bp);
- else {
- bp->b_flags |= B_DELWRI | B_DONE;
- brelse(bp);
- }
-}
-
-/*
- * Release the buffer, start I/O on it, but don't wait for completion.
- */
-bawrite(bp)
-register struct buf *bp;
-{
-
- bp->b_flags |= B_ASYNC;
- bwrite(bp);
-}
-
-/*
- * release the buffer, with no I/O implied.
- */
-brelse(bp)
-register struct buf *bp;
-{
- register struct buf **backp;
- register s;
-
- if (bp->b_flags&B_WANTED)
- wakeup((caddr_t)bp);
- if (bfreelist.b_flags&B_WANTED) {
- bfreelist.b_flags &= ~B_WANTED;
- wakeup((caddr_t)&bfreelist);
- }
- if ((bp->b_flags&B_ERROR) && bp->b_dev != NODEV) {
- bunhash(bp);
- bp->b_dev = NODEV; /* no assoc. on error */
- }
- s = spl6();
- if(bp->b_flags & (B_AGE|B_ERROR)) {
- backp = &bfreelist.av_forw;
- (*backp)->av_back = bp;
- bp->av_forw = *backp;
- *backp = bp;
- bp->av_back = &bfreelist;
- } else {
- backp = &bfreelist.av_back;
- (*backp)->av_forw = bp;
- bp->av_back = *backp;
- *backp = bp;
- bp->av_forw = &bfreelist;
- }
- bp->b_flags &= ~(B_WANTED|B_BUSY|B_ASYNC|B_AGE);
- splx(s);
-}
-
-/*
- * See if the block is associated with some buffer
- * (mainly to avoid getting hung up on a wait in breada)
- */
-incore(dev, blkno)
-dev_t dev;
-daddr_t blkno;
-{
- register struct buf *bp;
- register int dblkno = fsbtodb(blkno);
-
- for (bp = &buf[bufhash[BUFHASH(blkno)]]; bp != &buf[-1];
- bp = &buf[bp->b_hlink])
- if (bp->b_blkno == dblkno && bp->b_dev == dev)
- return (1);
- return (0);
-}
-
-struct buf *
-baddr(dev, blkno)
-dev_t dev;
-daddr_t blkno;
-{
-
- if (incore(dev, blkno))
- return (bread(dev, blkno));
- return (0);
-}
-
-/*
- * Assign a buffer for the given block. If the appropriate
- * block is already associated, return it; otherwise search
- * for the oldest non-busy buffer and reassign it.
- */
-struct buf *
-getblk(dev, blkno)
-dev_t dev;
-daddr_t blkno;
-{
- register struct buf *bp, *dp, *ep;
- register int i, x;
- register int dblkno = fsbtodb(blkno);
-
- loop:
- (void) spl0();
- for (bp = &buf[bufhash[BUFHASH(blkno)]]; bp != &buf[-1];
- bp = &buf[bp->b_hlink]) {
- if (bp->b_blkno != dblkno || bp->b_dev != dev)
- continue;
- (void) spl6();
- if (bp->b_flags&B_BUSY) {