Annotation of researchv10no/netfs/libnetb/disp.c, revision 1.1

1.1     ! root        1: #include "netb.h"
        !             2: #include "nberrno.h"
        !             3: #include "rf.h"
        !             4: 
        !             5: /*
        !             6:  * netb functions
        !             7:  */
        !             8: 
        !             9: static int illcmd();
        !            10: int _rfput(), _rfupdate(), _rfread(), _rfwrite();
        !            11: int _rfnamei(), _rfstat(), _rfdir(), _rftrunc();
        !            12: 
        !            13: static (*functab[])() = {
        !            14:        illcmd,         /* (0) illegal */
        !            15:        _rfput,         /* (1) put */
        !            16:        illcmd,         /* (2) get */
        !            17:        _rfupdate,      /* (3) update */
        !            18:        _rfread,        /* (4) read */
        !            19:        _rfwrite,       /* (5) write */
        !            20:        _rfnamei,       /* (6) namei */
        !            21:        _rfstat,        /* (7) stat */
        !            22:        illcmd,         /* (8) ioctl */
        !            23:        _rftrunc,       /* (9) trunc */
        !            24:        _rfdir, /* (10) dirread */
        !            25: };
        !            26: 
        !            27: #define        MAXCMD  10
        !            28: 
        !            29: /*
        !            30:  * names only for debugging output
        !            31:  */
        !            32: static char *funcnames[] = {
        !            33:        "ill", "put", "get", "upd", "read",
        !            34:        "write", "namei", "stat", "ioctl", "trunc", "dir"
        !            35: };
        !            36: 
        !            37: static char *ninames[] = {
        !            38:        "reg", "del", "creat", "xcreat", "link", "mkdir", "rmdir"
        !            39: };
        !            40: #define        MAXNI   6
        !            41: 
        !            42: extern int cuid, cgid;
        !            43: 
        !            44: static slide();
        !            45: 
        !            46: _rfscan(fd, buf, size)
        !            47: int fd;
        !            48: char *buf;
        !            49: int size;
        !            50: {
        !            51:        register unsigned char *sp;
        !            52:        register int blen, mlen;
        !            53:        register int n, c;
        !            54: 
        !            55:        sp = (unsigned char *)buf;
        !            56:        blen = 0;
        !            57:        for (;;) {
        !            58:                if (blen < SNBSIZE) {
        !            59:                        n = _rfgread(fd, buf+blen, size-blen, SNBSIZE);
        !            60:                        if (n < SNBSIZE)
        !            61:                                break;
        !            62:                        blen += n;
        !            63:                }
        !            64:                c = frnetchar(sp, SNB_CMD);
        !            65:                if (c < 0 || c > MAXCMD)
        !            66:                        c = 0;
        !            67:                mlen = frnetlong(sp, SNB_LEN);
        !            68:                if (rfdebug)
        !            69:                        rflog("%ld: %s: cmd %d tag x%lx flag %d len %ld\n",
        !            70:                                frnetlong(sp, SNB_TRANNUM), funcnames[c],
        !            71:                                frnetchar(sp, SNB_CMD), frnetlong(sp, SNB_TAG),
        !            72:                                frnetchar(sp, SNB_FLAGS), mlen);
        !            73:                if (frnetchar(sp, SNB_VERSION) != NETB)
        !            74:                        rfpanic("ill version: %d\n", frnetchar(sp, SNB_VERSION));
        !            75:                if (mlen > size)
        !            76:                        rfpanic("msg too long: %d\n", mlen);
        !            77:                if (mlen > blen) {
        !            78:                        n = _rfgread(fd, buf+blen, size-blen, mlen-blen);
        !            79:                        if (n < mlen - blen)
        !            80:                                break;
        !            81:                        blen += n;
        !            82:                }
        !            83:                if (rfdebug
        !            84:                &&  c == NBNAMI && frnetchar(sp, SNB_FLAGS) <= MAXNI) {
        !            85:                        rflog("\tnamei: %s '%.*s'\n", ninames[frnetchar(sp, SNB_FLAGS)],
        !            86:                                mlen - SNMSIZE, sp + SNMSIZE);
        !            87:                }
        !            88:                cuid = frnetshort(sp, SNB_UID);
        !            89:                cgid = frnetshort(sp, SNB_GID);
        !            90:                rfuid = _rfsuid(cuid);
        !            91:                rfgid = _rfsgid(cgid);
        !            92:                (*functab[c])(fd, sp, mlen);
        !            93:                blen -= mlen;
        !            94:                if (blen != 0) {        /* leftover stuff in buffer; shouldn't happen */
        !            95:                        rflog("%d bytes excess read\n", blen);
        !            96:                        slide(buf+mlen, n, mlen);
        !            97:                }
        !            98:        }
        !            99:        if (n)
        !           100:                rfpanic("bad read: %d\n", n);
        !           101: }
        !           102: 
        !           103: static
        !           104: slide(buf, len, dist)
        !           105: char *buf;
        !           106: register int len;
        !           107: int dist;
        !           108: {
        !           109:        register char *fr, *to;
        !           110: 
        !           111:        fr = buf;
        !           112:        to = buf - dist;
        !           113:        while (--len >= 0)
        !           114:                *to++ = *fr++;
        !           115: }
        !           116: 
        !           117: static
        !           118: illcmd(fd, sp)
        !           119: int fd;
        !           120: unsigned char *sp;
        !           121: {
        !           122:        unsigned char rbuf[RNBSIZE];
        !           123: 
        !           124:        tonetshort(rbuf, RNB_ERRNO, NBEINVAL);
        !           125:        _rfresp(fd, sp, rbuf, RNBSIZE);
        !           126: }
        !           127: 
        !           128: /*
        !           129:  * send a response
        !           130:  */
        !           131: 
        !           132: _rfresp(fd, sp, rp, len)
        !           133: int fd;
        !           134: register unsigned char *sp, *rp;
        !           135: int len;
        !           136: {
        !           137: 
        !           138:        if (rfdebug)
        !           139:                rflog("\t_rfresp: %ld: errno %d flags %d len %ld\n",
        !           140:                        frnetlong(sp, SNB_TRANNUM), frnetshort(rp, RNB_ERRNO),
        !           141:                        frnetchar(rp, RNB_FLAGS), len);
        !           142:        tonetlong(rp, RNB_TRANNUM, frnetlong(sp, SNB_TRANNUM));
        !           143:        tonetlong(rp, RNB_LEN, len);
        !           144:        if (write(fd, (char *)rp, len) != len)
        !           145:                rfpanic("bad _rfresp write\n", 0);
        !           146: }

unix.superglobalmegacorp.com

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