/* * program putback * * puts back media in scsi-changer * * usage: /usr/sbin/putback * */ #include #include #include #include #include #include #include #include #include #include #include #include #define PROG "putback" #define CHANGER "/dev/sch0" #define DEBUG 0 /* set to 1 for debug output */ /* ---------------------------------------------------------------------- */ int main(int argc, char *argv[]) { struct changer_params params; struct changer_get_element *dt; struct changer_move move; char *h; int fd,i,drive,cside; if (argc != 1) { fprintf(stderr,"Usage: %s\n",argv[0]); exit(1); } if (-1 == (fd = open(CHANGER,O_RDONLY))) { perror(PROG ": open " CHANGER); exit(1); } /* read changer status information */ if (ioctl(fd,CHIOGPARAMS,¶ms)) { perror(PROG ": ioctl CHIOGPARAMS"); exit(1); } #if DEBUG fprintf(stderr,PROG ": %d drives, %d slots\n", params.cp_ndrives,params.cp_nslots); #endif dt = malloc(sizeof(struct changer_get_element)*params.cp_ndrives); for (i = 0; i < params.cp_ndrives; i++) { dt[i].cge_type=CHET_DT; dt[i].cge_unit=i; if (ioctl(fd,CHIOGELEM,dt+i)) { fprintf(stderr,PROG ":ioctl CHIOGELEM mt %d: %s\n", i,strerror(errno)); exit(1); } if (NULL != (h = strchr(dt[i].cge_pvoltag,' '))) *h = '\0'; if (NULL != (h = strchr(dt[i].cge_avoltag,' '))) *h = '\0'; } for (drive=0; drive