Annotation of researchv8dc/cmd/qed/blkio.c, revision 1.1

1.1     ! root        1: /*% cc -c -O %
        !             2:  */
        !             3: #include "vars.h"
        !             4: #define BLKSIZE        512
        !             5: #ifdef BIGTMP
        !             6: #define        MAXBLOCKS       4095
        !             7: #else
        !             8: #define        MAXBLOCKS       255
        !             9: #endif
        !            10: #define        BLMASK          MAXBLOCKS
        !            11: char   ibuff[512];
        !            12: int    iblock = -1;
        !            13: int    oblock = 0;
        !            14: char   obuff[512];
        !            15: int    ooff;           /* offset of next byte in obuff */
        !            16: initio()
        !            17: {
        !            18:        lock++;
        !            19:        iblock = -1;
        !            20:        oblock = 0;
        !            21:        ooff = 0;
        !            22:        unlock();
        !            23: }
        !            24: char *getline(tl, lbuf)
        !            25:        int tl;
        !            26:        char *lbuf;
        !            27: {
        !            28:        register char *bp, *lp;
        !            29:        register int nl;
        !            30:        extern int read();
        !            31: 
        !            32:        lp = lbuf;
        !            33:        nl = -((tl<<1) & 0774);
        !            34:        tl = (tl>>8) & BLMASK;
        !            35:        do {
        !            36:                if (nl<=0) {
        !            37:                        if (tl==oblock)
        !            38:                                bp = obuff;
        !            39:                        else {
        !            40:                                bp = ibuff;
        !            41:                                if (tl!=iblock) {
        !            42:                                        iblock = -1;    /* signal protection */
        !            43:                                        blkio(tl, bp, read);
        !            44:                                        iblock = tl;
        !            45:                                }
        !            46:                        }
        !            47:                        tl++;
        !            48:                        bp -= nl;
        !            49:                        nl += BLKSIZE;
        !            50:                }
        !            51:                nl--;
        !            52:        } while (*lp++ = *bp++);
        !            53:        return(lbuf);
        !            54: }
        !            55: int putline()
        !            56: {
        !            57:        register char *op, *lp;
        !            58:        register int r;
        !            59:        extern int write();
        !            60: 
        !            61:        modified();
        !            62:        lp = linebuf;
        !            63:        r = (oblock<<8) + (ooff>>1);    /* ooff may be 512! */
        !            64:        op = obuff + ooff;
        !            65:        lock++;
        !            66:        do {
        !            67:                if (op >= obuff+BLKSIZE) {
        !            68:                        /* delay updating oblock until after blkio succeeds */
        !            69:                        blkio(oblock, op=obuff, write);
        !            70:                        oblock++;
        !            71:                        ooff = 0;
        !            72:                }
        !            73:                if((*op = *lp++) == '\n') {
        !            74:                        *op++ = '\0';
        !            75:                        linebp = lp;
        !            76:                        break;
        !            77:                }
        !            78:        } while (*op++);
        !            79:        ooff = (((op-obuff)+3)&~3);
        !            80:        unlock();
        !            81:        return (r);
        !            82: }
        !            83: blkio(b, buf, iofcn)
        !            84:        char *buf;
        !            85:        int (*iofcn)();
        !            86: {
        !            87:        if (b>=MAXBLOCKS
        !            88:        || (lseek(tfile, ((long) b) * 512L, 0)<0L)
        !            89:        || (*iofcn)(tfile, buf, 512) != 512) {
        !            90:                error('T');
        !            91:        }
        !            92: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.