/*
* This is an example of using mrd_move_medium(3mrd) directly to
* move a cartridge from one slot to another. To simplify the
* example, it only supports slot to slot moves, but it shows
* how the absolute element addresses are calcuated. For each
* additional destination address given, the previous (successful)
* destination address is used as the source.
*
* Usage:
*
* mrd_move_medium robot source dest [ dest... ]
*/
#ifndef lint
static char SccsId[] = "@(#)mrd_move_medium.c 1.4 3/5/97" ;
#endif
#include <stdio.h>
#include <stdlib.h>
#include <mrd_common.h>
#include <mrd_message.h>
main(int argc, char *argv[])
{
int i ; /* counter */
int source ; /* Source address */
int dest ; /* Destination address */
int invert = 0 ; /* Assume it can't invert */
int transport ; /* Transport address */
int status ; /* return status */
char *robot ; /* Robot to open */
robot_info_t robot_info ; /* Robot data */
dev_status_t dev_status ; /* Device status */
char log_info[MRD_MAX_LOG_STRING+1] ;
/*
* Check that there are enough arguments.
*/
if( argc < 4 ) {
printf("usage: %s robot source dest [ dest... ]\n", argv[0]) ;
exit(1) ;
}
else {
robot = argv[1] ;
source = atoi(argv[2]) ;
}
/*
* Initialize the channel field of the robot_info, so
* mrd_startup(3mrd) will actually open the robot.
*/
robot_info.channel = BAD_CHANNEL ;
status = mrd_startup(robot, &robot_info, log_info) ;
if( status != MRD_STATUS_SUCCESS ) {
printf("Startup failed: %s: %s.\n", mrd_strstatus(status),
log_info[0] ? log_info : "none") ;
exit(1) ;
}
/*
* Set the transport address. If there is only one
* transport use the correct address. If there is
* more than one assume that the medium changer
* supports zero as the default.
*/
if( robot_info.transport_count == 1 )
transport = robot_info.transport_start ;
else
transport = 0 ;
/*
* Turn the relative slot address into an absolute slot
* address by adding the slot start address.
*/
source += robot_info.slot_start ;
/*
* For each destination address on the command line,
* move the the cartridge in the source to the
* destination. After each (successful) move, replace
* the previous source with this destination.
*/
for(i = 3; i < argc; i++) {
/*
* Calculate the absolute address.
*/
dest = atoi(argv[i]) + robot_info.slot_start ;
/*
* Print an audit as we go. Since we know these
* are slots, convert back to relative addresses
* for the audit.
*/
printf("Move the medium in slot %d to slot %d\n",
source - robot_info.slot_start,
dest - robot_info.slot_start) ;
status = mrd_move_medium(&robot_info, transport, source,
dest, invert, &dev_status) ;
if( status != MRD_STATUS_SUCCESS ) {
printf("Move failed on %s: %s\n", robot,
mrd_strstatus(status)) ;
/*
* Since the cartridge didn't move, don't
* reset the source, by skipping the remainder
* of the loop.
*/
continue ;
}
/*
* Make the next source, this destination.
*/
source = dest ;
}
(void)mrd_shutdown(&robot_info) ;
return 0 ;
}