- register *p;
- register c;
-
- p = bp->b_un.b_words;
- c = BSIZE/sizeof(int);
- do
- *p++ = 0;
- while (--c);
- bp->b_resid = 0;
-}
-
-/*
- * swap I/O -
- *
- * If the flag indicates a dirty page push initiated
- * by the pageout daemon, we map the page into the i th
- * virtual page of process 2 (the daemon itself) where i is
- * the index of the swap header that has been allocated.
- * We simply initialize the header and queue the I/O but
- * do not wait for completion. When the I/O completes,
- * iodone() will link the header to a list of cleaned
- * pages to be processed by the pageout daemon.
- */
-swap(p, dblkno, addr, nbytes, rdflg, flag, dev, pfcent)
- struct proc *p;
- swblk_t dblkno;
- caddr_t addr;
- int flag, nbytes;
- dev_t dev;
- unsigned pfcent;
-{
- register struct buf *bp;
- register int c;
- int p2dp;
- register struct pte *dpte, *vpte;
-
- VOID spl6();
- while (bswlist.av_forw == NULL) {
- bswlist.b_flags |= B_WANTED;
- sleep((caddr_t)&bswlist, PSWP+1);
- }
- bp = bswlist.av_forw;
- bswlist.av_forw = bp->av_forw;
- VOID spl0();
-
- bp->b_flags = B_BUSY | B_PHYS | rdflg | flag;
- if ((bp->b_flags & (B_DIRTY|B_PGIN)) == 0)
- if (rdflg == B_READ)
- sum.v_pswpin += btoc(nbytes);
- else
- sum.v_pswpout += btoc(nbytes);
- bp->b_proc = p;
- if (flag & B_DIRTY) {
- p2dp = ((bp - swbuf) * CLSIZE) * KLMAX;
- dpte = dptopte(&proc[2], p2dp);
- vpte = vtopte(p, btop(addr));
- for (c = 0; c < nbytes; c += NBPG) {
- if (vpte->pg_pfnum == 0 || vpte->pg_fod)
- panic("swap bad pte");
- *dpte++ = *vpte++;
- }
- bp->b_un.b_addr = (caddr_t)ctob(p2dp);
- } else
- bp->b_un.b_addr = addr;
- while (nbytes > 0) {
- c = imin(ctob(120), nbytes);
- bp->b_bcount = c;
- bp->b_blkno = dblkno;
- bp->b_dev = dev;
- if (dev == swapdev)
- bp->b_blkno += swplo;
- (*bdevsw[major(dev)].d_strategy)(bp);
- if (flag & B_DIRTY) {
- if (c < nbytes)
- panic("big push");
- swsize[bp - swbuf] = nbytes;
- swpf[bp - swbuf] = pfcent;
- return;
+ register struct buf *ep;
+ struct buf *dp;
+ daddr_t start, last;
+ int s, error, allerrors = 0;
+
+ start = blkno;
+#ifdef SECSIZE
+ last = start + size - 1;
+#else SECSIZE
+ last = start + btodb(size) - 1;
+#endif SECSIZE
+ dp = BUFHASH(vp, blkno);
+loop:
+ for (ep = dp->b_forw; ep != dp; ep = ep->b_forw) {
+ if (ep->b_vp != vp || (ep->b_flags & B_INVAL))
+ continue;
+ /* look for overlap */
+ if (ep->b_bcount == 0 || ep->b_blkno > last ||
+#ifdef SECSIZE
+ ep->b_blkno + ep->b_bcount / ep->b_blksize <= start)
+#else SECSIZE
+ ep->b_blkno + btodb(ep->b_bcount) <= start)
+#endif SECSIZE
+ continue;
+ s = splbio();
+ if (ep->b_flags&B_BUSY) {
+ ep->b_flags |= B_WANTED;
+ sleep((caddr_t)ep, PRIBIO+1);
+ splx(s);
+ goto loop;