/* * This is an example of using mrd_position_to_element(3mrd) * to perform multiple Position To Element commands. For * each pair of arguments after the robot and transport * address, it will position the transport to that location. * * mrd_position_to_element robot transport type address * * Type can be one of: * * slot, port, drive or transport * * The optional transport argument can be a transport address * number, the word "default" or an empty string. To keep the * example as simple as possible, it doesn't try to invert the * transport. */ #ifndef lint static char SccsId[] = "@(#)mrd_position_to_element.c 1.2 3/5/97" ; #endif #include <stdio.h> #include <stdlib.h> #include <string.h> #include <mrd_common.h> #include <mrd_message.h> /* * Given a string, resembling one of the element types, * return the SCSI type code for it. */ struct { int code ; char *string ; } etypes[] = { TRANSPORT, "transport", SLOT, "slot", DRIVE, "drive", PORT, "port", } ; convert_type(char *etype) { register i ; /* * For each entry in the array. */ for(i = 0; i < sizeof(etypes)/sizeof(etypes[0]); i++) /* * Do a case insensitive comparison, allowing * abbreviations. Return as soon as a match is * found. Return -1 if one isn't found. */ #ifdef vms if( strncmp(etypes[i].string, etype, strlen(etype)) == 0 ) #else if( strncasecmp(etypes[i].string, etype, strlen(etype)) == 0 ) #endif return etypes[i].code ; return -1 ; } main(int argc, char *argv[]) { int el ; /* Counter */ int status ; /* Status from MRD calls */ int invert = 0 ; /* Don't invert */ char *robot ; /* Robot name */ int type ; /* Element type */ int element ; /* Relative element addr */ int address ; /* Absolute element addr */ int transport ; /* Transport address */ char *transport_name ; /* Tranport name */ robot_info_t robot_info ; dev_status_t dev_status ; char log_info[MRD_MAX_LOG_STRING+1] ; if( argc < 5 ) { printf("usage: %s robot transport type address ...\n", argv[0]); exit(1) ; } /* * Get the medium changer name. */ robot = argv[1] ; /* * Get the transport number. We'll keep it as a name * so we can detect the default transport. Once we * know the element addresses, we can add the base * base address if appropriate. */ if( strcmp(argv[2], "default") == 0 ) transport_name = NULL ; else transport_name = argv[2] ; /* * Make sure there are pairs of arguments left. There * should be an odd number. */ if((argc % 2) == 0 ) { printf("Pairs of arguments are required.\n") ; exit(1) ; } /* * Open the robot. */ robot_info.channel = BAD_CHANNEL ; status = mrd_startup(robot, &robot_info, log_info) ; if( status != MRD_STATUS_SUCCESS ) { fprintf(stderr, "Can't start %s: %s\n", robot, mrd_strstatus(status)) ; exit(1) ; } if( transport_name == NULL ) transport = 0 ; else transport = atoi(transport_name) + robot_info.transport_start; /* * Look at the element addresses in pairs. */ for(el = 3; el < argc; el += 2) { type = convert_type(argv[el]) ; element = atoi(argv[el + 1]) ; switch( type ) { case SLOT: address = element + robot_info.slot_start ; break ; case DRIVE: address = element + robot_info.device_start ; break ; case TRANSPORT: address = element + robot_info.transport_start ; break ; case PORT: address = element + robot_info.port_start ; break ; default: printf("Unknown element type: %s %s\n", argv[el], argv[el + 1]) ; continue ; } /* * Audit the command. */ printf("Position transport to %s #%d.\n", mrd_strelement(type), element) ; /* * Do the command. */ status = mrd_position_to_element(&robot_info, transport, address, invert, &dev_status) ; if( status != MRD_STATUS_SUCCESS ) printf("Position to Element failed: %s: %s.\n", robot, mrd_strstatus(status)) ; } (void)mrd_shutdown(&robot_info) ; return 0 ; }