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

1.1     ! root        1: #include       <stdio.h>
        !             2: #include       <stddef.h>
        !             3: #include       <string.h>
        !             4: #include       "scsi.h"
        !             5: #include       "juke.h"
        !             6: 
        !             7: j_load(char *vol_id, char *buf, long tlimit)
        !             8: {
        !             9:        Side side;
        !            10:        int n, sh, dr;
        !            11:        char disk_to_load[256];
        !            12:        struct Lunstatus *l;
        !            13: 
        !            14:        if(j_rdshelves(buf))    /* read in shelf names */
        !            15:                return(-1);
        !            16:        if(j_getstatus(buf))    /* get the jukebox status */
        !            17:                return(-1);
        !            18:        /* now check which side we want */
        !            19:        n = strlen(vol_id);
        !            20:        strcpy(disk_to_load, vol_id);
        !            21:        if(disk_to_load[n-1] == 'a')
        !            22:                side = SIDEA;
        !            23:        else if(disk_to_load[n-1] == 'b')
        !            24:                side = SIDEB;
        !            25:        else {
        !            26:                sprintf(buf, "vol_id '%s' must end in a or b", vol_id);
        !            27:                return(-1);
        !            28:        }
        !            29:        disk_to_load[n-1] = 0;
        !            30:        /* which shelf is that? */
        !            31:        sh = j_shelfof(disk_to_load);
        !            32:        if(sh < 0){
        !            33:                sprintf(buf, "can't find vol_id %s", disk_to_load);
        !            34:                return(-1);
        !            35:        }
        !            36:        while(tlimit >= 0){
        !            37:                for(n = 0; n < NLUN; n++){
        !            38:                        l = &j_status.lun[n];
        !            39:                        if(l->diskin && l->shelfvalid && (sh == (l->retshelf>>1))){
        !            40:                                if(((l->retshelf&1) == side) && (n < nlun))
        !            41:                                        return(n);
        !            42:                                if(l->ready)
        !            43:                                        goto await;
        !            44:                                if(j_drive_to_shelf(n, -1, 0, buf))
        !            45:                                        return(-1);
        !            46:                                if(j_getstatus(buf))    /* get the jukebox status */
        !            47:                                        return(-1);
        !            48:                                break;
        !            49:                        }
        !            50:                }
        !            51:                /* disk is available */
        !            52:                dr = j_empty_drive(tlimit, buf);
        !            53:                if(dr < 0){
        !            54:                        sprintf(buf, "can't find a free drive");
        !            55:                        return(-1);
        !            56:                }
        !            57:                if(j_shelf_to_drive(sh, side, dr, buf) < 0)
        !            58:                        return(-1);
        !            59:                return(dr);
        !            60: await:
        !            61:                sleep(10);
        !            62:                tlimit -= 10;
        !            63:                if(j_getstatus(buf))    /* get the jukebox status */
        !            64:                        return(-1);
        !            65:        }
        !            66:        sprintf(buf, "disk '%s' busy", disk_to_load);
        !            67:        return(-1);
        !            68: }

unix.superglobalmegacorp.com

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