Annotation of researchv10no/cmd/worm/scsi/load.c, revision 1.1

1.1     ! root        1: #define        _POSIX_SOURCE
        !             2: #include       <stddef.h>
        !             3: #include       <stdlib.h>
        !             4: #include       <unistd.h>
        !             5: #include       <stdio.h>
        !             6: #include       <string.h>
        !             7: #include       <errno.h>
        !             8: #include       <time.h>
        !             9: #include       "jukeface.h"
        !            10: #include       "jukebox.h"
        !            11: 
        !            12: static j_empty_drive(Jukebox *, long tlimit, char *buf);
        !            13: 
        !            14: j_load(Jukebox *j, char *vol_id, char *buf, long tlimit)
        !            15: {
        !            16:        int side;
        !            17:        int n, sh, dr;
        !            18:        char disk_to_load[256];
        !            19:        struct lun *l;
        !            20: 
        !            21:        if(j_rdshelves(j, buf)) /* read in shelf names */
        !            22:                return(-1);
        !            23: /*
        !            24:        be careful. due to a prom change the shelf indicator
        !            25:        is now off when IN a drive. so do the drive status AFTER
        !            26:        the shelf status.
        !            27: */
        !            28:        if(j_shstatus(j, buf))  /* get the jukebox status */
        !            29:                return(-1);
        !            30:        if(j_drstatus(j, buf))  /* get the jukebox status */
        !            31:                return(-1);
        !            32:        /* now check which side we want */
        !            33:        n = strlen(vol_id);
        !            34:        strcpy(disk_to_load, vol_id);
        !            35:        if(disk_to_load[n-1] == 'a')
        !            36:                side = SIDEA;
        !            37:        else if(disk_to_load[n-1] == 'b')
        !            38:                side = SIDEB;
        !            39:        else {
        !            40:                sprintf(buf, "vol_id '%s' must end in a or b", vol_id);
        !            41:                return(-1);
        !            42:        }
        !            43:        disk_to_load[n-1] = 0;
        !            44:        /* which shelf is that? */
        !            45:        sh = j_shelfof(j, disk_to_load);
        !            46:        if(sh < 0){
        !            47:                sprintf(buf, "can't find vol_id %s", disk_to_load);
        !            48:                return(-1);
        !            49:        }
        !            50:        while(tlimit >= 0){
        !            51:                for(n = 0; n < j->nluns; n++){
        !            52:                        l = &j->luns[n];
        !            53:                        if(l->shelf == sh){
        !            54:                                if((l->side == side) && (n < j->nworms))
        !            55:                                        return(n);
        !            56:                                if(l->spunup)
        !            57:                                        goto await;
        !            58:                                if(j_dr_to_sh(n, -1, 0, buf))
        !            59:                                        return(-1);
        !            60:                                if(j_drstatus(j, buf))  /* get the jukebox status */
        !            61:                                        return(-1);
        !            62:                                break;
        !            63:                        }
        !            64:                }
        !            65:                /* disk is available */
        !            66:                dr = j_empty_drive(j, tlimit, buf);
        !            67:                if(dr < 0){
        !            68:                        sprintf(buf, "can't find a free drive");
        !            69:                        return(-1);
        !            70:                }
        !            71:                if(j_sh_to_dr(sh, side, dr, buf) < 0)
        !            72:                        return(-1);
        !            73:                return(dr);
        !            74: await:
        !            75:                sleep(10);
        !            76:                tlimit -= 10;
        !            77:                if(j_drstatus(j, buf))  /* get the jukebox status */
        !            78:                        return(-1);
        !            79:        }
        !            80:        sprintf(buf, "disk '%s' busy", disk_to_load);
        !            81:        return(-1);
        !            82: }
        !            83: 
        !            84: static
        !            85: j_empty_drive(Jukebox *j, long tlimit, char *buf)
        !            86: {      
        !            87:        int i, tstop;
        !            88:        
        !            89:        tstop = time((long *)0) + tlimit;
        !            90:        while(time((long *)0) <= tstop){
        !            91:                /* look for empty drives */
        !            92:                for(i = 0; i < j->nworms; i++)
        !            93:                        if(!j->luns[i].occupied)
        !            94:                                return(i);
        !            95:                /* look for spun down drives */
        !            96:                for(i = 0; i < j->nworms; i++){
        !            97:                        if(!j->luns[i].spunup){
        !            98:                                if(j_dr_to_sh(i, -1, SIDEA, buf))
        !            99:                                        return(-1);
        !           100:                                else
        !           101:                                        return(i);
        !           102:                        }
        !           103:                }
        !           104:                sleep(10);
        !           105:                if(j_drstatus(j, buf))  /* get the jukebox status */
        !           106:                        return(-1);
        !           107:        }
        !           108:        return(-1);
        !           109: }

unix.superglobalmegacorp.com

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