|
|
1.1 ! root 1: ! 2: #define NULL 0 ! 3: #define B_READ 1 ! 4: ! 5: struct buf { ! 6: struct buf *b_actf, *b_actl; ! 7: int b_cylin; ! 8: struct buf *av_forw; ! 9: int b_flags; ! 10: } dtab; ! 11: ! 12: main(argc, argv) ! 13: char **argv; ! 14: { ! 15: int i; char *cp; ! 16: ! 17: argc--, argv++; ! 18: while (argc > 0) { ! 19: cp = *argv++; ! 20: i = *cp++ == 'r'; ! 21: doit(atoi(cp), i); ! 22: printem(); ! 23: --argc; ! 24: } ! 25: } ! 26: ! 27: struct buf fum[100]; ! 28: int next; ! 29: ! 30: doit(cyl, rw) ! 31: { ! 32: struct buf *bp = &fum[next++]; ! 33: ! 34: bp->b_cylin = cyl; ! 35: bp->b_flags = rw; ! 36: disksort(&dtab, bp); ! 37: } ! 38: ! 39: printem() ! 40: { ! 41: register struct buf *bp = dtab.b_actf; ! 42: while (bp != &dtab && bp) { ! 43: printf("w\0r" + 2 * bp->b_flags); ! 44: printf("%d ", bp->b_cylin); ! 45: bp = bp->av_forw; ! 46: } ! 47: printf("\n"); ! 48: } ! 49: ! 50: disksort(dp, bp) ! 51: register struct buf *dp, *bp; ! 52: { ! 53: register struct buf *ap; ! 54: struct buf *tp; ! 55: ! 56: ap = dp->b_actf; ! 57: if(ap == NULL) { ! 58: dp->b_actf = bp; ! 59: dp->b_actl = bp; ! 60: bp->av_forw = NULL; ! 61: return; ! 62: } ! 63: tp = NULL; ! 64: if (ap->b_cylin > bp->b_cylin) { ! 65: while (ap->av_forw && ap->av_forw->b_cylin > ap->b_cylin) ! 66: ap = ap->av_forw; ! 67: } ! 68: while (ap->av_forw && ap->av_forw->b_cylin <= bp->b_cylin) ! 69: ap = ap->av_forw; ! 70: bp->av_forw = ap->av_forw; ! 71: ap->av_forw = bp; ! 72: if(ap == dp->b_actl) ! 73: dp->b_actl = bp; ! 74: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.