Annotation of researchv10no/cmd/worm/oscsi/wren/oomode.c, revision 1.1.1.1

1.1       root        1: #include       <stdio.h>
                      2: #include       "../scsi.h"
                      3: #include       "../scsish.h"
                      4: #include       "fns.h"
                      5: 
                      6: #define        SHORT(n)        ((ret.data[n]<<8)|(ret.data[n+1]))
                      7: 
                      8: static int
                      9: er(int pcf, char *err)
                     10: {
                     11:        struct scsi_cmd cmd;
                     12:        struct scsi_return ret;
                     13:        int n;
                     14:        static char *bit[8] = { "DCR", "DTE", "PER", "EEC", "RC", "TB", "ARRE", "AWRE" };
                     15: 
                     16:        set6(cmd, 0x1A, 0, (pcf<<6)|0x01, 0, 20, 0);
                     17:        if(n = s_io(0, &cmd, 0, &ret, 20, err))
                     18:                return(n);
                     19:        printf("error recovery:\n\t");
                     20:        for(n = 7; n >= 0; n--)
                     21:                printf(" %s%s", (ret.data[14]&(1<<n))? "":"~", bit[n]);
                     22:        printf("\n\t%d retries, max ecc span=%d\n", ret.data[15], ret.data[16]);
                     23:        return(0);
                     24: }
                     25: 
                     26: static int
                     27: dr(int pcf, char *err)
                     28: {
                     29:        struct scsi_cmd cmd;
                     30:        struct scsi_return ret;
                     31:        int n;
                     32: 
                     33:        set6(cmd, 0x1A, 0, (pcf<<6)|0x02, 0, 24, 0);
                     34:        if(n = s_io(0, &cmd, 0, &ret, 24, err))
                     35:                return(n);
                     36:        printf("disconnect/reconnect:\n");
                     37:        printf("\tread reconnect=%d/256,", ret.data[14]);
                     38:        printf(" write reconnect=%d/256\n", ret.data[15]);
                     39:        return(0);
                     40: }
                     41: 
                     42: static int
                     43: fp(int pcf, char *err)
                     44: {
                     45:        struct scsi_cmd cmd;
                     46:        struct scsi_return ret;
                     47:        int n;
                     48:        static char *bit[8] = { "", "", "", "INS", "SURF", "Remove", "HardSec", "SoftSec" };
                     49: 
                     50:        set6(cmd, 0x1A, 0, (pcf<<6)|0x03, 0, 36, 0);
                     51:        if(n = s_io(0, &cmd, 0, &ret, 36, err))
                     52:                return(n);
                     53:        printf("format parameters:\n");
                     54:        printf("\tsec=%dB, trk=%d secs, interleave=%d trk skew=%d cyl skew=%d\n",
                     55:                SHORT(24), SHORT(22), SHORT(26), SHORT(28), SHORT(30));
                     56:        printf("\t%d alt sec/%d alt trk per zone(=%d trks), %d alt trks per vol\n",
                     57:                SHORT(16), SHORT(18), SHORT(14), SHORT(20));
                     58:        printf("\tdrive type:");
                     59:        for(n = 7; n >= 3; n--)
                     60:                printf(" %s%s", (ret.data[32]&(1<<n))? "":"~", bit[n]);
                     61:        printf("\n");
                     62:        return(0);
                     63: }
                     64: 
                     65: static int
                     66: geom(int pcf, char *err)
                     67: {
                     68:        struct scsi_cmd cmd;
                     69:        struct scsi_return ret;
                     70:        int n;
                     71: 
                     72:        set6(cmd, 0x1A, 0, (pcf<<6)|0x04, 0, 32, 0);
                     73:        if(n = s_io(0, &cmd, 0, &ret, 32, err))
                     74:                return(n);
                     75:        printf("drive geometry:\n\t%d cyls, %d heads\n",
                     76:                (ret.data[14]<<16)|SHORT(15), ret.data[17]);
                     77:        return(0);
                     78: }
                     79: 
                     80: static int
                     81: cc(int pcf, char *err)
                     82: {
                     83:        struct scsi_cmd cmd;
                     84:        struct scsi_return ret;
                     85:        int n;
                     86:        static char *bit[8] = { "", "", "", "", "CacheEnable", "RSVD", "WIE", "RSVD" };
                     87: 
                     88:        set6(cmd, 0x1A, 0, (pcf<<6)|0x38, 0, 28, 0);
                     89:        if(n = s_io(0, &cmd, 0, &ret, 28, err))
                     90:                return(n);
                     91:        printf("cache control:\n\t");
                     92:        for(n = 7; n >= 4; n--)
                     93:                printf(" %s%s", (ret.data[14]&(1<<n))? "":"~", bit[n]);
                     94:        printf(", cache size=%d\n", ret.data[14]&0xF);
                     95:        printf("\tprefetch: thr=%d max=%dx%d min=%dx%d\n",
                     96:                ret.data[15], ret.data[16], ret.data[17], ret.data[18], ret.data[19]);
                     97:        return(0);
                     98: }
                     99: 
                    100: int
                    101: wr_modesense(int niargs, int *iargs, int ncargs, char **cargs, char *err)
                    102: {
                    103:        int n;
                    104: 
                    105: #pragma ref ncargs
                    106: #pragma ref cargs
                    107: #pragma ref niargs
                    108: #pragma ref iargs
                    109: 
                    110: #define        PCF     0       /* current values */
                    111: 
                    112:        printf("mode sense(%d,0):\n", s_id);
                    113:        if(n = er(PCF, err))
                    114:                return(n);
                    115:        if(n = dr(PCF, err))
                    116:                return(n);
                    117:        if(n = fp(PCF, err))
                    118:                return(n);
                    119:        if(n = geom(PCF, err))
                    120:                return(n);
                    121:        if(n = cc(PCF, err))
                    122:                return(n);
                    123:        return(0);
                    124: }
                    125: 
                    126: int
                    127: wr_modeselect(int niargs, int *iargs, int ncargs, char **cargs, char *err)
                    128: {
                    129:        struct scsi_cmd cmd;
                    130:        struct scsi_return ret;
                    131:        int n;
                    132: 
                    133: #pragma ref niargs
                    134: #pragma ref ncargs
                    135: #pragma ref cargs
                    136: 
                    137:        printf("changing modes to ");
                    138:        if((iargs[0] < 256) && (iargs[0] >= 0))
                    139:                printf("er-param=%d(=#%x), ", iargs[0], iargs[0]);
                    140:        if((iargs[1] < 256) && (iargs[1] >= 0))
                    141:                printf("er-retries=%d, ", iargs[1]);
                    142:        if((iargs[2] < 256) && (iargs[2] >= 0))
                    143:                printf("read-recon=%d/256, ", iargs[2]);
                    144:        if((iargs[3] < 256) && (iargs[3] >= 0))
                    145:                printf("write-recon=%d/256, ", iargs[3]);
                    146:        if((iargs[4] < 256) && (iargs[4] >= 0))
                    147:                printf("cache %sable, ", iargs[4]?"en":"dis");
                    148:        printf("\nsleep(10); kill me if you disagree\n");
                    149:        fflush(stdout);
                    150:        sleep(10);
                    151:        /* do error recovery */
                    152:        if(((iargs[0] < 256) && (iargs[0] >= 0)) || ((iargs[1] < 256) && (iargs[1] >= 0))){
                    153:                set6(cmd, 0x1A, 0, (0<<6)|0x01, 0, 20, 0);
                    154:                if(n = s_io(0, &cmd, 0, &ret, 20, err))
                    155:                        return(n);
                    156:                memcpy(cmd.data, ret.data, 20);
                    157:                cmd.data[14] &= ~0x10;
                    158:                if((iargs[0] < 256) && (iargs[0] >= 0))
                    159:                        cmd.data[14] = iargs[0];
                    160:                if((iargs[1] < 256) && (iargs[1] >= 0))
                    161:                        cmd.data[15] = iargs[1];
                    162:                set6(cmd, 0x15, 0x11, 0, 0, 20, 0);
                    163:                if(n = s_io(0, &cmd, 20, &ret, 0, err))
                    164:                        return(n);
                    165:        }
                    166:        /* reconnect */
                    167:        if(((iargs[2] < 256) && (iargs[2] >= 0)) || ((iargs[3] < 256) && (iargs[3] >= 0))){
                    168:                set6(cmd, 0x1A, 0, (0<<6)|0x02, 0, 24, 0);
                    169:                if(n = s_io(0, &cmd, 0, &ret, 24, err))
                    170:                        return(n);
                    171:                memcpy(cmd.data, ret.data, 24);
                    172:                if((iargs[3] < 256) && (iargs[3] >= 0))
                    173:                        cmd.data[14] = iargs[3];
                    174:                if((iargs[4] < 256) && (iargs[4] >= 0))
                    175:                        cmd.data[15] = iargs[4];
                    176:                set6(cmd, 0x15, 0x11, 0, 0, 24, 0);
                    177:                if(n = s_io(0, &cmd, 24, &ret, 0, err))
                    178:                        return(n);
                    179:        }
                    180:        /* do cache control */
                    181:        if((iargs[4] < 256) && (iargs[4] >= 0)){
                    182:                set6(cmd, 0x1A, 0, (0<<6)|0x38, 0, 28, 0);
                    183:                if(n = s_io(0, &cmd, 0, &ret, 28, err))
                    184:                        return(n);
                    185:                memcpy(cmd.data, ret.data, 28);
                    186:                cmd.data[14] &= ~0x10;
                    187:                if(iargs[4])
                    188:                        cmd.data[14] |= 0x10;
                    189:                set6(cmd, 0x15, 0x11, 0, 0, 28, 0);
                    190:                if(n = s_io(0, &cmd, 28, &ret, 0, err))
                    191:                        return(n);
                    192:        }
                    193:        return(0);
                    194: }

unix.superglobalmegacorp.com

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