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

1.1     ! root        1: #include       <stddef.h>
        !             2: #include       <stdio.h>
        !             3: #include       <string.h>
        !             4: #include       "jukeface.h"
        !             5: #include       "jukebox.h"
        !             6: 
        !             7: char *j_shelf[NSHELF];
        !             8: int j_wrshelf = 0;
        !             9: 
        !            10: j_rdshelves(char *err)
        !            11: {
        !            12:        FILE *fp;
        !            13:        static haveread = 0;
        !            14:        int shno;
        !            15:        char vname[256];
        !            16: 
        !            17:        if(haveread)
        !            18:                return(0);
        !            19:        for(shno = 0; shno < NSHELF; shno++)
        !            20:                j_shelf[shno] = 0;
        !            21:        if((fp = fopen(JUKEDIR, "r")) == NULL){
        !            22:                pperror(err, JUKEDIR);
        !            23:                return(-1);
        !            24:        }
        !            25:        while(fscanf(fp, "%d %s\n", &shno, vname) == 2){
        !            26:                if((shno < 0) || (shno >= NSHELF)){
        !            27:                fprintf(stderr, "Warning: bad shelf number in %s: %d (vol_id=%s)\n",
        !            28:                                JUKEDIR, shno, vname);
        !            29:                        continue;
        !            30:                
        !            31:                }
        !            32:                j_shelf[shno] = strdup(vname);
        !            33:        }
        !            34:        fclose(fp);
        !            35:        haveread = 1;
        !            36:        return(0);
        !            37: }
        !            38: 
        !            39: j_wrshelves(char *err)
        !            40: {
        !            41:        FILE *fp;
        !            42:        int shno;
        !            43: 
        !            44:        if((fp = fopen(JUKEDIR, "w")) == NULL){
        !            45:                pperror(err, JUKEDIR);
        !            46:                return(-1);
        !            47:        }
        !            48:        for(shno = 0; shno < NSHELF; shno++)
        !            49:                if(j_shelf[shno])
        !            50:                        fprintf(fp, "%d %s\n", shno, j_shelf[shno]);
        !            51:        fclose(fp);
        !            52:        return(0);
        !            53: }
        !            54: 
        !            55: int
        !            56: j_shelfof(char *vol_id)
        !            57: {
        !            58:        int i;
        !            59:        char buf[512];
        !            60: 
        !            61:        for(;;){
        !            62:                for(i = 0; i < NSHELF; i++)
        !            63:                        if(j_shelf[i] && (strcmp(j_shelf[i], vol_id) == 0))
        !            64:                                return(i);
        !            65:                if((i = warm_inv(buf)) <= 0)
        !            66:                        break;
        !            67:        }
        !            68:        if(i < 0)
        !            69:                fprintf(stderr, "jukebox: %s\n", buf);
        !            70:        return(-1);
        !            71: }
        !            72: 
        !            73: int
        !            74: j_driveof(char *vol_id)
        !            75: {
        !            76:        int i, sh;
        !            77: 
        !            78:        if((sh = j_shelfof(vol_id)) < 0)
        !            79:                return(-1);
        !            80:        for(i = 0; i < NLUN; i++)
        !            81:                if(j_status.lun[i].shelfvalid && (j_status.lun[i].retshelf == sh))
        !            82:                        return(i);
        !            83:        return(-1);
        !            84: }

unix.superglobalmegacorp.com

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