-/* ufs_bio.c 6.1 83/07/29 */
+/*
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ * @(#)ufs_bio.c 7.1 (Berkeley) 6/5/86
+ */
#include "../machine/pte.h"
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/buf.h"
-#include "../h/conf.h"
-#include "../h/proc.h"
-#include "../h/seg.h"
-#include "../h/vm.h"
-#include "../h/trace.h"
+#include "param.h"
+#include "systm.h"
+#include "dir.h"
+#include "user.h"
+#include "buf.h"
+#include "conf.h"
+#include "proc.h"
+#include "seg.h"
+#include "vm.h"
+#include "trace.h"
/*
* Read in (if necessary) the block and return a buffer pointer.
panic("bread: size 0");
bp = getblk(dev, blkno, size);
if (bp->b_flags&B_DONE) {
- trace(TR_BREADHIT, dev, blkno);
- return(bp);
+ trace(TR_BREADHIT, pack(dev, size), blkno);
+ return (bp);
}
bp->b_flags |= B_READ;
if (bp->b_bcount > bp->b_bufsize)
panic("bread");
(*bdevsw[major(dev)].d_strategy)(bp);
- trace(TR_BREADMISS, dev, blkno);
+ trace(TR_BREADMISS, pack(dev, size), blkno);
u.u_ru.ru_inblock++; /* pay for read */
biowait(bp);
- return(bp);
+ return (bp);
}
/*
if (bp->b_bcount > bp->b_bufsize)
panic("breada");
(*bdevsw[major(dev)].d_strategy)(bp);
- trace(TR_BREADMISS, dev, blkno);
+ trace(TR_BREADMISS, pack(dev, size), blkno);
u.u_ru.ru_inblock++; /* pay for read */
} else
- trace(TR_BREADHIT, dev, blkno);
+ trace(TR_BREADHIT, pack(dev, size), blkno);
}
/*
rabp = getblk(dev, rablkno, rabsize);
if (rabp->b_flags & B_DONE) {
brelse(rabp);
- trace(TR_BREADHITRA, dev, blkno);
+ trace(TR_BREADHITRA, pack(dev, rabsize), blkno);
} else {
rabp->b_flags |= B_READ|B_ASYNC;
if (rabp->b_bcount > rabp->b_bufsize)
panic("breadrabp");
(*bdevsw[major(dev)].d_strategy)(rabp);
- trace(TR_BREADMISSRA, dev, rablock);
+ trace(TR_BREADMISSRA, pack(dev, rabsize), rablock);
u.u_ru.ru_inblock++; /* pay in advance */
}
}
bp->b_flags &= ~(B_READ | B_DONE | B_ERROR | B_DELWRI);
if ((flag&B_DELWRI) == 0)
u.u_ru.ru_oublock++; /* noone paid yet */
- trace(TR_BWRITE, bp->b_dev, bp->b_blkno);
+ trace(TR_BWRITE, pack(bp->b_dev, bp->b_bcount), bp->b_blkno);
if (bp->b_bcount > bp->b_bufsize)
panic("bwrite");
(*bdevsw[major(bp->b_dev)].d_strategy)(bp);
register struct buf *flist;
register s;
+ trace(TR_BRELSE, pack(bp->b_dev, bp->b_bufsize), bp->b_blkno);
/*
* If someone's waiting for the buffer, or
* is waiting for a buffer wake 'em up.
/*
* Stick the buffer back on a free list.
*/
- s = spl6();
+ s = splbio();
if (bp->b_bufsize <= 0) {
/* block has no buffer ... put at front of unused buffer list */
flist = &bfreelist[BQ_EMPTY];
register struct buf *bp, *dp;
int s;
- if ((unsigned)blkno >= 1 << (sizeof(int)*NBBY-PGSHIFT)) /* XXX */
- blkno = 1 << ((sizeof(int)*NBBY-PGSHIFT) + 1);
+ if (size > MAXBSIZE)
+ panic("getblk: size too big");
+ /*
+ * To prevent overflow of 32-bit ints when converting block
+ * numbers to byte offsets, blknos > 2^32 / DEV_BSIZE are set
+ * to the maximum number that can be converted to a byte offset
+ * without overflow. This is historic code; what bug it fixed,
+ * or whether it is still a reasonable thing to do is open to
+ * dispute. mkm 9/85
+ */
+ if ((unsigned)blkno >= 1 << (sizeof(int)*NBBY-DEV_BSHIFT))
+ blkno = 1 << ((sizeof(int)*NBBY-DEV_BSHIFT) + 1);
/*
* Search the cache for the block. If we hit, but
* the buffer is in use for i/o, then we wait until
if (bp->b_blkno != blkno || bp->b_dev != dev ||
bp->b_flags&B_INVAL)
continue;
- s = spl6();
+ s = splbio();
if (bp->b_flags&B_BUSY) {
bp->b_flags |= B_WANTED;
sleep((caddr_t)bp, PRIBIO+1);
}
splx(s);
notavail(bp);
- if (brealloc(bp, size) == 0)
+ if (bp->b_bcount != size && brealloc(bp, size) == 0)
goto loop;
bp->b_flags |= B_CACHE;
- return(bp);
+ return (bp);
}
if (major(dev) >= nblkdev)
panic("blkdev");
bp->b_error = 0;
if (brealloc(bp, size) == 0)
goto loop;
- return(bp);
+ return (bp);
}
/*
{
register struct buf *bp, *flist;
+ if (size > MAXBSIZE)
+ panic("geteblk: size too big");
loop:
bp = getnewbuf();
bp->b_flags |= B_INVAL;
bp->b_error = 0;
if (brealloc(bp, size) == 0)
goto loop;
- return(bp);
+ return (bp);
}
/*
if (bp->b_dev == NODEV)
return (allocbuf(bp, size));
+ trace(TR_BREALLOC, pack(bp->b_dev, size), bp->b_blkno);
/*
* Search cache for any buffers that overlap the one that we
* are trying to allocate. Overlapping buffers must be marked
if (ep->b_bcount == 0 || ep->b_blkno > last ||
ep->b_blkno + btodb(ep->b_bcount) <= start)
continue;
- s = spl6();
+ s = splbio();
if (ep->b_flags&B_BUSY) {
ep->b_flags |= B_WANTED;
sleep((caddr_t)ep, PRIBIO+1);
int s;
loop:
- s = spl6();
+ s = splbio();
for (dp = &bfreelist[BQ_AGE]; dp > bfreelist; dp--)
if (dp->av_forw != dp)
break;
bwrite(bp);
goto loop;
}
- trace(TR_BRELSE, bp->b_dev, bp->b_blkno);
+ trace(TR_BRELSE, pack(bp->b_dev, bp->b_bufsize), bp->b_blkno);
bp->b_flags = B_BUSY;
return (bp);
}
{
int s;
- s = spl6();
+ s = splbio();
while ((bp->b_flags&B_DONE)==0)
sleep((caddr_t)bp, PRIBIO);
splx(s);
if (ep->b_bcount == 0 || ep->b_blkno > last ||
ep->b_blkno + btodb(ep->b_bcount) <= start)
continue;
- s = spl6();
+ s = splbio();
if (ep->b_flags&B_BUSY) {
ep->b_flags |= B_WANTED;
sleep((caddr_t)ep, PRIBIO+1);
int s;
loop:
- s = spl6();
+ s = splbio();
for (flist = bfreelist; flist < &bfreelist[BQ_EMPTY]; flist++)
for (bp = flist->av_forw; bp != flist; bp = bp->av_forw) {
if ((bp->b_flags & B_DELWRI) == 0)
/*
* Pick up the device's error number and pass it to the user;
- * if there is an error but the number is 0 set a generalized
- * code. Actually the latter is always true because devices
- * don't yet return specific errors.
+ * if there is an error but the number is 0 set a generalized code.
*/
geterror(bp)
register struct buf *bp;