Annotation of researchv10dc/cmd/rarepl/rarct.c, revision 1.1

1.1     ! root        1: /*% cc -O -o rarct %
        !             2:  *
        !             3:  * read the rct and other stuff
        !             4:  */
        !             5: 
        !             6: #include <stdio.h>
        !             7: #include <sys/param.h>
        !             8: #include <sys/udaioc.h>
        !             9: #include "rct.h"
        !            10: 
        !            11: struct ud_unit ud_unit;
        !            12: 
        !            13: main(argc, argv)
        !            14: int argc;
        !            15: char **argv;
        !            16: {
        !            17:        int hdr = 0;
        !            18:        int stat = 0;
        !            19:        int nd = 0;
        !            20:        int errs = 0;
        !            21: 
        !            22:        while (--argc > 0) {
        !            23:                if (**++argv == '-')
        !            24:                        switch (argv[0][1]) {
        !            25:                        case 'h':
        !            26:                                hdr++;
        !            27:                                continue;
        !            28: 
        !            29:                        case 'c':
        !            30:                                stat++;
        !            31:                                continue;
        !            32: 
        !            33:                        default:
        !            34:                                fprintf(stderr, "%s ignored\n", *argv);
        !            35:                                continue;
        !            36:                        }
        !            37:                nd++;
        !            38:                errs += dodev(*argv, hdr, stat);
        !            39:        }
        !            40:        if (nd == 0) {
        !            41:                fprintf(stderr, "usage: %s dev\n", argv[0]);
        !            42:                exit(1);
        !            43:        }
        !            44:        exit(errs);
        !            45: }
        !            46: 
        !            47: dodev(dev, hdr, stat)
        !            48: char *dev;
        !            49: int hdr, stat;
        !            50: {
        !            51:        int fd;
        !            52:        daddr_t size;
        !            53:        char buf[RBNSEC];
        !            54:        register daddr_t i;
        !            55:        daddr_t rctmax();
        !            56: 
        !            57:        if ((fd = open(dev, 0)) < 0) {
        !            58:                perror(dev);
        !            59:                return (1);
        !            60:        }
        !            61:        /*
        !            62:         * hack to force driver to read status
        !            63:         */
        !            64:        if (read(fd, buf, RBNSEC) != RBNSEC)
        !            65:                perror("read first block");
        !            66:        if (ioctl(fd, UIOCHAR, &ud_unit) < 0) {
        !            67:                perror("ioctl");
        !            68:                close(fd);
        !            69:                return (1);
        !            70:        }
        !            71:        if (stat)
        !            72:                statput();
        !            73:        if (hdr) {
        !            74:                rctread(fd, buf, RCTHDR);
        !            75:                hdrput(buf);
        !            76:        }
        !            77:        if (hdr || stat) {
        !            78:                close(fd);
        !            79:                return (0);
        !            80:        }
        !            81:        size = rctmax();
        !            82:        for (i = RCTTAB; i < size; i++) {
        !            83:                rctread(fd, buf, i);
        !            84:                rctput(buf, i);
        !            85:        }
        !            86:        close(fd);
        !            87:        return (0);
        !            88: }
        !            89: 
        !            90: daddr_t
        !            91: rctmax()
        !            92: {
        !            93:        register daddr_t nrbns;
        !            94: 
        !            95:        nrbns = (ud_unit.radsize / ud_unit.tracksz) * ud_unit.rbns;
        !            96:        nrbns = ((nrbns+RBNPB-1) / RBNPB) + RCTTAB;
        !            97:        if (nrbns >= ud_unit.rctsize)
        !            98:                return ((daddr_t)ud_unit.rctsize);
        !            99:        return (nrbns);
        !           100: }
        !           101: 
        !           102: rctread(fd, buf, bno)
        !           103: char *buf;
        !           104: daddr_t bno;
        !           105: {
        !           106:        struct ud_rctbuf rb;
        !           107:        register int i;
        !           108: 
        !           109:        rb.lbn = bno;
        !           110:        rb.buf = buf;
        !           111:        if (ioctl(fd, UIORRCT, &rb) < 0) {
        !           112:                perror("read rct");
        !           113:                fprintf(stderr, "block %d\n", bno);
        !           114:                for (i = 0; i < RBNSEC; i++)
        !           115:                        buf[i] = 0;
        !           116:        }
        !           117: }
        !           118: 
        !           119: rctput(buf, bno)
        !           120: char *buf;
        !           121: int bno;
        !           122: {
        !           123:        register long rbn;
        !           124:        register struct rbd *rp;
        !           125:        register int i;
        !           126: 
        !           127:        rbn = (bno - RCTTAB) * RBNPB;
        !           128:        rp = (struct rbd *)buf;
        !           129:        for (i = 0; i < RBNPB; i++, rp++, rbn++) {
        !           130:                if (rp->rb_code == RFREE || rp->rb_code == RNULL)
        !           131:                        continue;
        !           132:                printf("%ld: %o: %ld\n", rbn, rp->rb_code, rp->rb_lbn);
        !           133:        }
        !           134: }
        !           135: 
        !           136: hdrput(buf)
        !           137: char *buf;
        !           138: {
        !           139:        register struct rct *rc;
        !           140: 
        !           141:        rc = (struct rct *)buf;
        !           142:        printf("volser x%lx x%lx\n", rc->rc_volser[0], rc->rc_volser[1]);
        !           143:        printf("flags 0%x lbn %ld rbn %ld badrbn %ld\n",
        !           144:                rc->rc_flags, rc->rc_lbn, rc->rc_rbn, rc->rc_badrbn);
        !           145: }
        !           146: 
        !           147: char *
        !           148: mtoa(m)
        !           149:        long m;
        !           150: {
        !           151:        static char buf[10];
        !           152:        char *s = buf;
        !           153:        register k;
        !           154: 
        !           155: #define        M5(b, s)        if(k = ((m>>(b-4))&0x1F)) *s++ = 'A'-1+k
        !           156: 
        !           157:        M5(31, s);
        !           158:        M5(26, s);
        !           159:        M5(21, s);
        !           160:        M5(16, s);
        !           161:        M5(11, s);
        !           162:        m &= 0x7F;
        !           163:        *s++ = '0'+(m/10);
        !           164:        *s++ = '0'+(m%10);
        !           165:        *s = 0;
        !           166:        return(buf);
        !           167: }
        !           168: 
        !           169: statput()
        !           170: {
        !           171: 
        !           172:        printf("size %ld\nrctsize %ld\n", ud_unit.radsize, ud_unit.rctsize);
        !           173:        printf("medium x%lx='%s'\n", ud_unit.medium, mtoa(ud_unit.medium));
        !           174:        printf("tracks %d groups %d cyls %d\n",
        !           175:                ud_unit.tracksz, ud_unit.groupsz, ud_unit.cylsz);
        !           176:        printf("rbns/track %d\ncopies %d\n", ud_unit.rbns, ud_unit.copies);
        !           177: }

unix.superglobalmegacorp.com

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