Annotation of researchv10dc/cmd/oworm/oscsi/init.c, revision 1.1

1.1     ! root        1: #include       "scsi.h"
        !             2: 
        !             3: #define        DEV     "/dev/scsi"
        !             4: 
        !             5: int scsi_fd;
        !             6: int scsi_id;
        !             7: int scsi_verbose;
        !             8: 
        !             9: scsiinit(complain)
        !            10: {
        !            11:        if((scsi_fd = open(DEV, 2)) < 0){
        !            12:                if(complain)
        !            13:                        perror(DEV);
        !            14:                return(1);
        !            15:        }
        !            16:        return(0);
        !            17: }
        !            18: 
        !            19: scsiid(id)
        !            20: {
        !            21:        scsi_id = id;
        !            22: }
        !            23: 
        !            24: scsiclro(o)
        !            25:        register struct scsi_o *o;
        !            26: {
        !            27:        extern char *memset();
        !            28:        memset((char *)o, 0xDD, sizeof(*o));
        !            29: }
        !            30: 
        !            31: scsireg(fd, csr, per)
        !            32: {
        !            33:        char buf[256];
        !            34:        extern char *strcat();
        !            35: 
        !            36: #define        add(x)  strcat(buf, x)
        !            37: 
        !            38:        buf[0] = 0;
        !            39:        if(csr&CSR_DONE) add(", i/o done");
        !            40:        if(csr&CSR_ERROR) add(", error");
        !            41:        if(csr&CSR_R) add(", request active");
        !            42:        if(csr&CSR_M) add(", message active");
        !            43:        if(csr&CSR_I) add(", i/o active");
        !            44:        if(csr&CSR_C) add(", c/d active");
        !            45:        if(csr&CSR_S) add(", select active");
        !            46:        if(csr&CSR_B) add(", busy active");
        !            47:        if(buf[0] == 0)
        !            48:                fprint(fd, "CSR: zero");
        !            49:        else {
        !            50:                fprint(fd, "CSR:%s", &buf[1]);
        !            51:                if(csr&!CSR_BITS)
        !            52:                        fprint(fd, " BAD BITS SET 0x%ux", csr&!CSR_BITS);
        !            53:        }
        !            54:        fprint(fd, "; ");
        !            55:        buf[0] = 0;
        !            56:        if(per&PER_CHECK) add(", check status");
        !            57:        if(per&PER_DRBUSY) add(", drive busy");
        !            58:        if(per&PER_SBUSY) add(", busy timeout");
        !            59:        if(per&PER_SELECT) add(", select timeout");
        !            60:        if(buf[0] == 0)
        !            61:                fprint(fd, "PER: zero\n");
        !            62:        else
        !            63:                fprint(fd, "PER:%s\n", &buf[1]);
        !            64: }
        !            65: 
        !            66: static char *smsg[16] =
        !            67: {
        !            68:        "good", "check", "met/good", "reserved", "busy", "reserved",
        !            69:        "reserved", "reserved", "intermediate good", "reserved", "intermediate good/met",
        !            70:        "reserved", "reservation conflict", "reserved", "reserved", "reserved",
        !            71: };
        !            72: 
        !            73: scsidump(o)
        !            74:        register struct scsi_o *o;
        !            75: {
        !            76:        extern char *exstab[];
        !            77: 
        !            78:        Fprint(1, "csr=0x%uhx per=0x%uhx status=0x%uhx(%s) 0x%uhx 0x%uhx\n", o->csr,
        !            79:                o->per, o->status[0], smsg[(o->status[0]>>1)&0xF], o->status[1],
        !            80:                o->status[2]);
        !            81:        Fprint(1, "data=0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", o->data[0],
        !            82:                o->data[1], o->data[2], o->data[3], o->data[4], o->data[5],
        !            83:                o->data[6], o->data[7], o->data[8], o->data[9], o->data[10],
        !            84:                o->data[11]);
        !            85:        if(o->data[0] == 0x70)
        !            86:                Fprint(1, " (extended sense: %s)", exstab[o->data[2]&0xF]);
        !            87:        Fprint(1, "\n");
        !            88: }
        !            89: 
        !            90: scsiio(i, o, nn, str)
        !            91:        struct scsi_i *i;
        !            92:        struct scsi_o *o;
        !            93:        char *str;
        !            94: {
        !            95:        int n;
        !            96: 
        !            97:        if((n = write(scsi_fd, (char *)i, N(nn))) != N(nn)){
        !            98:                fprint(2, "%s: wrote %d, really wrote %d\n", str, N(nn), n);
        !            99:                perror("write");
        !           100:                return(1);
        !           101:        }
        !           102:        scsiclro(o);
        !           103:        n = read(scsi_fd, (char *)o, sizeof *o);
        !           104:        if(n < 0){
        !           105:                perror(str);
        !           106:                scsireg(2, o->csr, o->per);
        !           107:                return(1);
        !           108:        }
        !           109:        return(n);
        !           110: }

unix.superglobalmegacorp.com

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