home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / sys / dev / dsort.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-03  |  788 b   |  44 lines

  1. /*
  2.  * generalized seek sort for disk
  3.  */
  4.  
  5. #include "../h/param.h"
  6. #include "../h/systm.h"
  7. #include "../h/buf.h"
  8.  
  9. #define    b_cylin    b_resid
  10.  
  11. disksort(dp, bp)
  12. register struct buf *dp, *bp;
  13. {
  14.     register struct buf *ap;
  15.     struct buf *tp;
  16.  
  17.     ap = dp->b_actf;
  18.     if(ap == NULL) {
  19.         dp->b_actf = bp;
  20.         dp->b_actl = bp;
  21.         bp->av_forw = NULL;
  22.         return;
  23.     }
  24.     tp = NULL;
  25.     for(; ap != NULL; ap = ap->av_forw) {
  26.         if ((bp->b_flags&B_READ) && (ap->b_flags&B_READ) == 0) {
  27.             if (tp == NULL)
  28.                 tp = ap;
  29.             break;
  30.         }
  31.         if ((bp->b_flags&B_READ) == 0 && (ap->b_flags&B_READ))
  32.             continue;
  33.         if(ap->b_cylin <= bp->b_cylin)
  34.             if(tp == NULL || ap->b_cylin >= tp->b_cylin)
  35.                 tp = ap;
  36.     }
  37.     if(tp == NULL)
  38.         tp = dp->b_actl;
  39.     bp->av_forw = tp->av_forw;
  40.     tp->av_forw = bp;
  41.     if(tp == dp->b_actl)
  42.         dp->b_actl = bp;
  43. }
  44.