Annotation of researchv10no/cmd/worm/nio.c, revision 1.1

1.1     ! root        1: #include       <libc.h>
        !             2: #include       "worm.h"
        !             3: 
        !             4: Read(s, buf, n)
        !             5:        register Superblock *s;
        !             6:        char *buf;
        !             7:        long n;
        !             8: {
        !             9:        register k;
        !            10:        int len;
        !            11: 
        !            12:        n *= s->blocksize;
        !            13:        if(n != (int)n){
        !            14:                fprint(2, "bad arg to Read n=%ld\n", n);
        !            15:                abort();
        !            16:        }
        !            17:        len = BIGBLOCK;
        !            18:        while(n){
        !            19:                if(n < len) len = n;
        !            20: fprint(2, "reading fd=%d len=%d\n", s->fd, len);
        !            21:                if((k = read(s->fd, buf, len)) != len){
        !            22: fprint(2, "k=%d\n", k);
        !            23:                        if(k && (errno != ENXIO)){
        !            24:                                perror("Read");
        !            25:                                exit(1);
        !            26:                        }
        !            27:                        return(1);
        !            28:                }
        !            29:                n -= len;
        !            30:                buf += len;
        !            31:        }
        !            32:        return(0);
        !            33: }
        !            34: 
        !            35: Write(s, buf, n)
        !            36:        register Superblock *s;
        !            37:        char *buf;
        !            38:        long n;
        !            39: {
        !            40:        register k;
        !            41:        int len;
        !            42:        char msg[256];
        !            43: 
        !            44:        n *= s->blocksize;
        !            45:        if(n != (int)n){
        !            46:                fprint(2, "bad arg to Write n=%d\n", n);
        !            47:                abort();
        !            48:        }
        !            49:        len = BIGBLOCK;
        !            50:        while(n){
        !            51:                if(n < len) len = n;
        !            52:                if((k = write(s->fd, buf, len)) != len){
        !            53:                        sprint(msg, "Write %d blks (%dB)", n/s->blocksize, n);
        !            54:                        perror(msg);
        !            55:                        return(1);
        !            56:                }
        !            57:                n -= len;
        !            58:                buf += len;
        !            59:        }
        !            60:        return(0);
        !            61: }
        !            62: 
        !            63: Seek(s, blk)
        !            64:        register Superblock *s;
        !            65:        long blk;
        !            66: {
        !            67:        bigseek(s->fd, blk, s->blocksize, 0);
        !            68: }
        !            69: 
        !            70: bigseek(fd, a, b, ptr)
        !            71: {
        !            72: #define        SEEK64  /**/
        !            73: #ifdef SEEK64
        !            74: #include       <sys/param.h>
        !            75:        llong_t off;
        !            76:        extern llong_t Llmul(), ltoL();
        !            77: 
        !            78:        off = Llmul(ltoL(a), b);
        !            79:        llseek(fd, off, ptr);
        !            80: fprint(2, "seek(fd=%d, %dx%d\n", fd, a, b);
        !            81: #else
        !            82:        lseek(fd, a*(long)b, ptr);
        !            83: #endif
        !            84: }

unix.superglobalmegacorp.com

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