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