Annotation of cci/usr/src/etc/rtar/tarrmt.c, revision 1.1

1.1     ! root        1: static char *sccsid = "@(#)dumprmt.c   1.6 (Berkeley) 7/1/83";
        !             2: 
        !             3: #include <sys/param.h>
        !             4: #include <sys/mtio.h>
        !             5: #include <sys/ioctl.h>
        !             6: 
        !             7: #include <netinet/in.h>
        !             8: 
        !             9: #include <stdio.h>
        !            10: #include <netdb.h>
        !            11: #include <pwd.h>
        !            12: 
        !            13: #define        TS_CLOSED       0
        !            14: #define        TS_OPEN         1
        !            15: 
        !            16: static int rmtstate = TS_CLOSED;
        !            17: int    rmtape;
        !            18: int    rmtconnaborted();
        !            19: char   *rmtpeer;
        !            20: struct         passwd  *getpwuid();
        !            21: 
        !            22: rmthost(host)
        !            23:        char *host;
        !            24: {
        !            25: 
        !            26:        rmtpeer = host;
        !            27:        signal(SIGPIPE, rmtconnaborted);
        !            28:        rmtgetconn();
        !            29:        if (rmtape < 0)
        !            30:                exit(1);
        !            31: }
        !            32: 
        !            33: rmtconnaborted()
        !            34: {
        !            35: 
        !            36:        fprintf(stderr, "Lost connection to remote host.\n");
        !            37:        exit(1);
        !            38: }
        !            39: 
        !            40: rmtgetconn()
        !            41: {
        !            42:        static struct servent *sp = 0;
        !            43:        struct passwd *pwd;
        !            44: 
        !            45:        if (sp == 0) {
        !            46:                sp = getservbyname("shell", "tcp");
        !            47:                if (sp == 0) {
        !            48:                        fprintf(stderr, "rdump: shell/tcp: unknown service\n");
        !            49:                        exit(1);
        !            50:                }
        !            51:        }
        !            52:        pwd = (struct passwd *)getpwuid(getuid());
        !            53:        if (pwd == 0) {
        !            54:                fprintf(stderr, "Who are you?\n");
        !            55:                exit(1);
        !            56:        }
        !            57:         rmtape = rcmd(&rmtpeer, sp->s_port, pwd->pw_name,
        !            58:                        pwd->pw_name, "/etc/rmt", 0);
        !            59: }
        !            60: 
        !            61: rmtopen(tape, mode)
        !            62:        char *tape;
        !            63:        int mode;
        !            64: {
        !            65:        char buf[256];
        !            66: 
        !            67:        sprintf(buf, "O%s\n%d\n", tape, mode);
        !            68:        rmtcall(tape, buf);
        !            69:        rmtstate = TS_OPEN;
        !            70: }
        !            71: 
        !            72: rmtcreat(tape, mode)
        !            73:        char *tape;
        !            74:        int mode;
        !            75: {
        !            76:        char buf[256];
        !            77: 
        !            78:        sprintf(buf, "N%s\n%d\n", tape, mode);
        !            79:        rmtcall(tape, buf);
        !            80:        rmtstate = TS_OPEN;
        !            81: }
        !            82: 
        !            83: rmtclose()
        !            84: {
        !            85: 
        !            86:        if (rmtstate != TS_OPEN)
        !            87:                return;
        !            88:        rmtcall("close", "C\n");
        !            89:        rmtstate = TS_CLOSED;
        !            90: }
        !            91: 
        !            92: rmtread(buf, count)
        !            93:        char *buf;
        !            94:        int count;
        !            95: {
        !            96:        char line[30];
        !            97:        int n, i, cc;
        !            98:        extern errno;
        !            99: 
        !           100:        sprintf(line, "R%d\n", count);
        !           101:        n = rmtcall("read", line);
        !           102:        if (n < 0) {
        !           103:                errno = n;
        !           104:                return (-1);
        !           105:        }
        !           106:        for (i = 0; i < n; i += cc) {
        !           107:                cc = read(rmtape, buf+i, n - i);
        !           108:                if (cc <= 0) {
        !           109:                        rmtconnaborted();
        !           110:                }
        !           111:        }
        !           112:        return (n);
        !           113: }
        !           114: 
        !           115: rmtwrite(buf, count)
        !           116:        char *buf;
        !           117:        int count;
        !           118: {
        !           119:        char line[30];
        !           120: 
        !           121:        sprintf(line, "W%d\n", count);
        !           122:        write(rmtape, line, strlen(line));
        !           123:        write(rmtape, buf, count);
        !           124:        return (rmtreply("write"));
        !           125: }
        !           126: 
        !           127: rmtwrite0(count)
        !           128:        int count;
        !           129: {
        !           130:        char line[30];
        !           131: 
        !           132:        sprintf(line, "W%d\n", count);
        !           133:        write(rmtape, line, strlen(line));
        !           134: }
        !           135: 
        !           136: rmtwrite1(buf, count)
        !           137:        char *buf;
        !           138:        int count;
        !           139: {
        !           140: 
        !           141:        write(rmtape, buf, count);
        !           142: }
        !           143: 
        !           144: rmtwrite2()
        !           145: {
        !           146:        int i;
        !           147: 
        !           148:        return (rmtreply("write"));
        !           149: }
        !           150: 
        !           151: rmtseek(offset, pos)
        !           152:        int offset, pos;
        !           153: {
        !           154:        char line[80];
        !           155: 
        !           156:        sprintf(line, "L%d\n%d\n", offset, pos);
        !           157:        return (rmtcall("seek", line));
        !           158: }
        !           159: 
        !           160: struct mtget mts;
        !           161: 
        !           162: struct mtget *
        !           163: rmtstatus()
        !           164: {
        !           165:        register int i;
        !           166:        register char *cp;
        !           167: 
        !           168:        if (rmtstate != TS_OPEN)
        !           169:                return (0);
        !           170:        if (rmtcall("status", "S\n") < 0)
        !           171:                return((struct mtget *)0);
        !           172:        /* rmtcall("status", "S\n"); */ 
        !           173:        for (i = 0, cp = (char *)&mts; i < sizeof(mts); i++)
        !           174:                *cp++ = rmtgetb();
        !           175:        return (&mts);
        !           176: }
        !           177: 
        !           178: rmtioctl(cmd, count)
        !           179:        int cmd, count;
        !           180: {
        !           181:        char buf[256];
        !           182: 
        !           183:        if (count < 0)
        !           184:                return (-1);
        !           185:        sprintf(buf, "I%d\n%d\n", cmd, count);
        !           186:        return (rmtcall("ioctl", buf));
        !           187: }
        !           188: 
        !           189: rmtcall(cmd, buf)
        !           190:        char *cmd, *buf;
        !           191: {
        !           192: 
        !           193:        if (write(rmtape, buf, strlen(buf)) != strlen(buf))
        !           194:                rmtconnaborted();
        !           195:        return (rmtreply(cmd));
        !           196: }
        !           197: 
        !           198: rmtreply(cmd)
        !           199:        char *cmd;
        !           200: {
        !           201:        register int c;
        !           202:        char code[30], emsg[BUFSIZ];
        !           203: 
        !           204:        rmtgets(code, sizeof (code));
        !           205:        if (*code == 'E' || *code == 'F') {
        !           206:                rmtgets(emsg, sizeof (emsg));
        !           207:                msg("%s: %s\n", cmd, emsg, code + 1);
        !           208:                if (*code == 'F') {
        !           209:                        rmtstate = TS_CLOSED;
        !           210:                        return (-1);
        !           211:                }
        !           212:                return (-1);
        !           213:        }
        !           214:        if (*code != 'A') {
        !           215:                msg("Protocol to remote tape server botched (code %s?).\n",
        !           216:                    code);
        !           217:                rmtconnaborted();
        !           218:        }
        !           219:        return (atoi(code + 1));
        !           220: }
        !           221: 
        !           222: rmtgetb()
        !           223: {
        !           224:        char c;
        !           225: 
        !           226:        if (read(rmtape, &c, 1) != 1)
        !           227:                rmtconnaborted();
        !           228:        return (c);
        !           229: }
        !           230: 
        !           231: rmtgets(cp, len)
        !           232:        char *cp;
        !           233:        int len;
        !           234: {
        !           235: 
        !           236:        while (len > 1) {
        !           237:                *cp = rmtgetb();
        !           238:                if (*cp == '\n') {
        !           239:                        cp[1] = 0;
        !           240:                        return;
        !           241:                }
        !           242:                cp++;
        !           243:                len--;
        !           244:        }
        !           245:        msg("Protocol to remote tape server botched (in rmtgets).\n");
        !           246:        rmtconnaborted();
        !           247: }
        !           248: msg(cp, a1, a2, a3)
        !           249:        char *cp;
        !           250: {
        !           251: 
        !           252:        fprintf(stderr, cp, a1, a2, a3);
        !           253: }

unix.superglobalmegacorp.com

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