Annotation of researchv9/netb/src/main.c, revision 1.1

1.1     ! root        1: /* Network file system B.
        !             2:  * Setup message contains protocol type, max message size, and dev, at least.
        !             3:  * Maybe add some permissions stuff.
        !             4:  * The second message contains login names and uids from the client.
        !             5:  * The third message contains group names and gids from the client.
        !             6:  * Each message is acked by a single byte (1, 2, resp 3).
        !             7:  *
        !             8:  * All headers are translated from the client .../sys/h/netb.h into a global
        !             9:  * host structure that contains the union of all the fields.  Each type of
        !            10:  * response is converted back to the client's format as part of sending the
        !            11:  * response.  server() is in input.c.
        !            12:  */
        !            13: 
        !            14: #include "share.h"
        !            15: int cfd, dbgfd, debugflag;
        !            16: int dtime;
        !            17: 
        !            18: main(argc, argv)
        !            19: char **argv;
        !            20: {      int i, n;
        !            21:        char buf[32];
        !            22:        cfd = 0;        /* we get invoked by rexec */
        !            23:        dbgfd = open("/dev/null", 1);
        !            24: /*     dbgfd = creat("/tmp/zarf", 0644); /* /tmp/zarf is creamed on reboot */
        !            25:        n = xread(cfd, buf, 16);
        !            26:        if(n != 16)
        !            27:                fatal("client: read on setup %d bytes %d, |%s|\n", n, errno, buf);
        !            28:        n = buf[0];
        !            29:        hisdev = buf[1] << 8;   /* that's his dev */
        !            30:        switch(buf[2]) {
        !            31:        default:
        !            32:                fatal("unk protocol %c (0%0)\n", buf[2], buf[2]);
        !            33:        case 't': case 'd':
        !            34:                proto = buf[2];
        !            35:                break;
        !            36:        }
        !            37:        debugflag = buf[3];
        !            38:        switch(buf[4]) {
        !            39:        default:
        !            40:                fatal("unk client type %c (0%0)\n", buf[4], buf[4]);
        !            41:        case 'v': case 's':
        !            42:                clienttype = buf[4];
        !            43:                break;
        !            44:        }
        !            45:        buf[0] = 1;
        !            46:        write(cfd, buf, 1);
        !            47:        for(i = 0; i < FILES; i++)
        !            48:                files[i].fd = -1;
        !            49:        error("server %d\n", getpid());
        !            50:        error("CSOURCE=%s\n", getenv("CSOURCE"));
        !            51:        server(n * 1024);
        !            52: }
        !            53: 
        !            54: /* read a fixed size off cfd */
        !            55: xread(fd, buf, cnt)
        !            56: unsigned char *buf;
        !            57: {      unsigned char *p = buf;
        !            58:        int i, n;
        !            59:        n = 0;
        !            60: loop:
        !            61:        i = read(fd, p, cnt - n);
        !            62:        if(i <= 0)
        !            63:                fatal("xread(%d) n %d i %d\n", cnt, n, i);
        !            64:        
        !            65:        p += i;
        !            66:        n += i;
        !            67:        if(n >= cnt)
        !            68:                return(cnt);
        !            69:        goto loop;
        !            70: }
        !            71: 
        !            72: char msgbuf[1024];
        !            73: /* VARARGS1 */
        !            74: error(s, a, b, c, d, e, f)
        !            75: char *s;
        !            76: {
        !            77:        sprintf(msgbuf, s, a, b, c, d, e, f);
        !            78:        write(dbgfd, msgbuf, strlen(msgbuf));
        !            79: }
        !            80: 
        !            81: /* VARARGS1 */
        !            82: debug(s, a, b, c, d, e, f)
        !            83: char *s;
        !            84: {
        !            85:        if(!debugflag)
        !            86:                return;
        !            87:        sprintf(msgbuf, s, a, b, c, d, e, f);
        !            88:        write(dbgfd, msgbuf, strlen(msgbuf));
        !            89:        /*sync();vain attempt to preserve every precious byte of message */
        !            90: }
        !            91: /* VARARGS1 */
        !            92: fatal(s, a, b, c, d, e, f)
        !            93: {
        !            94:        sprintf(msgbuf, s, a, b, c, d, e, f);
        !            95:        write(dbgfd, msgbuf, strlen(msgbuf));
        !            96:        exit(1);
        !            97: }

unix.superglobalmegacorp.com

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